def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        compute_client = self.app.client_manager.compute
        volume_client = self.app.client_manager.volume

        compute_limits = compute_client.limits.get(parsed_args.is_reserved)
        volume_limits = volume_client.limits.get()

        if parsed_args.is_absolute:
            compute_limits = compute_limits.absolute
            volume_limits = volume_limits.absolute
            columns = ["Name", "Value"]
            return (columns, (utils.get_item_properties(s, columns)
                    for s in itertools.chain(compute_limits, volume_limits)))

        elif parsed_args.is_rate:
            compute_limits = compute_limits.rate
            volume_limits = volume_limits.rate
            columns = ["Verb", "URI", "Value", "Remain", "Unit",
                       "Next Available"]
            return (columns, (utils.get_item_properties(s, columns)
                    for s in itertools.chain(compute_limits, volume_limits)))

        else:
            return ({}, {})
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.data_processing

        data = client.job_binaries.list()

        if parsed_args.name:
            data = utils.get_by_name_substring(data, parsed_args.name)

        if parsed_args.long:
            columns = ('name', 'id', 'url', 'description', 'is_public',
                       'is_protected')
            column_headers = utils.prepare_column_headers(columns)

        else:
            columns = ('name', 'id', 'url')
            column_headers = utils.prepare_column_headers(columns)

        return (
            column_headers,
            (osc_utils.get_item_properties(
                s,
                columns
            ) for s in data)
        )
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.baremetal

        columns = res_fields.NODE_RESOURCE

        params = {}
        if parsed_args.limit is not None and parsed_args.limit < 0:
            raise exc.CommandError(
                _('Expected non-negative --limit, got %s') %
                parsed_args.limit)
        params['limit'] = parsed_args.limit
        params['marker'] = parsed_args.marker
        if parsed_args.associated:
            params['associated'] = parsed_args.associated
        if parsed_args.maintenance:
            params['maintenance'] = parsed_args.maintenance

        if parsed_args.long:
            columns = res_fields.NODE_DETAILED_RESOURCE
        params['detail'] = parsed_args.long

        self.log.debug("params(%s)" % params)
        data = client.node.list(**params)

        data = oscutils.sort_items(data, parsed_args.sort)

        return (columns.labels,
                (oscutils.get_item_properties(s, columns.fields, formatters={
                    'Properties': oscutils.format_dict},) for s in data))
    def take_action_network(self, client, parsed_args):
        column_headers = self._get_column_headers(parsed_args)
        columns = (
            'id',
            'protocol',
            'remote_ip_prefix',
            'port_range_min',
            'remote_group_id',
        )

        # Get the security group rules using the requested query.
        query = {}
        if parsed_args.group is not None:
            # NOTE(rtheis): Unfortunately, the security group resource
            # does not contain security group rules resources. So use
            # the security group ID in a query to get the resources.
            security_group_id = client.find_security_group(
                parsed_args.group,
                ignore_missing=False
            ).id
            query = {'security_group_id': security_group_id}
        else:
            columns = columns + ('security_group_id',)
        rules = list(client.security_group_rules(**query))

        # Reformat the rules to display a port range instead
        # of just the port range minimum. This maintains
        # output compatibility with compute.
        for rule in rules:
            rule.port_range_min = _format_network_port_range(rule)

        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                ) for s in rules))
    def take_action(self, parsed_args):
        client = self.app.client_manager.network

        columns = (
            'id',
            'name',
            'mac_address',
            'fixed_ips',
        )
        column_headers = (
            'ID',
            'Name',
            'MAC Address',
            'Fixed IP Addresses',
        )

        filters = {}
        if parsed_args.router:
            _router = client.find_router(parsed_args.router,
                                         ignore_missing=False)
            filters = {'device_id': _router.id}

        data = client.ports(**filters)

        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                    formatters=_formatters,
                ) for s in data))
    def take_action(self, parsed_args):

        def _get_project(project_id):
            try:
                return getattr(project_hash[project_id], 'name', project_id)
            except KeyError:
                return project_id

        self.log.debug("take_action(%s)", parsed_args)

        compute_client = self.app.client_manager.compute
        columns = (
            "ID",
            "Name",
            "Description",
        )
        column_headers = columns
        if parsed_args.all_projects:
            # TODO(dtroyer): Translate Project_ID to Project (name)
            columns = columns + ('Tenant ID',)
            column_headers = column_headers + ('Project',)
        search = {'all_tenants': parsed_args.all_projects}
        data = compute_client.security_groups.list(search_opts=search)

        projects = self.app.client_manager.identity.projects.list()
        project_hash = {}
        for project in projects:
            project_hash[project.id] = project

        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                    formatters={'Tenant ID': _get_project},
                ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        client = self.app.client_manager.orchestration

        fields = {
            'nested_depth': parsed_args.nested_depth,
            'with_detail': parsed_args.long,
            'filters': heat_utils.format_parameters(parsed_args.filter),
        }

        try:
            resources = client.resources.list(parsed_args.stack, **fields)
        except heat_exc.HTTPNotFound:
            msg = _('Stack not found: %s') % parsed_args.stack
            raise exc.CommandError(msg)

        columns = ['physical_resource_id', 'resource_type', 'resource_status',
                   'updated_time']

        if len(resources) >= 1 and not hasattr(resources[0], 'resource_name'):
            columns.insert(0, 'logical_resource_id')
        else:
            columns.insert(0, 'resource_name')

        if parsed_args.nested_depth or parsed_args.long:
            columns.append('stack_name')

        return (
            columns,
            (utils.get_item_properties(r, columns) for r in resources)
        )
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.data_processing
        search_opts = {}
        if parsed_args.plugin:
            search_opts['plugin_name'] = parsed_args.plugin
        if parsed_args.version:
            search_opts['hadoop_version'] = parsed_args.version

        data = client.cluster_templates.list(search_opts=search_opts)

        if parsed_args.name:
            data = utils.get_by_name_substring(data, parsed_args.name)

        if parsed_args.long:
            columns = ('name', 'id', 'plugin_name', 'hadoop_version',
                       'node_groups', 'description')
            column_headers = utils.prepare_column_headers(
                columns, {'hadoop_version': 'version'})

        else:
            columns = ('name', 'id', 'plugin_name', 'hadoop_version')
            column_headers = utils.prepare_column_headers(
                columns, {'hadoop_version': 'version'})

        return (
            column_headers,
            (osc_utils.get_item_properties(
                s,
                columns,
                formatters={
                    'node_groups': _format_node_groups_list
                }
            ) for s in data)
        )
