def take_action(self, parsed_args):

        if parsed_args.long:
            columns = ('Zone Name', 'Zone Status', 'Zone Resource',
                       'Host Name', 'Service Name', 'Service Status')
        else:
            columns = ('Zone Name', 'Zone Status')

        # Show everything by default.
        show_all = (not parsed_args.compute and
                    not parsed_args.volume and
                    not parsed_args.network)

        result = []
        if parsed_args.compute or show_all:
            result += self._get_compute_availability_zones(parsed_args)
        if parsed_args.volume or show_all:
            result += self._get_volume_availability_zones(parsed_args)
        if parsed_args.network or show_all:
            result += self._get_network_availability_zones(parsed_args)

        return (columns,
                (utils.get_dict_properties(
                    s, columns
                ) for s in result))
Ejemplo n.º 2
0
    def _get_detailed_quotas(self, parsed_args):
        columns = (
            'resource',
            'in_use',
            'reserved',
            'limit'
        )
        column_headers = (
            'Resource',
            'In Use',
            'Reserved',
            'Limit'
        )
        quotas = {}
        if parsed_args.compute:
            quotas.update(self.get_compute_quota(
                self.app.client_manager.compute, parsed_args))
        if parsed_args.network:
            quotas.update(self.get_network_quota(parsed_args))

        result = []
        for resource, values in quotas.items():
            # NOTE(slaweq): there is no detailed quotas info for some resources
            # and it should't be displayed here
            if type(values) is dict:
                result.append({
                    'resource': resource,
                    'in_use': values.get('in_use'),
                    'reserved': values.get('reserved'),
                    'limit': values.get('limit')
                })
        return (column_headers,
                (utils.get_dict_properties(
                    s, columns,
                ) for s in result))
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     ppg_id = _get_id(client, parsed_args.port_pair_group, resource)
     obj = client.show_sfc_port_pair_group(ppg_id)[resource]
     columns, display_columns = nc_osc_utils.get_columns(obj, _attr_map)
     data = utils.get_dict_properties(obj, columns)
     return display_columns, data
Ejemplo n.º 4
0
 def take_action(self, parsed_args):
     self.log.debug("take_action(%s)", parsed_args)
     client = self.app.client_manager.messaging
     flavor_data = client.flavor(parsed_args.flavor_name,
                                 auto_create=False).get()
     columns = ('Name', 'Pool Group', 'Capabilities')
     return columns, utils.get_dict_properties(flavor_data, columns)
Ejemplo n.º 5
0
    def take_action(self, parsed_args):
        client = _get_client(self, parsed_args)

        pool_data = client.pool(parsed_args.pool_name,
                                auto_create=False).get()
        columns = ('Name', 'Weight', 'URI', 'Group', 'Options')
        return columns, utils.get_dict_properties(pool_data, columns)
    def take_action(self, parsed_args):

        if parsed_args.long:
            columns = ('Name', 'Bytes', 'Count')
        else:
            columns = ('Name',)

        kwargs = {}
        if parsed_args.prefix:
            kwargs['prefix'] = parsed_args.prefix
        if parsed_args.marker:
            kwargs['marker'] = parsed_args.marker
        if parsed_args.end_marker:
            kwargs['end_marker'] = parsed_args.end_marker
        if parsed_args.limit:
            kwargs['limit'] = parsed_args.limit
        if parsed_args.all:
            kwargs['full_listing'] = True

        data = self.app.client_manager.object_store.container_list(
            **kwargs
        )

        return (columns,
                (utils.get_dict_properties(
                    s, columns,
                    formatters={},
                ) for s in data))
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     obj = client.list_fwaas_firewall_groups()[const.FWGS]
     headers, columns = column_util.get_column_definitions(
         _attr_map, long_listing=parsed_args.long)
     return (headers, (utils.get_dict_properties(
         s, columns, formatters=_formatters) for s in obj))
Ejemplo n.º 8
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     attrs = {}
     if parsed_args.name is not None:
         attrs['name'] = str(parsed_args.name)
     if parsed_args.type is not None:
         attrs['type'] = parsed_args.type
     if parsed_args.route_targets is not None:
         attrs['route_targets'] = parsed_args.route_targets
     if parsed_args.import_targets is not None:
         attrs['import_targets'] = parsed_args.import_targets
     if parsed_args.export_targets is not None:
         attrs['export_targets'] = parsed_args.export_targets
     if parsed_args.route_distinguishers is not None:
         attrs['route_distinguishers'] = parsed_args.route_distinguishers
     if parsed_args.vni is not None:
         attrs['vni'] = parsed_args.vni
     if parsed_args.local_pref is not None:
         attrs['local_pref'] = parsed_args.local_pref
     if 'project' in parsed_args and parsed_args.project is not None:
         project_id = nc_osc_utils.find_project(
             self.app.client_manager.identity,
             parsed_args.project,
             parsed_args.project_domain,
         ).id
         attrs['tenant_id'] = project_id
     body = {constants.BGPVPN: attrs}
     obj = client.create_bgpvpn(body)[constants.BGPVPN]
     columns, display_columns = column_util.get_columns(obj, _attr_map)
     data = osc_utils.get_dict_properties(obj, columns,
                                          formatters=_formatters)
     return display_columns, data
