How to use the st2client.commands.resource.ResourceBranch function in st2client

To help you get started, we’ve selected a few st2client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StackStorm / st2 / st2client / st2client / commands / policy.py View on Github external
filters = {'resource_type': args.resource_type}
            filters.update(**kwargs)
            instances = self.manager.query(**filters)
            return instances
        else:
            return self.manager.get_all(**kwargs)


class PolicyTypeGetCommand(resource.ResourceGetCommand):
    pk_argument_name = 'ref_or_id'

    def get_resource(self, ref_or_id, **kwargs):
        return self.get_resource_by_ref_or_id(ref_or_id=ref_or_id, **kwargs)


class PolicyBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(PolicyBranch, self).__init__(
            models.Policy,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            commands={
                'list': PolicyListCommand,
                'get': PolicyGetCommand,
                'update': PolicyUpdateCommand,
                'delete': PolicyDeleteCommand,
            },
        )
github StackStorm / st2 / st2client / st2client / commands / service_registry.py View on Github external
'service-registry', description, app, subparsers, parent_parser=parent_parser
        )

        self.subparsers = self.parser.add_subparsers(
            help=('List of commands for managing service registry.')
        )

        # Instantiate commands
        args_groups = ['Manage service registry groups', self.app, self.subparsers]
        args_members = ['Manage service registry members', self.app, self.subparsers]

        self.commands['groups'] = ServiceRegistryGroupsBranch(*args_groups)
        self.commands['members'] = ServiceRegistryMembersBranch(*args_members)


class ServiceRegistryGroupsBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(ServiceRegistryGroupsBranch, self).__init__(
            ServiceRegistryGroup,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            read_only=True,
            commands={'list': ServiceRegistryListGroupsCommand, 'get': NoopCommand},
        )

        del self.commands['get']


class ServiceRegistryMembersBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
github StackStorm / st2 / st2client / st2client / commands / webhook.py View on Github external
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

from st2client.commands import resource
from st2client.formatters import table
from st2client.models import Webhook


class WebhookBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(WebhookBranch, self).__init__(
            Webhook,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            read_only=True,
            commands={'list': WebhookListCommand, 'get': WebhookGetCommand},
        )


class WebhookListCommand(resource.ContentPackResourceListCommand):
    display_attributes = ['url', 'type', 'description']

    def run_and_print(self, args, **kwargs):
github StackStorm / st2 / st2client / st2client / commands / policy.py View on Github external
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import logging

from st2client import models
from st2client.commands import resource


LOG = logging.getLogger(__name__)


class PolicyTypeBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(PolicyTypeBranch, self).__init__(
            models.PolicyType,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            read_only=True,
            commands={'list': PolicyTypeListCommand, 'get': PolicyTypeGetCommand},
        )


class PolicyTypeListCommand(resource.ResourceListCommand):
    display_attributes = ['id', 'resource_type', 'name', 'description']

    def __init__(self, resource, *args, **kwargs):
github StackStorm / st2 / st2client / st2client / commands / keyvalue.py View on Github external
import six

from st2client.commands import resource
from st2client.commands.noop import NoopCommand
from st2client.formatters import table
from st2client.models.keyvalue import KeyValuePair
from st2client.utils.date import format_isodate_for_user_timezone

LOG = logging.getLogger(__name__)

DEFAULT_LIST_SCOPE = 'all'
DEFAULT_GET_SCOPE = 'system'
DEFAULT_CUD_SCOPE = 'system'


class KeyValuePairBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(KeyValuePairBranch, self).__init__(
            KeyValuePair,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            commands={
                'list': KeyValuePairListCommand,
                'get': KeyValuePairGetCommand,
                'delete': KeyValuePairDeleteCommand,
                'create': NoopCommand,
                'update': NoopCommand,
            },
        )
github StackStorm / st2 / st2client / st2client / commands / action_alias.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

from st2client.models import core
from st2client.models.action_alias import ActionAlias
from st2client.models.action_alias import ActionAliasMatch
from st2client.commands import resource
from st2client.formatters import table


__all__ = ['ActionAliasBranch', 'ActionAliasMatchCommand', 'ActionAliasExecuteCommand']


class ActionAliasBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(ActionAliasBranch, self).__init__(
            ActionAlias,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            read_only=False,
            commands={'list': ActionAliasListCommand, 'get': ActionAliasGetCommand},
        )

        self.commands['match'] = ActionAliasMatchCommand(
            self.resource, self.app, self.subparsers, add_help=True
        )
        self.commands['execute'] = ActionAliasExecuteCommand(
            self.resource, self.app, self.subparsers, add_help=True
github StackStorm / st2 / st2client / st2client / commands / inquiry.py View on Github external
from __future__ import absolute_import

import json
import logging

from st2client.commands import resource
from st2client.formatters import table
from st2client.models.inquiry import Inquiry
from st2client.utils.interactive import InteractiveForm

LOG = logging.getLogger(__name__)

DEFAULT_SCOPE = 'system'


class InquiryBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):

        super(InquiryBranch, self).__init__(
            Inquiry,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            read_only=True,
            commands={'list': InquiryListCommand, 'get': InquiryGetCommand},
        )

        # Register extended commands
        self.commands['respond'] = InquiryRespondCommand(self.resource, self.app, self.subparsers)
github StackStorm / st2 / st2client / st2client / commands / service_registry.py View on Github external
class ServiceRegistryGroupsBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(ServiceRegistryGroupsBranch, self).__init__(
            ServiceRegistryGroup,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            read_only=True,
            commands={'list': ServiceRegistryListGroupsCommand, 'get': NoopCommand},
        )

        del self.commands['get']


class ServiceRegistryMembersBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(ServiceRegistryMembersBranch, self).__init__(
            ServiceRegistryMember,
            description,
            app,
            subparsers,
            parent_parser=parent_parser,
            read_only=True,
            commands={'list': ServiceRegistryListMembersCommand, 'get': NoopCommand},
        )

        del self.commands['get']


class ServiceRegistryListGroupsCommand(resource.ResourceListCommand):
    display_attributes = ['group_id']
github StackStorm / st2 / st2client / st2client / commands / action.py View on Github external
now = int(time.time())
        elapsed_seconds = (now - start_timestamp)
        instance.status = '%s (%ss elapsed)' % (instance.status, elapsed_seconds)
    elif status in LIVEACTION_COMPLETED_STATES and start_timestamp and end_timestamp:
        start_timestamp = parse_isotime(start_timestamp)
        start_timestamp = calendar.timegm(start_timestamp.timetuple())
        end_timestamp = parse_isotime(end_timestamp)
        end_timestamp = calendar.timegm(end_timestamp.timetuple())

        elapsed_seconds = (end_timestamp - start_timestamp)
        instance.status = '%s (%ss elapsed)' % (instance.status, elapsed_seconds)

    return instance


class ActionBranch(resource.ResourceBranch):

    def __init__(self, description, app, subparsers, parent_parser=None):
        super(ActionBranch, self).__init__(
            models.Action, description, app, subparsers,
            parent_parser=parent_parser,
            commands={
                'list': ActionListCommand,
                'get': ActionGetCommand,
                'update': ActionUpdateCommand,
                'delete': ActionDeleteCommand
            })

        # Registers extended commands
        self.commands['enable'] = ActionEnableCommand(self.resource, self.app, self.subparsers)
        self.commands['disable'] = ActionDisableCommand(self.resource, self.app, self.subparsers)
        self.commands['execute'] = ActionRunCommand(
github StackStorm / st2 / st2client / st2client / commands / rbac.py View on Github external
return result

    def run_and_print(self, args, **kwargs):
        instances = self.run(args, **kwargs)
        self.print_output(instances, table.MultiColumnTable,
                          attributes=args.attr, widths=args.width,
                          json=args.json, yaml=args.yaml)


class RoleGetCommand(resource.ResourceGetCommand):
    display_attributes = ['all']
    attribute_display_order = ROLE_ATTRIBUTE_DISPLAY_ORDER
    pk_argument_name = 'id'


class RoleAssignmentBranch(resource.ResourceBranch):
    def __init__(self, description, app, subparsers, parent_parser=None):
        super(RoleAssignmentBranch, self).__init__(
            UserRoleAssignment, description, app, subparsers,
            parent_parser=parent_parser,
            read_only=True,
            commands={
                'list': RoleAssignmentListCommand,
                'get': RoleAssignmentGetCommand
            })


class RoleAssignmentListCommand(resource.ResourceCommand):
    display_attributes = ['id', 'role', 'user', 'is_remote', 'source', 'description']
    attribute_display_order = ROLE_ASSIGNMENT_ATTRIBUTE_DISPLAY_ORDER

    def __init__(self, resource, *args, **kwargs):