Exemple #9
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        identity_client = self.app.client_manager.identity
        auth_ref = self.app.client_manager.auth_ref

        # Project and user are required, if not included in command args
        # default to the values used for authentication.  For token-flow
        # authentication they must be included on the command line.
        if not parsed_args.project:
            if self.app.client_manager.auth_ref:
                parsed_args.project = auth_ref.project_id
            else:
                msg = "Project must be specified"
                raise exceptions.CommandError(msg)
        if not parsed_args.user:
            if self.app.client_manager.auth_ref:
                parsed_args.user = auth_ref.user_id
            else:
                msg = "User must be specified"
                raise exceptions.CommandError(msg)

        project = utils.find_resource(identity_client.tenants, parsed_args.project)
        user = utils.find_resource(identity_client.users, parsed_args.user)

        data = identity_client.roles.roles_for_user(user.id, project.id)

        columns = ("ID", "Name", "Project", "User")

        # Add the names to the output even though they will be constant
        for role in data:
            role.user = user.name
            role.project = project.name

        return (columns, (utils.get_item_properties(s, columns, formatters={}) for s in data))
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        compute_client = self.app.client_manager.compute
        columns = ("Name", "Fingerprint")
        data = compute_client.keypairs.list()

        return (columns, (utils.get_item_properties(s, columns) for s in data))