Ejemplo n.º 9
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        search_client = self.app.client_manager.search
        columns = (
            "Resource Type",
            "Type",
            "Name",
            "Options"
        )
        params = {
            "type": parsed_args.type,
            "limit_terms": parsed_args.limit_terms,
            "all_projects": parsed_args.all_projects
        }
        data = search_client.facets.list(**params)
        result = []
        for resource_type, values in data.items():
            if isinstance(values, list):
                # Cope with pre-1.0 service APIs
                facets = values
            else:
                facets = values['facets']
            for s in facets:
                options = []
                for o in s.get('options', []):
                    options.append(
                        str(o['key']) + '(' + str(o['doc_count']) + ')')
                s["options"] = ', '.join(options)
                s["resource_type"] = resource_type
                result.append(utils.get_dict_properties(s, columns))
        return (columns, result)
    def take_action(self, parsed_args):
        client = self.app.client_manager.neutronclient
        create_method = getattr(
            client, 'create_bgpvpn_%s_assoc' % self._assoc_res_name)
        bgpvpn = client.find_resource(constants.BGPVPN, parsed_args.bgpvpn)
        assoc_res = client.find_resource(self._assoc_res_name,
                                         parsed_args.resource)
        body = {
            self._resource: {
                '%s_id' % self._assoc_res_name: assoc_res['id'],
            },
        }
        if 'project' in parsed_args and parsed_args.project is not None:
            project_id = nc_osc_utils.find_project(
                self.app.client_manager.identity,
                parsed_args.project,
                parsed_args.project_domain,
            ).id
            body[self._resource]['tenant_id'] = project_id

        arg2body = getattr(self, '_args2body', None)
        if callable(arg2body):
            body[self._resource].update(
                arg2body(bgpvpn['id'], parsed_args)[self._resource])

        obj = create_method(bgpvpn['id'], body)[self._resource]
        transform = getattr(self, '_transform_resource', None)
        if callable(transform):
            transform(obj)
        columns, display_columns = nc_osc_utils.get_columns(obj,
                                                            self._attr_map)
        data = osc_utils.get_dict_properties(obj, columns,
                                             formatters=self._formatters)
        return display_columns, data
Ejemplo n.º 11
0
def _show_config(heat_client, config_id, config_only):
    try:
        sc = heat_client.software_configs.get(config_id=config_id)
    except heat_exc.HTTPNotFound:
        raise exc.CommandError(_('Configuration not found: %s') % config_id)

    columns = None
    rows = None

    if config_only:
        print(sc.config)
    else:
        columns = (
            'id',
            'name',
            'group',
            'config',
            'inputs',
            'outputs',
            'options',
            'creation_time',
        )
        rows = utils.get_dict_properties(sc.to_dict(), columns)

    return columns, rows
Ejemplo n.º 12
0
 def _test_get_dict_properties_with_formatter(self, formatters):
     names = ('id', 'attr')
     item = {'id': 'fake-id', 'attr': ['a', 'b']}
     res_id, res_attr = utils.get_dict_properties(item, names,
                                                  formatters=formatters)
     self.assertEqual('fake-id', res_id)
     return res_attr
Ejemplo n.º 13
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     data = client.list_trunks()
     headers = (
         'ID',
         'Name',
         'Parent Port',
         'Description'
     )
     columns = (
         'id',
         'name',
         'port_id',
         'description'
     )
     if parsed_args.long:
         headers += (
             'Status',
             'State',
             'Created At',
             'Updated At',
         )
         columns += (
             'status',
             'admin_state_up',
             'created_at',
             'updated_at'
         )
     return (headers,
             (osc_utils.get_dict_properties(
                 s, columns,
                 formatters=_formatters,
             ) for s in data[TRUNKS]))
Ejemplo n.º 14
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     attrs = _get_common_attrs(self.app.client_manager, parsed_args)
     obj = client.create_network_log({'log': attrs})['log']
     columns, display_columns = osc_utils.get_columns(obj, _attr_map)
     data = utils.get_dict_properties(obj, columns)
     return (display_columns, data)
Ejemplo n.º 15
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     attrs = _get_common_attrs(self.app.client_manager, parsed_args)
     obj = common.create_sfc_resource(self, client, resource, attrs)
     columns = common.get_columns(obj[resource])
     data = utils.get_dict_properties(obj[resource], columns)
     return columns, data