Exemple #11
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        senlin_client = self.app.client_manager.clustering
        columns = ['id', 'name', 'type', 'created_at']
        queries = {
            'limit': parsed_args.limit,
            'marker': parsed_args.marker,
            'sort': parsed_args.sort,
            'global_project': parsed_args.global_project,
        }
        if parsed_args.filters:
            queries.update(senlin_utils.format_parameters(parsed_args.filters))

        policies = senlin_client.policies(**queries)
        formatters = {}
        if not parsed_args.full_id:
            formatters = {
                'id': lambda x: x[:8]
            }
        return (
            columns,
            (utils.get_item_properties(p, columns, formatters=formatters)
             for p in policies)
        )
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        senlin_client = self.app.client_manager.clustering
        columns = ['id', 'timestamp', 'obj_type', 'obj_id', 'obj_name',
                   'action', 'status', 'status_reason', 'level']
        queries = {
            'sort': parsed_args.sort,
            'limit': parsed_args.limit,
            'marker': parsed_args.marker,
            'global_project': parsed_args.global_project,
        }

        if parsed_args.filters:
            queries.update(senlin_utils.format_parameters(parsed_args.filters))

        formatters = {}
        if not parsed_args.full_id:
            formatters['id'] = lambda x: x[:8]
            formatters['obj_id'] = lambda x: x[:8] if x else ''

        events = senlin_client.events(**queries)
        return (
            columns,
            (utils.get_item_properties(e, columns, formatters=formatters)
             for e in events)
        )
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        columns = column_headers = (
            "ID",
            "IP Protocol",
            "IP Range",
            "Port Range",
            "Remote Security Group",
        )

        rules_to_list = []
        if parsed_args.group:
            group = utils.find_resource(
                compute_client.security_groups,
                parsed_args.group,
            )
            rules_to_list = group.rules
        else:
            columns = columns + ('parent_group_id',)
            column_headers = column_headers + ('Security Group',)
            for group in compute_client.security_groups.list():
                rules_to_list.extend(group.rules)

        # Argh, the rules are not Resources...
        rules = []
        for rule in rules_to_list:
            rules.append(security_group_rules.SecurityGroupRule(
                compute_client.security_group_rules,
                _xform_security_group_rule(rule),
            ))

        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                ) for s in rules))
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.data_processing
        search_opts = {'tags': parsed_args.tags} if parsed_args.tags else {}

        data = client.images.list(search_opts=search_opts)

        if parsed_args.name:
            data = utils.get_by_name_substring(data, parsed_args.name)

        if parsed_args.username:
            data = [i for i in data if parsed_args.username in i.username]

        if parsed_args.long:
            columns = ('name', 'id', 'username', 'tags', 'status',
                       'description')
            column_headers = [c.capitalize() for c in columns]

        else:
            columns = ('name', 'id', 'username', 'tags')
            column_headers = [c.capitalize() for c in columns]

        return (
            column_headers,
            (osc_utils.get_item_properties(
                s,
                columns,
                formatters={
                    'tags': osc_utils.format_list
                },
            ) for s in data)
        )
    def take_action(self, parsed_args):
        def _get_project(project_id):
            try:
                return getattr(project_hash[project_id], "name", project_id)
            except KeyError:
                return project_id

        self.log.debug("take_action(%s)", parsed_args)

        compute_client = self.app.client_manager.compute
        columns = ("ID", "Name", "Description")
        column_headers = columns
        if parsed_args.all_projects:
            # TODO(dtroyer): Translate Project_ID to Project (name)
            columns = columns + ("Tenant ID",)
            column_headers = column_headers + ("Project",)
        search = {"all_tenants": parsed_args.all_projects}
        data = compute_client.security_groups.list(search_opts=search)

        project_hash = {}
        try:
            projects = self.app.client_manager.identity.projects.list()
        except ks_exc.ClientException:
            # This fails when the user is not an admin, just move along
            pass
        else:
            for project in projects:
                project_hash[project.id] = project

        return (
            column_headers,
            (utils.get_item_properties(s, columns, formatters={"Tenant ID": _get_project}) for s in data),
        )
    def take_action(self, parsed_args):
        identity_client = self.app.client_manager.identity

        domain = None
        if parsed_args.domain:
            domain = common.find_domain(identity_client,
                                        parsed_args.domain).id

        if parsed_args.user:
            user = common.find_user(
                identity_client,
                parsed_args.user,
                parsed_args.user_domain,
            ).id
        else:
            user = None

        # List groups
        if parsed_args.long:
            columns = ('ID', 'Name', 'Domain ID', 'Description')
        else:
            columns = ('ID', 'Name')
        data = identity_client.groups.list(
            domain=domain,
            user=user,
        )

        return (
            columns,
            (utils.get_item_properties(
                s, columns,
                formatters={},
            ) for s in data)
        )