Ejemplo n.º 16
0
    def take_action(self, parsed_args):
        if parsed_args.name:
            if len(parsed_args.objects) > 1:
                msg = _('Attempting to upload multiple objects and '
                        'using --name is not permitted')
                raise exceptions.CommandError(msg)
        results = []
        for obj in parsed_args.objects:
            if len(obj) > 1024:
                LOG.warning(
                    _('Object name is %s characters long, default limit'
                      ' is 1024'), len(obj))
            data = self.app.client_manager.object_store.object_create(
                container=parsed_args.container,
                object=obj,
                name=parsed_args.name,
            )
            results.append(data)

        columns = ("object", "container", "etag")
        return (columns,
                (utils.get_dict_properties(
                    s, columns,
                    formatters={},
                ) for s in results))
Ejemplo n.º 17
0
 def take_action(self, parsed_args):
     client = _get_client(self, parsed_args)
     kwargs = {'id': parsed_args.subscription_id}
     pool_data = client.subscription(parsed_args.queue_name,
                                     **kwargs)
     columns = ('ID', 'Subscriber', 'TTL', 'Age', 'Confirmed', 'Options')
     return columns, utils.get_dict_properties(pool_data.__dict__, columns)
Ejemplo n.º 18
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.tackerclient
     _params = {}
     if parsed_args.nfp_id:
         _params['nfp_id'] = parsed_args.nfp_id
     if parsed_args.tenant_id:
         _params['tenant_id'] = parsed_args.tenant_id
     classifiers = client.list('classifiers', fcs_path, True,
                               **_params)
     for classifier in classifiers['classifiers']:
         error_reason = classifier.get('error_reason', None)
         if error_reason and \
                 len(error_reason) > DEFAULT_ERROR_REASON_LENGTH:
             classifier['error_reason'] = error_reason[
                 :DEFAULT_ERROR_REASON_LENGTH]
             classifier['error_reason'] += '...'
     data = {}
     data['classifiers'] = classifiers['classifiers']
     data = client.list_classifiers()
     headers, columns = tacker_osc_utils.get_column_definitions(
         _attr_map_fc, long_listing=None)
     return (headers,
             (utils.get_dict_properties(
                 s, columns,
             ) for s in data[_FC + 's']))
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     fc_id = _get_id(client, parsed_args.flow_classifier, resource)
     obj = client.show_sfc_flow_classifier(fc_id)[resource]
     columns, display_columns = nc_osc_utils.get_columns(obj, _attr_map)
     data = utils.get_dict_properties(obj, columns)
     return display_columns, data
Ejemplo n.º 20
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.tackerclient
     _params = {}
     if parsed_args.vim_id:
         _params['vim_id'] = parsed_args.vim_id
     if parsed_args.vim_name:
         vim_id = tackerV10.find_resourceid_by_name_or_id(
             client, 'vim', parsed_args.vim_name
         )
         _params['vim_id'] = vim_id
     if parsed_args.vnfd_id:
         _params['vnfd_id'] = parsed_args.vnfd_id
     if parsed_args.vnfd_name:
         vim_id = tackerV10.find_resourceid_by_name_or_id(
             client, 'vnfd', parsed_args.vnfd_name
         )
         _params['vnfd_id'] = vim_id
     if parsed_args.tenant_id:
         _params['tenant_id'] = parsed_args.tenant_id
     data = client.list_vnfs(**_params)
     headers, columns = tacker_osc_utils.get_column_definitions(
         _attr_map, long_listing=parsed_args.long)
     return (headers,
             (utils.get_dict_properties(
                 s, columns,
             ) for s in data[_VNF + 's']))
Ejemplo n.º 21
0
    def take_action(self, parsed_args):
        volume_client = self.app.client_manager.volume
        qos_specs_list = volume_client.qos_specs.list()

        for qos in qos_specs_list:
            try:
                qos_associations = volume_client.qos_specs.get_associations(
                    qos,
                )
                if qos_associations:
                    associations = [
                        association.name for association in qos_associations
                    ]
                    qos._info.update({'associations': associations})
            except Exception as ex:
                if type(ex).__name__ == 'NotFound':
                    qos._info.update({'associations': None})
                else:
                    raise

        display_columns = (
            'ID', 'Name', 'Consumer', 'Associations', 'Properties')
        columns = ('ID', 'Name', 'Consumer', 'Associations', 'Specs')
        return (display_columns,
                (utils.get_dict_properties(
                    s._info, columns,
                    formatters={
                        'Specs': utils.format_dict,
                        'Associations': utils.format_list
                    },
                ) for s in qos_specs_list))
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     sg_id = _get_id(client, parsed_args.service_graph, resource)
     obj = client.show_sfc_service_graph(sg_id)[resource]
     columns, display_columns = column_util.get_columns(obj, _attr_map)
     data = utils.get_dict_properties(obj, columns)
     return display_columns, data
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     obj = client.list_ipsec_site_connections()['ipsec_site_connections']
     headers, columns = osc_utils.get_column_definitions(
         _attr_map, long_listing=parsed_args.long)
     return (headers, (utils.get_dict_properties(
         s, columns, formatters=_formatters) for s in obj))
Ejemplo n.º 24
0
 def take_action(self, parsed_args):
     data = self.app.client_manager.neutronclient.list_bgp_peers()
     headers = ('ID', 'Name', 'Peer IP', 'Remote AS')
     columns = ('id', 'name', 'peer_ip', 'remote_as')
     return (headers,
             (utils.get_dict_properties(
                 s, columns,
             ) for s in data[constants.BGP_PEERS]))
Ejemplo n.º 25
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     attrs = _get_attrs(self.app.client_manager, parsed_args)
     body = {constants.BGP_PEER: attrs}
     obj = client.create_bgp_peer(body)[constants.BGP_PEER]
     columns, display_columns = column_util.get_columns(obj)
     data = utils.get_dict_properties(obj, columns)
     return display_columns, data
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     data = client.list_sfc_service_graphs()
     headers, columns = column_util.get_column_definitions(
         _attr_map, long_listing=parsed_args.long)
     return (headers,
             (utils.get_dict_properties(s, columns)
              for s in data['service_graphs']))
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     attrs = _get_common_attrs(self.app.client_manager, parsed_args)
     body = {resource: attrs}
     obj = client.create_sfc_flow_classifier(body)[resource]
     columns, display_columns = nc_osc_utils.get_columns(obj, _attr_map)
     data = utils.get_dict_properties(obj, columns)
     return display_columns, data
Ejemplo n.º 28
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     trunk_id = _get_id(client, parsed_args.trunk, TRUNK)
     obj = client.show_trunk(trunk_id)
     columns = _get_columns(obj[TRUNK])
     data = osc_utils.get_dict_properties(obj[TRUNK], columns,
                                          formatters=_formatters)
     return columns, data
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     obj = client.list_sfc_flow_classifiers()
     obj_extend = self.extend_list(obj, parsed_args)
     headers, columns = nc_osc_utils.get_column_definitions(
         _attr_map, long_listing=parsed_args.long)
     return (headers, (utils.get_dict_properties(
         s, columns) for s in obj_extend))
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     id = client.find_resource(constants.BGP_SPEAKER,
                               parsed_args.bgp_speaker)['id']
     obj = client.show_bgp_speaker(id)[constants.BGP_SPEAKER]
     columns, display_columns = column_util.get_columns(obj)
     data = utils.get_dict_properties(obj, columns)
     return display_columns, data
    def setUp(self):
        super(TestShareGroupList, self).setUp()

        self.new_share_group = (
            manila_fakes.FakeShareGroup.create_one_share_group())
        self.groups_mock.list.return_value = [self.new_share_group]

        self.share_group = (
            manila_fakes.FakeShareGroup.create_one_share_group())
        self.groups_mock.get.return_value = self.share_group

        self.share_groups_list = (
            manila_fakes.FakeShareGroup.create_share_groups(count=2))
        self.groups_mock.list.return_value = self.share_groups_list

        self.values = (oscutils.get_dict_properties(s._info, self.columns)
                       for s in self.share_groups_list)

        self.cmd = osc_share_groups.ListShareGroup(self.app, None)
    def take_action(self, parsed_args):
        # Hide tenant_id for now, the value incorrect in the
        # plugin implementation
        invisible_columns = ('tenant_id', )

        client = self.app.client_manager.nuageclient
        # At this time client.find_resource is implemented using list instead
        # of show, that's why we have to do two calls. Once this is fixed
        # upstream we can reduce the number of calls
        netpartition_id = client.find_net_partition(
            name_or_id=parsed_args.nuage_netpartition)['id']
        item = client.show_net_partition(netpartition_id)['net_partition']

        column_getter = sdk_utils.get_osc_show_columns_for_sdk_resource
        osc_column_map = {k: v for v, k, _ in _attr_map}
        columns, display_columns = column_getter(item, osc_column_map,
                                                 invisible_columns)

        return display_columns, utils.get_dict_properties(item, columns)
    def take_action_compute(self, client, parsed_args):
        search = {'all_tenants': parsed_args.all_projects}
        data = client.api.security_group_list(
            # TODO(dtroyer): add limit, marker
            search_opts=search, )

        columns = (
            "ID",
            "Name",
            "Description",
        )
        column_headers = columns
        if parsed_args.all_projects:
            columns = columns + ('Tenant ID', )
            column_headers = column_headers + ('Project', )
        return (column_headers, (utils.get_dict_properties(
            s,
            columns,
        ) for s in data))
    def take_action_network(self, client, parsed_args):
        column_headers = self._get_column_headers(parsed_args)
        columns = (
            'id',
            'protocol',
            'ether_type',
            'remote_ip_prefix',
            'port_range',
        )
        if parsed_args.long:
            columns = columns + ('direction',)
        columns = columns + ('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',)

        if parsed_args.ingress:
            query['direction'] = 'ingress'
        if parsed_args.egress:
            query['direction'] = 'egress'
        if parsed_args.protocol is not None:
            query['protocol'] = parsed_args.protocol

        rules = [
            self._format_network_security_group_rule(r)
            for r in client.security_group_rules(**query)
        ]

        return (column_headers,
                (utils.get_dict_properties(
                    s, columns,
                ) for s in rules))
    def take_action(self, parsed_args):
        rows = const.FLAVORPROFILE_ROWS
        data = None
        if uuidutils.is_uuid_like(parsed_args.flavorprofile):
            try:
                data = (
                    self.app.client_manager.load_balancer.flavorprofile_show(
                        flavorprofile_id=parsed_args.flavorprofile))
            except exceptions.NotFound:
                pass
        if data is None:
            attrs = v2_utils.get_flavorprofile_attrs(self.app.client_manager,
                                                     parsed_args)
            flavorprofile_id = attrs.pop('flavorprofile_id')

            data = self.app.client_manager.load_balancer.flavorprofile_show(
                flavorprofile_id=flavorprofile_id)

        return (rows, (utils.get_dict_properties(data, rows, formatters={})))