Exemple #17
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        client = self.app.client_manager.orchestration

        fields = {
            'stack_id': parsed_args.stack,
            'resource_name': parsed_args.resource,
            'event_id': parsed_args.event
        }

        try:
            client.stacks.get(parsed_args.stack)
            client.resources.get(parsed_args.stack, parsed_args.resource)
            event = client.events.get(**fields)
        except exc.HTTPNotFound as ex:
            raise exc.CommandError(str(ex))

        formatters = {
            'links': heat_utils.link_formatter,
            'resource_properties': heat_utils.json_formatter
        }

        columns = []
        for key in event.to_dict():
            columns.append(key)

        return columns, utils.get_item_properties(event, columns,
                                                  formatters=formatters)
 def take_action(self, parsed_args):
     self.log.debug("take_action(%s)" % parsed_args)
     client = self.app.client_manager.network
     obj = client.find_network(parsed_args.identifier, ignore_missing=False)
     columns = _get_columns(obj)
     data = utils.get_item_properties(obj, columns, formatters=_formatters)
     return (columns, data)
    def take_action(self, parsed_args):
        data = self.app.client_manager.network.subnet_pools()

        if parsed_args.long:
            headers = (
                'ID',
                'Name',
                'Prefixes',
                'Default Prefix Length',
                'Address Scope',
            )
            columns = (
                'id',
                'name',
                'prefixes',
                'default_prefixlen',
                'address_scope_id',
            )
        else:
            headers = (
                'ID',
                'Name',
                'Prefixes',
            )
            columns = (
                'id',
                'name',
                'prefixes',
            )

        return (headers,
                (utils.get_item_properties(
                    s, columns,
                    formatters=_formatters,
                ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        compute_client = self.app.client_manager.compute
        group = utils.find_resource(
            compute_client.security_groups,
            parsed_args.group,
        )

        # Argh, the rules are not Resources...
        rules = []
        for rule in group.rules:
            rules.append(security_group_rules.SecurityGroupRule(
                compute_client.security_group_rules,
                _xform_security_group_rule(rule),
            ))

        columns = column_headers = (
            "ID",
            "IP Protocol",
            "IP Range",
            "Port Range",
            "Remote Security Group",
        )
        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                ) for s in rules))
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)
        columns = ('ID', 'Name', 'Tenant ID', 'User ID')
        identity_client = self.app.client_manager.identity

        # user-only roles are not supported in KSL so we are
        # required to have a user and tenant; default to the
        # values used for authentication if not specified
        if not parsed_args.tenant:
            parsed_args.tenant = identity_client.auth_tenant_id
        if not parsed_args.user:
            parsed_args.user = identity_client.auth_user_id

        tenant = utils.find_resource(identity_client.tenants,
                                     parsed_args.tenant)
        user = utils.find_resource(identity_client.users, parsed_args.user)

        data = identity_client.roles.roles_for_user(user.id, tenant.id)

        # Add the names to the output even though they will be constant
        for role in data:
            role.user_id = user.name
            role.tenant_id = tenant.name

        return (columns,
                (utils.get_item_properties(
                    s, columns,
                    formatters={},
                ) for s in data))
    def take_action_compute(self, client, parsed_args):
        column_headers = self._get_column_headers(parsed_args)
        columns = (
            "ID",
            "IP Protocol",
            "IP Range",
            "Port Range",
            "Remote Security Group",
        )

        rules_to_list = []
        if parsed_args.group is not None:
            group = utils.find_resource(
                client.security_groups,
                parsed_args.group,
            )
            rules_to_list = group.rules
        else:
            columns = columns + ('parent_group_id',)
            search = {'all_tenants': parsed_args.all_projects}
            for group in client.security_groups.list(search_opts=search):
                rules_to_list.extend(group.rules)

        # NOTE(rtheis): Turn the raw rules into resources.
        rules = []
        for rule in rules_to_list:
            rules.append(compute_secgroup_rules.SecurityGroupRule(
                client.security_group_rules,
                network_utils.transform_compute_security_group_rule(rule),
            ))

        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                ) for s in rules))
 def get_data(self, parsed_args):
     self.log.debug('get_data(%s)' % parsed_args)
     nova_client = self.app.client_manager.compute
     search_opts = {
         'all_tenants': parsed_args.all_tenants,
         'reservation_id': parsed_args.reservation_id,
         'ip': parsed_args.ip,
         'ip6': parsed_args.ip6,
         'name': parsed_args.name,
         'image': parsed_args.image,
         'flavor': parsed_args.flavor,
         'status': parsed_args.status,
         'host': parsed_args.host,
         'instance_name': parsed_args.instance_name,
         }
     self.log.debug('search options: %s', search_opts)
     # FIXME(dhellmann): Consider adding other columns
     columns = ('ID', 'Name', 'Status', 'Networks')
     data = nova_client.servers.list(search_opts=search_opts)
     return (columns,
             (utils.get_item_properties(
                 s, columns,
                 formatters={'Networks': _format_servers_list_networks},
                 ) for s in data),
             )
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute

        data = compute_client.aggregates.list()

        if parsed_args.long:
            # Remove availability_zone from metadata because Nova doesn't
            for d in data:
                if 'availability_zone' in d.metadata:
                    d.metadata.pop('availability_zone')
            # This is the easiest way to change column headers
            column_headers = (
                "ID",
                "Name",
                "Availability Zone",
                "Properties",
            )
            columns = (
                "ID",
                "Name",
                "Availability Zone",
                "Metadata",
            )
        else:
            column_headers = columns = (
                "ID",
                "Name",
                "Availability Zone",
            )

        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                ) for s in data))
    def take_action(self, parsed_args):
        identity_client = self.app.client_manager.identity
        if parsed_args.long:
            columns = ('ID', 'Name', 'Domain ID', 'Description', 'Enabled')
        else:
            columns = ('ID', 'Name')
        kwargs = {}

        domain_id = None
        if parsed_args.domain:
            domain_id = common.find_domain(identity_client,
                                           parsed_args.domain).id
            kwargs['domain'] = domain_id

        if parsed_args.user:
            if parsed_args.domain:
                user_id = utils.find_resource(identity_client.users,
                                              parsed_args.user,
                                              domain_id=domain_id).id
            else:
                user_id = utils.find_resource(identity_client.users,
                                              parsed_args.user).id

            kwargs['user'] = user_id

        data = identity_client.projects.list(**kwargs)
        return (columns,
                (utils.get_item_properties(
                    s, columns,
                    formatters={},
                ) for s in data))
 def take_action(self, parsed_args):
     client = self.app.client_manager.network
     attrs = _get_attrs(self.app.client_manager, parsed_args)
     obj = client.create_subnet(**attrs)
     columns = _get_columns(obj)
     data = utils.get_item_properties(obj, columns, formatters=_formatters)
     return (columns, data)