Ejemplo n.º 36
0
    def take_action(self, parsed_args):
        rows = const.LOAD_BALANCER_ROWS
        attrs = v2_utils.get_loadbalancer_attrs(self.app.client_manager,
                                                parsed_args)
        self._check_attrs(attrs)
        body = {'loadbalancer': attrs}

        data = self.app.client_manager.load_balancer.load_balancer_create(
            json=body)

        formatters = {
            'listeners': v2_utils.format_list,
            'pools': v2_utils.format_list,
            'l7policies': v2_utils.format_list
        }

        return (rows,
                (utils.get_dict_properties(
                    data['loadbalancer'], rows, formatters=formatters)))
    def take_action(self, parsed_args):
        client = self.app.client_manager.nuageclient
        project_id = self._find_project_id(parsed_args.project)
        try:
            obj = client.show_project_netpartition_mapping(
                project_id)[RESOURCE_NAME]
        except neutron_exc.NotFound:
            raise neutron_exc.NotFound('No Project netpartition '
                                       'mapping was found for Project '
                                       '{}.'.format(parsed_args.project))
        try:
            obj['net_partition_name'] = client.show_net_partition(
                obj['net_partition_id'])['net_partition']['name']
        except neutron_exc.NotFound:
            pass

        columns, display_columns = column_util.get_columns(obj, _attr_map)
        data = utils.get_dict_properties(obj, columns)
        return display_columns, data
Ejemplo n.º 38
0
 def take_action(self, parsed_args):
     search_opts = {}
     client = self.app.client_manager.neutronclient
     if parsed_args.bgp_speaker is not None:
         search_opts = {}
         speaker_id = client.find_resource(constants.BGP_SPEAKER,
                                           parsed_args.bgp_speaker)['id']
         search_opts['bgp_speaker'] = speaker_id
         data = client.list_dragents_hosting_bgp_speaker(**search_opts)
     else:
         attrs = {'agent_type': 'BGP dynamic routing agent'}
         data = client.list_agents(**attrs)
     headers = ('ID', 'Host', 'State', 'Alive')
     columns = ('id', 'host', 'admin_state_up', 'alive')
     return (headers, (utils.get_dict_properties(
         s,
         columns,
         formatters=_formatters,
     ) for s in data['agents']))
Ejemplo n.º 39
0
def _show_action(senlin_client, action_id):
    try:
        action = senlin_client.get_action(action_id)
    except sdk_exc.ResourceNotFound:
        raise exc.CommandError(_('Action not found: %s') % action_id)

    formatters = {
        'inputs': senlin_utils.json_formatter,
        'outputs': senlin_utils.json_formatter,
        'metadata': senlin_utils.json_formatter,
        'data': senlin_utils.json_formatter,
        'depends_on': senlin_utils.list_formatter,
        'depended_by': senlin_utils.list_formatter,
    }
    data = action.to_dict()
    columns = sorted(data.keys())
    return columns, utils.get_dict_properties(data,
                                              columns,
                                              formatters=formatters)
Ejemplo n.º 40
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        client = self.app.client_manager.orchestration

        try:
            outputs = client.stacks.output_list(parsed_args.stack)['outputs']
        except heat_exc.HTTPNotFound:
            try:
                outputs = client.stacks.get(
                    parsed_args.stack).to_dict()['outputs']
            except heat_exc.HTTPNotFound:
                msg = _('Stack not found: %s') % parsed_args.stack
                raise exc.CommandError(msg)

        columns = ['output_key', 'description']

        return (columns, (utils.get_dict_properties(s, columns)
                          for s in outputs))
Ejemplo n.º 41
0
    def take_action(self, parsed_args):

        results = []
        for container in parsed_args.containers:
            if len(container) > 256:
                LOG.warning(
                    _('Container name is %s characters long, the default limit'
                      ' is 256'), len(container))
            data = self.app.client_manager.object_store.container_create(
                container=container,
            )
            results.append(data)

        columns = ("account", "container", "x-trans-id")
        return (columns,
                (utils.get_dict_properties(
                    s, columns,
                    formatters={},
                ) for s in results))
Ejemplo n.º 42
0
    def take_action(self, parsed_args):
        rows = const.LISTENER_ROWS
        attrs = v2_utils.get_listener_attrs(self.app.client_manager,
                                            parsed_args)

        listener_id = attrs.pop('listener_id')

        data = self.app.client_manager.load_balancer.listener_show(
            listener_id=listener_id, )
        formatters = {
            'loadbalancers': v2_utils.format_list,
            'pools': v2_utils.format_list,
            'l7policies': v2_utils.format_list,
            'insert_headers': v2_utils.format_hash
        }

        return rows, utils.get_dict_properties(data,
                                               rows,
                                               formatters=formatters)
Ejemplo n.º 43
0
    def setUp(self):
        super(TestShareAccessList, self).setUp()

        self.share = manila_fakes.FakeShare.create_one_share()
        self.access_rule_1 = (
            manila_fakes.FakeShareAccessRule.create_one_access_rule(
                attrs={"share_id": self.share.id}))
        self.access_rule_2 = (
            manila_fakes.FakeShareAccessRule.create_one_access_rule(
                attrs={"share_id": self.share.id, "access_to": "admin"}))
        self.access_rules = [self.access_rule_1, self.access_rule_2]

        self.shares_mock.get.return_value = self.share
        self.access_rules_mock.access_list.return_value = self.access_rules
        self.values_list = (oscutils.get_dict_properties(
            a._info, self.access_rules_columns) for a in self.access_rules)

        # Get the command object to test
        self.cmd = osc_share_access_rules.ListShareAccess(self.app, None)
Ejemplo n.º 44
0
    def take_action_compute(self, client, parsed_args):
        columns = (
            'id',
            'label',
            'cidr',
        )
        column_headers = (
            'ID',
            'Name',
            'Subnet',
        )

        data = client.api.network_list()

        return (column_headers, (utils.get_dict_properties(
            s,
            columns,
            formatters=_formatters,
        ) for s in data))
Ejemplo n.º 45
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     params = {}
     if parsed_args.project is not None:
         project_id = nc_osc_utils.find_project(
             self.app.client_manager.identity,
             parsed_args.project,
             parsed_args.project_domain,
         ).id
         params['tenant_id'] = project_id
     if parsed_args.property:
         params.update(parsed_args.property)
     objs = client.list_bgpvpns(**params)[constants.BGPVPNS]
     headers, columns = nc_osc_utils.get_column_definitions(
         _attr_map, long_listing=parsed_args.long)
     return (headers, (osc_utils.get_dict_properties(s,
                                                     columns,
                                                     formatters=_formatters)
                       for s in objs))
Ejemplo n.º 46
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        baremetal_client = self.app.client_manager.baremetal

        columns = res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.fields
        labels = res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.labels

        methods = baremetal_client.driver.get_vendor_passthru_methods(
            parsed_args.driver)

        params = []
        for method, response in methods.items():
            response['name'] = method
            http_methods = ', '.join(response['http_methods'])
            response['http_methods'] = http_methods
            params.append(response)

        return (labels, (oscutils.get_dict_properties(s, columns)
                         for s in params))
Ejemplo n.º 47
0
    def take_action(self, parsed_args):
        columns = const.AMPHORA_COLUMNS
        attrs = v2_utils.get_amphora_attrs(self.app.client_manager,
                                           parsed_args)

        data = self.app.client_manager.load_balancer.amphora_list(**attrs)

        formatters = {
            'amphorae': v2_utils.format_list,
        }

        return (
            columns,
            (utils.get_dict_properties(
                amp,
                columns,
                formatters=formatters,
            ) for amp in data['amphorae']),
        )
Ejemplo n.º 48
0
    def take_action(self, parsed_args):
        http = self.app.client_manager.placement

        data = {'name': parsed_args.name}

        if 'uuid' in parsed_args and parsed_args.uuid:
            data['uuid'] = parsed_args.uuid
        if ('parent_provider' in parsed_args and parsed_args.parent_provider):
            self.check_version(version.ge('1.14'))
            data['parent_provider_uuid'] = parsed_args.parent_provider

        resp = http.request('POST', BASE_URL, json=data)
        resource = http.request('GET', resp.headers['Location']).json()

        fields = ('uuid', 'name', 'generation')
        if self.compare_version(version.ge('1.14')):
            fields += ('root_provider_uuid', 'parent_provider_uuid')

        return fields, utils.get_dict_properties(resource, fields)