Exemple #27
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        senlin_client = self.app.client_manager.clustering

        columns = ['id', 'name', 'index', 'status', 'cluster_id',
                   'physical_id', 'profile_name', 'created_at', 'updated_at']
        queries = {
            'cluster_id': parsed_args.cluster,
            'sort': parsed_args.sort,
            'limit': parsed_args.limit,
            'marker': parsed_args.marker,
            'global_project': parsed_args.global_project,
        }

        if parsed_args.filters:
            queries.update(senlin_utils.format_parameters(parsed_args.filters))

        nodes = senlin_client.nodes(**queries)

        if not parsed_args.full_id:
            formatters = {
                'id': lambda x: x[:8],
                'cluster_id': lambda x: x[:8] if x else '',
                'physical_id': lambda x: x[:8] if x else ''
            }
        else:
            formatters = {}

        return (
            columns,
            (utils.get_item_properties(n, columns, formatters=formatters)
             for n in nodes)
        )
    def take_action_network(self, client, parsed_args):
        # Get the security group ID to hold the rule.
        security_group_id = client.find_security_group(
            parsed_args.group,
            ignore_missing=False
        ).id

        # Build the create attributes.
        attrs = {}
        # TODO(rtheis): Add --direction option. Until then, continue
        # with the default of 'ingress'.
        attrs['direction'] = 'ingress'
        # TODO(rtheis): Add --ethertype option. Until then, continue
        # with the default of 'IPv4'
        attrs['ethertype'] = 'IPv4'
        # TODO(rtheis): Add port range support (type and code) for icmp
        # protocol. Until then, continue ignoring the port range.
        if parsed_args.proto != 'icmp':
            attrs['port_range_min'] = parsed_args.dst_port[0]
            attrs['port_range_max'] = parsed_args.dst_port[1]
        attrs['protocol'] = parsed_args.proto
        if parsed_args.src_group is not None:
            attrs['remote_group_id'] = client.find_security_group(
                parsed_args.src_group,
                ignore_missing=False
            ).id
        else:
            attrs['remote_ip_prefix'] = parsed_args.src_ip
        attrs['security_group_id'] = security_group_id

        # Create and show the security group rule.
        obj = client.create_security_group_rule(**attrs)
        columns = _get_columns(obj)
        data = utils.get_item_properties(obj, columns)
        return (columns, data)