Ejemplo n.º 49
0
    def take_action(self, parsed_args):

        attrs = {
            'parameters': {},
        }

        # mandatory
        attrs['vault_id'] = parsed_args.vault_id

        # optional

        if parsed_args.auto_trigger is not None:
            attrs['parameters'].update(auto_trigger=parsed_args.auto_trigger)
        if parsed_args.description:
            attrs['parameters'].update(
                description=parsed_args.description)
        if parsed_args.no_incremental is not None:
            attrs['parameters'].update(incremental=parsed_args.no_incremental)
        if parsed_args.backup_name:
            attrs['parameters'].update(
                name=parsed_args.backup_name)
        if parsed_args.resources:
            attrs['parameters'].update(
                resources=parsed_args.resources)
        if parsed_args.resource_details:
            attrs['parameters'].update(resource_details=_normalize_resources(
                parsed_args.resource_details))

        client = self.app.client_manager.cbr
        obj = client.create_checkpoint(**attrs)

        data = utils.get_dict_properties(
            _flatten_checkpoint(obj), self.columns)

        if obj.vault.resources:
            data, self.columns = _add_resources_to_obj(obj, data, self.columns)

        if obj.vault.skipped_resources:
            data, self.columns = _add_skipped_resources_to_obj(obj, data,
                                                               self.columns)

        return (self.columns, data)
Ejemplo n.º 50
0
    def take_action(self, parsed_args):
        rows = const.POOL_ROWS

        attrs = v2_utils.get_pool_attrs(self.app.client_manager, parsed_args)
        pool_id = attrs.pop('pool_id')

        data = self.app.client_manager.load_balancer.pool_show(
            pool_id=pool_id, )
        formatters = {
            'loadbalancers': v2_utils.format_list,
            'members': v2_utils.format_list,
            'listeners': v2_utils.format_list,
            'session_persistence': v2_utils.format_hash
        }

        return (rows,
                (utils.get_dict_properties(data,
                                           rows,
                                           formatters=formatters,
                                           mixed_case_fields=['enable-tls'])))
Ejemplo n.º 51
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     attrs = _get_common_attrs(self.app.client_manager, parsed_args)
     if parsed_args.name:
         attrs['name'] = str(parsed_args.name)
     attrs['type'] = parsed_args.type
     if parsed_args.type == 'subnet':
         _subnet_ids = [client.find_resource(
             'subnet',
             endpoint,
             cmd_resource='subnet')['id']
             for endpoint in parsed_args.endpoints]
         attrs['endpoints'] = _subnet_ids
     else:
         attrs['endpoints'] = parsed_args.endpoints
     obj = client.create_endpoint_group(
         {'endpoint_group': attrs})['endpoint_group']
     columns, display_columns = column_util.get_columns(obj, _attr_map)
     data = utils.get_dict_properties(obj, columns)
     return display_columns, data
Ejemplo n.º 52
0
def _show_node(senlin_client, node_id, show_details=False):
    """Show detailed info about the specified node."""

    try:
        node = senlin_client.get_node(node_id, details=show_details)
    except sdk_exc.ResourceNotFound:
        raise exc.CommandError(_('Node not found: %s') % node_id)

    formatters = {
        'metadata': senlin_utils.json_formatter,
        'data': senlin_utils.json_formatter,
        'dependents': senlin_utils.json_formatter,
    }
    data = node.to_dict()
    if show_details and data['details']:
        formatters['details'] = senlin_utils.nested_dict_formatter(
            list(data['details'].keys()), ['property', 'value'])
    columns = sorted(data.keys())
    return columns, utils.get_dict_properties(data, columns,
                                              formatters=formatters)
Ejemplo n.º 53
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        instance = osc_utils.find_resource(share_client.share_instances,
                                           parsed_args.instance)

        export_locations = share_client.share_instance_export_locations.list(
            instance, search_opts=None)

        columns = [
            'ID',
            'Path',
            'Is Admin Only',
            'Preferred',
        ]

        data = (osc_utils.get_dict_properties(export_location._info, columns)
                for export_location in export_locations)

        return (columns, data)
Ejemplo n.º 54
0
    def test_list_share_networks_detail(self):
        values = (oscutils.get_dict_properties(
            s._info, COLUMNS_DETAIL) for s in self.share_networks_list)

        arglist = [
            '--detail',
        ]

        verifylist = [
            ('detail', True),
        ]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)

        self.share_networks_mock.list.assert_called_once_with(
            search_opts=self.expected_search_opts)
        self.assertEqual(COLUMNS_DETAIL, columns)
        self.assertEqual(list(values), list(data))
Ejemplo n.º 55
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     list_method = getattr(client,
                           'list_bgpvpn_%s_assocs' % self._assoc_res_name)
     bgpvpn = client.find_resource(constants.BGPVPN, parsed_args.bgpvpn)
     params = {}
     if parsed_args.property:
         params.update(parsed_args.property)
     objs = list_method(bgpvpn['id'], retrieve_all=True,
                        **params)[self._resource_plural]
     transform = getattr(self, '_transform_resource', None)
     if callable(transform):
         [transform(obj) for obj in objs]
     headers, columns = column_util.get_column_definitions(
         self._attr_map, long_listing=parsed_args.long)
     return (headers,
             (osc_utils.get_dict_properties(s,
                                            columns,
                                            formatters=self._formatters)
              for s in objs))
Ejemplo n.º 56
0
    def take_action(self, parsed_args):
        volume_client = self.app.client_manager.volume
        qos_specs_list = volume_client.qos_specs.list()

        for qos in qos_specs_list:
            qos_associations = volume_client.qos_specs.get_associations(qos)
            if qos_associations:
                associations = [association.name
                                for association in qos_associations]
                qos._info.update({'associations': associations})

        columns = ('ID', 'Name', 'Consumer', 'Associations', 'Specs')
        return (columns,
                (utils.get_dict_properties(
                    s._info, columns,
                    formatters={
                        'Specs': utils.format_dict,
                        'Associations': utils.format_list
                    },
                ) for s in qos_specs_list))
Ejemplo n.º 57
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)
        heat_client = self.app.client_manager.orchestration

        try:
            data = heat_client.stacks.snapshot(parsed_args.stack,
                                               parsed_args.name)
        except heat_exc.HTTPNotFound:
            raise exc.CommandError(_('Stack not found: %s')
                                   % parsed_args.stack)

        columns = [
            'ID',
            'name',
            'status',
            'status_reason',
            'data',
            'creation_time'
        ]
        return (columns, utils.get_dict_properties(data, columns))
Ejemplo n.º 58
0
 def take_action(self, parsed_args):
     client = self.app.client_manager.neutronclient
     attrs = _get_common_attrs(self.app.client_manager, parsed_args)
     if parsed_args.vpnservice:
         _vpnservice_id = client.find_resource(
             'vpnservice',
             parsed_args.vpnservice,
             cmd_resource='vpnservice')['id']
         attrs['vpnservice_id'] = _vpnservice_id
     if parsed_args.ikepolicy:
         _ikepolicy_id = client.find_resource(
             'ikepolicy', parsed_args.ikepolicy,
             cmd_resource='ikepolicy')['id']
         attrs['ikepolicy_id'] = _ikepolicy_id
     if parsed_args.ipsecpolicy:
         _ipsecpolicy_id = client.find_resource(
             'ipsecpolicy',
             parsed_args.ipsecpolicy,
             cmd_resource='ipsecpolicy')['id']
         attrs['ipsecpolicy_id'] = _ipsecpolicy_id
     if parsed_args.peer_id:
         attrs['peer_id'] = parsed_args.peer_id
     if parsed_args.peer_address:
         attrs['peer_address'] = parsed_args.peer_address
     if parsed_args.psk:
         attrs['psk'] = parsed_args.psk
     if parsed_args.name:
         attrs['name'] = parsed_args.name
     if (bool(parsed_args.local_endpoint_group) != bool(
             parsed_args.peer_endpoint_group)):
         message = _("You must specify both local and peer endpoint "
                     "groups")
         raise exceptions.CommandError(message)
     if not parsed_args.peer_cidrs and not parsed_args.local_endpoint_group:
         message = _("You must specify endpoint groups or peer CIDR(s)")
         raise exceptions.CommandError(message)
     obj = client.create_ipsec_site_connection(
         {'ipsec_site_connection': attrs})['ipsec_site_connection']
     columns, display_columns = column_util.get_columns(obj, _attr_map)
     data = utils.get_dict_properties(obj, columns, formatters=_formatters)
     return display_columns, data
Ejemplo n.º 59
0
    def take_action(self, parsed_args):
        client = self.app.client_manager.iam

        table_columns = (
            'Access Key',
            'Description',
            'User ID',
            'Status',
            'Created At',
        )

        attrs = {}

        if parsed_args.user_id:
            attrs['user_id'] = parsed_args.user_id

        data = client.credentials(**attrs)

        table = (table_columns, (utils.get_dict_properties(s, self.columns)
                                 for s in data))
        return table
Ejemplo n.º 60
0
    def test_share_snapshot_instance_list_snapshot_id(self):
        self.share_snapshot = (
            manila_fakes.FakeShareSnapshot.create_one_snapshot())

        self.share_snapshots_mock.get.return_value = self.share_snapshot
        self.share_snapshot_instances_mock.list.return_value = ([
            self.share_snapshot_instances[0]
        ])

        values = (osc_lib_utils.get_dict_properties(s._info, COLUMNS)
                  for s in [self.share_snapshot_instances[0]])

        arglist = ['--snapshot', self.share_snapshot.id]
        verifylist = [('snapshot', self.share_snapshot.id)]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)

        self.assertEqual(COLUMNS, columns)
        self.assertEqual(list(values), list(data))