Exemple #29
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.data_processing

        data = client.job_executions.list()
        for job in data:
            job.status = job.info['status']

        if parsed_args.status:
            data = [job for job in data
                    if job.info['status'] == parsed_args.status.replace(
                        '-', '').upper()]

        if parsed_args.long:
            columns = ('id', 'cluster id', 'job id', 'status', 'start time',
                       'end time')
            column_headers = utils.prepare_column_headers(columns)

        else:
            columns = ('id', 'cluster id', 'job id', 'status')
            column_headers = utils.prepare_column_headers(columns)

        return (
            column_headers,
            (osc_utils.get_item_properties(
                s,
                columns
            ) for s in data)
        )
 def take_action(self, parsed_args):
     compute_client = self.app.client_manager.compute
     if parsed_args.long:
         columns = (
             "Id",
             "Binary",
             "Host",
             "Zone",
             "Status",
             "State",
             "Updated At",
             "Disabled Reason"
         )
     else:
         columns = (
             "Id",
             "Binary",
             "Host",
             "Zone",
             "Status",
             "State",
             "Updated At"
         )
     data = compute_client.services.list(parsed_args.host,
                                         parsed_args.service)
     return (columns,
             (utils.get_item_properties(
                 s, columns,
             ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)
        compute_client = self.app.client_manager.compute

        columns = ('ID', 'Pool', 'IP', 'Fixed IP', 'Instance ID')

        data = compute_client.floating_ips.list()

        return (columns, (utils.get_item_properties(
            s,
            columns,
            formatters={},
        ) for s in data))
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        columns = ("ID", "Hypervisor Hostname")

        if parsed_args.matching:
            data = compute_client.hypervisors.search(parsed_args.matching)
        else:
            data = compute_client.hypervisors.list()

        return (columns, (utils.get_item_properties(
            s,
            columns,
        ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        compute_client = self.app.client_manager.compute
        columns = (
            "Name",
            "Fingerprint"
        )
        data = compute_client.keypairs.list()

        return (columns,
                (utils.get_item_properties(
                    s, columns,
                ) for s in data))
Exemple #34
0
 def take_action(self, parsed_args):
     self.log.debug('take_action(%s)' % parsed_args)
     if parsed_args.long:
         columns = ('ID', 'Name', 'Type', 'Description')
     else:
         columns = ('ID', 'Name')
     data = self.app.client_manager.identity.services.list()
     return (columns,
             (utils.get_item_properties(
                 s, columns,
                 formatters={},
             ) for s in data),
            )
 def take_action(self, parsed_args):
     if parsed_args.long:
         columns = ['ID', 'Name', 'Description', 'Extra Specs']
         column_headers = ['ID', 'Name', 'Description', 'Properties']
     else:
         columns = ['ID', 'Name']
         column_headers = columns
     data = self.app.client_manager.volume.volume_types.list()
     return (column_headers, (utils.get_item_properties(
         s,
         columns,
         formatters={'Extra Specs': utils.format_dict},
     ) for s in data))
Exemple #36
0
 def take_action(self, parsed_args):
     self.log.debug('take_action(%s)' % parsed_args)
     if parsed_args.long:
         columns = ('ID', 'Name', 'Project Id', 'Domain Id',
                    'Description', 'Email', 'Enabled')
     else:
         columns = ('ID', 'Name')
     data = self.app.client_manager.identity.users.list()
     return (columns,
             (utils.get_item_properties(
                 s, columns,
                 formatters={},
             ) for s in data))
Exemple #37
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)
        compute_client = self.app.client_manager.compute

        columns = ('Name',)

        data = compute_client.floating_ip_pools.list()

        return (columns,
                (utils.get_item_properties(
                    s, columns,
                    formatters={},
                ) for s in data))
 def take_action(self, parsed_args):
     if parsed_args.long:
         columns = ('ID', 'Type', 'Blob')
         column_headers = ('ID', 'Type', 'Rules')
     else:
         columns = ('ID', 'Type')
         column_headers = columns
     data = self.app.client_manager.identity.policies.list()
     return (column_headers, (utils.get_item_properties(
         s,
         columns,
         formatters={},
     ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.page_size is not None:
            kwargs["page_size"] = parsed_args.page_size

        data = image_client.images.list(**kwargs)
        columns = ["ID", "Name"]

        return (columns, (utils.get_item_properties(s, columns) for s in data))
    def take_action(self, parsed_args):
        client_manager = self.app.client_manager
        user = _determine_ec2_user(parsed_args, client_manager)

        columns = ('access', 'secret', 'tenant_id', 'user_id')
        column_headers = ('Access', 'Secret', 'Project ID', 'User ID')
        data = client_manager.identity.ec2.list(user)

        return (column_headers, (utils.get_item_properties(
            s,
            columns,
            formatters={},
        ) for s in data))
Exemple #41
0
    def take_action_network(self, client, parsed_args):
        # Get the security group ID to hold the rule.
        security_group_id = client.find_security_group(
            parsed_args.group,
            ignore_missing=False
        ).id

        # Build the create attributes.
        attrs = {}
        # NOTE(rtheis): A direction must be specified and ingress
        # is the default.
        if parsed_args.ingress or not parsed_args.egress:
            attrs['direction'] = 'ingress'
        if parsed_args.egress:
            attrs['direction'] = 'egress'
        if parsed_args.ethertype:
            attrs['ethertype'] = parsed_args.ethertype
        else:
            # NOTE(rtheis): Default based on protocol is IPv4 for now.
            # Once IPv6 protocols are added, this will need to be updated.
            attrs['ethertype'] = 'IPv4'
        # TODO(rtheis): Add port range support (type and code) for icmp
        # protocol. Until then, continue ignoring the port range.
        if parsed_args.proto != 'icmp':
            attrs['port_range_min'] = parsed_args.dst_port[0]
            attrs['port_range_max'] = parsed_args.dst_port[1]
        attrs['protocol'] = parsed_args.proto
        if parsed_args.src_group is not None:
            attrs['remote_group_id'] = client.find_security_group(
                parsed_args.src_group,
                ignore_missing=False
            ).id
        elif parsed_args.src_ip is not None:
            attrs['remote_ip_prefix'] = parsed_args.src_ip
        elif attrs['ethertype'] == 'IPv4':
            attrs['remote_ip_prefix'] = '0.0.0.0/0'
        attrs['security_group_id'] = security_group_id
        if parsed_args.project is not None:
            identity_client = self.app.client_manager.identity
            project_id = identity_common.find_project(
                identity_client,
                parsed_args.project,
                parsed_args.project_domain,
            ).id
            attrs['tenant_id'] = project_id

        # Create and show the security group rule.
        obj = client.create_security_group_rule(**attrs)
        columns = _get_columns(obj)
        data = utils.get_item_properties(obj, columns)
        return (columns, data)
 def take_action(self, parsed_args):
     compute_client = self.app.client_manager.compute
     columns = (
         "Host",
         "Project",
         "CPU",
         "Memory MB",
         "Disk GB"
     )
     data = compute_client.hosts.get(parsed_args.host)
     return (columns,
             (utils.get_item_properties(
                 s, columns,
             ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug("take_action: (%s)", parsed_args)

        def _format_volume_id(volume_id):
            """Return a volume name if available

            :param volume_id: a volume ID
            :rtype: either the volume ID or name
            """

            volume = volume_id
            if volume_id in volume_cache.keys():
                volume = volume_cache[volume_id].name
            return volume

        if parsed_args.long:
            columns = [
                'ID', 'Name', 'Description', 'Status', 'Size', 'Created At',
                'Volume ID', 'Metadata'
            ]
            column_headers = copy.deepcopy(columns)
            column_headers[6] = 'Volume'
            column_headers[7] = 'Properties'
        else:
            columns = ['ID', 'Name', 'Description', 'Status', 'Size']
            column_headers = copy.deepcopy(columns)

        # Cache the volume list
        volume_cache = {}
        try:
            for s in self.app.client_manager.volume.volumes.list():
                volume_cache[s.id] = s
        except Exception:
            # Just forget it if there's any trouble
            pass

        search_opts = {
            'all_tenants': parsed_args.all_projects,
        }

        data = self.app.client_manager.volume.volume_snapshots.list(
            search_opts=search_opts)
        return (column_headers, (utils.get_item_properties(
            s,
            columns,
            formatters={
                'Metadata': utils.format_dict,
                'Volume ID': _format_volume_id
            },
        ) for s in data))
 def take_action(self, parsed_args):
     compute_client = self.app.client_manager.compute
     if parsed_args.long:
         columns = ("Id", "Binary", "Host", "Zone", "Status", "State",
                    "Updated At", "Disabled Reason")
     else:
         columns = ("Id", "Binary", "Host", "Zone", "Status", "State",
                    "Updated At")
     data = compute_client.services.list(parsed_args.host,
                                         parsed_args.service)
     return (columns, (utils.get_item_properties(
         s,
         columns,
     ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)

        identity_client = self.app.client_manager.identity
        user = utils.find_resource(identity_client.users, parsed_args.user).id

        columns = ('ID', 'Consumer ID', 'Expires At', 'Project Id',
                   'Authorizing User Id')
        data = identity_client.tokens.list_access_tokens(user)
        return (columns, (utils.get_item_properties(
            s,
            columns,
            formatters={},
        ) for s in data))
Exemple #46
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)

        identity_client = self.app.client_manager.identity
        user = utils.find_resource(identity_client.users, parsed_args.user).id

        columns = ('Access Key', 'Consumer Key', 'Issued At', 'Project Id',
                   'User Id', 'Requested Roles')
        data = identity_client.oauth.list_authorizations(user)
        return (columns, (utils.get_item_properties(
            s,
            columns,
            formatters={},
        ) for s in data))
 def _get_return_data(self, data, include_project=True):
     columns = (
         "ID",
         "Name",
         "Description",
     )
     column_headers = columns
     if include_project:
         columns = columns + ('Tenant ID',)
         column_headers = column_headers + ('Project',)
     return (column_headers,
             (utils.get_item_properties(
                 s, columns,
             ) for s in data))
Exemple #48
0
    def take_action_network(self, client, parsed_args):
        if parsed_args.long:
            columns = (
                'id',
                'name',
                'status',
                'tenant_id',
                'admin_state_up',
                'shared',
                'subnets',
                'provider_network_type',
                'router_external',
                'availability_zones',
            )
            column_headers = (
                'ID',
                'Name',
                'Status',
                'Project',
                'State',
                'Shared',
                'Subnets',
                'Network Type',
                'Router Type',
                'Availability Zones',
            )
        else:
            columns = (
                'id',
                'name',
                'subnets'
            )
            column_headers = (
                'ID',
                'Name',
                'Subnets',
            )

        if parsed_args.external:
            args = {'router:external': True}
        else:
            args = {}

        data = client.networks(**args)

        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                    formatters=_formatters,
                ) for s in data))
Exemple #49
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        client = self.app.client_manager.messaging

        kwargs = {}
        if parsed_args.marker is not None:
            kwargs["marker"] = parsed_args.marker
        if parsed_args.limit is not None:
            kwargs["limit"] = parsed_args.limit

        data = client.queues(**kwargs)
        columns = ("Name", )
        return (columns, (utils.get_item_properties(s, columns) for s in data))
 def take_action(self, parsed_args):
     self.log.debug('take_action(%s)' % parsed_args)
     if parsed_args.long:
         columns = ('ID', 'Name', 'Extra Specs')
         column_headers = ('ID', 'Name', 'Properties')
     else:
         columns = ('ID', 'Name')
         column_headers = columns
     data = self.app.client_manager.volume.volume_types.list()
     return (column_headers, (utils.get_item_properties(
         s,
         columns,
         formatters={'Extra Specs': utils.format_dict},
     ) for s in data))
Exemple #51
0
    def take_action(self, parsed_args):
        client = self.app.client_manager.network

        attrs = _get_attrs(self.app.client_manager, parsed_args)
        obj = client.create_router(**attrs)

        columns = sorted(obj.keys())
        data = utils.get_item_properties(obj, columns, formatters=_formatters)

        if 'tenant_id' in columns:
            # Rename "tenant_id" to "project_id".
            index = columns.index('tenant_id')
            columns[index] = 'project_id'
        return (tuple(columns), data)
    def take_action(self, parsed_args):
        def _format_volume_id(volume_id):
            """Return a volume name if available

            :param volume_id: a volume ID
            :rtype: either the volume ID or name
            """

            volume = volume_id
            if volume_id in volume_cache.keys():
                volume = volume_cache[volume_id].display_name
            return volume

        if parsed_args.long:
            columns = [
                'ID', 'Display Name', 'Display Description', 'Status', 'Size',
                'Created At', 'Volume ID', 'Metadata'
            ]
            column_headers = copy.deepcopy(columns)
            column_headers[6] = 'Volume'
            column_headers[7] = 'Properties'
        else:
            columns = [
                'ID', 'Display Name', 'Display Description', 'Status', 'Size'
            ]
            column_headers = copy.deepcopy(columns)

        # Always update Name and Description
        column_headers[1] = 'Name'
        column_headers[2] = 'Description'

        # Cache the volume list
        volume_cache = {}
        try:
            for s in self.app.client_manager.volume.volumes.list():
                volume_cache[s.id] = s
        except Exception:
            # Just forget it if there's any trouble
            pass

        data = self.app.client_manager.volume.volume_snapshots.list()
        return (column_headers, (utils.get_item_properties(
            s,
            columns,
            formatters={
                'Metadata': utils.format_dict,
                'Volume ID': _format_volume_id
            },
        ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)
        client = self.app.client_manager.network

        if parsed_args.long:
            columns = (
                'id',
                'name',
                'status',
                'tenant_id',
                'admin_state_up',
                'shared',
                'subnets',
                'provider_network_type',
                'router_external',
            )
            column_headers = (
                'ID',
                'Name',
                'Status',
                'Project',
                'State',
                'Shared',
                'Subnets',
                'Network Type',
                'Router Type',
            )
        else:
            columns = (
                'id',
                'name',
                'subnets'
            )
            column_headers = (
                'ID',
                'Name',
                'Subnets',
            )

        if parsed_args.external:
            args = {'router:external': True}
        else:
            args = {}
        data = client.networks(**args)
        return (column_headers,
                (utils.get_item_properties(
                    s, columns,
                    formatters=_formatters,
                ) for s in data))
Exemple #54
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        client = self.app.client_manager.orchestration

        version = parsed_args.template_version
        try:
            functions = client.template_versions.get(version)
        except exc.HTTPNotFound:
            msg = _('Template version not found: %s') % version
            raise exc.CommandError(msg)

        fields = ['functions', 'description']
        return (fields, (utils.get_item_properties(s, fields)
                         for s in functions))
Exemple #55
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        compute_client = self.app.client_manager.compute
        columns = ("Host", "Service", "Disabled")

        if parsed_args.enabled:
            action = compute_client.services.enable
        else:
            action = compute_client.services.disable

        data = action(parsed_args.host, parsed_args.service)
        return (columns, (utils.get_item_properties(
            s,
            columns,
        ) for s in data))
Exemple #56
0
 def take_action(self, parsed_args):
     self.log.debug('take_action(%s)' % parsed_args)
     columns = (
         'ID',
         'Display Name',
         'Display Description',
         'Status',
         'Size'
     )
     data = self.app.client_manager.volume.backups.list()
     return (columns,
             (utils.get_item_properties(
                 s, columns,
                 formatters={},
             ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)
        identity_client = self.app.client_manager.identity
        columns = ('ID', 'Region', 'Service Name', 'Service Type', 'Enabled',
                   'Interface', 'URL')
        data = identity_client.endpoints.list()

        for ep in data:
            service = common.find_service(identity_client, ep.service_id)
            ep.service_name = service.name
            ep.service_type = service.type
        return (columns, (utils.get_item_properties(
            s,
            columns,
            formatters={},
        ) for s in data))
Exemple #58
0
    def take_action(self, parsed_args):
        identity_client = self.app.client_manager.identity

        kwargs = {}
        if parsed_args.parent_region:
            kwargs['parent_region_id'] = parsed_args.parent_region

        columns_headers = ('Region', 'Parent Region', 'Description')
        columns = ('ID', 'Parent Region Id', 'Description')

        data = identity_client.regions.list(**kwargs)
        return (columns_headers,
                (utils.get_item_properties(
                    s, columns,
                    formatters={},
                ) for s in data))
Exemple #59
0
 def take_action(self, parsed_args):
     compute_client = self.app.client_manager.compute
     columns = (
         "Agent ID",
         "Hypervisor",
         "OS",
         "Architecture",
         "Version",
         "Md5Hash",
         "URL"
     )
     data = compute_client.agents.list(parsed_args.hypervisor)
     return (columns,
             (utils.get_item_properties(
                 s, columns,
             ) for s in data))
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.page_size is not None:
            kwargs["page_size"] = parsed_args.page_size

        data = image_client.images.list(**kwargs)
        if parsed_args.long:
            columns = ('ID', 'Name', 'Disk Format', 'Container Format', 'Size',
                       'Status')
        else:
            columns = ("ID", "Name")

        return (columns, (utils.get_item_properties(s, columns) for s in data))