Ejemplo n.º 1
0
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        resource_flavor = _find_flavor(compute_client, parsed_args.flavor)

        access_projects = None
        # get access projects list of this flavor
        if not resource_flavor.is_public:
            try:
                flavor_access = compute_client.flavor_access.list(
                    flavor=resource_flavor.id)
                projects = [
                    utils.get_field(access, 'tenant_id')
                    for access in flavor_access
                ]
                # TODO(Huanxuan Ao): This format case can be removed after
                # patch https://review.openstack.org/#/c/330223/ merged.
                access_projects = utils.format_list(projects)
            except Exception as e:
                msg = _("Failed to get access projects list "
                        "for flavor '%(flavor)s': %(e)s")
                LOG.error(msg, {'flavor': parsed_args.flavor, 'e': e})

        flavor = resource_flavor._info.copy()
        flavor.update({'access_project_ids': access_projects})
        flavor.pop("links", None)

        flavor['properties'] = utils.format_dict(resource_flavor.get_keys())

        return zip(*sorted(six.iteritems(flavor)))
Ejemplo n.º 2
0
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        resource_flavor = _find_flavor(compute_client, parsed_args.flavor)

        access_projects = None
        # get access projects list of this flavor
        if not resource_flavor.is_public:
            try:
                flavor_access = compute_client.flavor_access.list(
                    flavor=resource_flavor.id)
                projects = [utils.get_field(access, 'tenant_id')
                            for access in flavor_access]
                # TODO(Huanxuan Ao): This format case can be removed after
                # patch https://review.openstack.org/#/c/330223/ merged.
                access_projects = utils.format_list(projects)
            except Exception as e:
                msg = _("Failed to get access projects list "
                        "for flavor '%(flavor)s': %(e)s")
                LOG.error(msg % {'flavor': parsed_args.flavor, 'e': e})

        flavor = resource_flavor._info.copy()
        flavor.update({
            'access_project_ids': access_projects
        })
        flavor.pop("links", None)

        flavor['properties'] = utils.format_dict(resource_flavor.get_keys())

        return zip(*sorted(six.iteritems(flavor)))
Ejemplo n.º 3
0
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        resource_flavor = _find_flavor(compute_client, parsed_args.flavor)

        access_projects = None
        # get access projects list of this flavor
        if not resource_flavor.is_public:
            try:
                flavor_access = compute_client.flavor_access.list(
                    flavor=resource_flavor.id)
                access_projects = [
                    utils.get_field(access, 'tenant_id')
                    for access in flavor_access
                ]
            except Exception as e:
                msg = _("Failed to get access projects list "
                        "for flavor '%(flavor)s': %(e)s")
                LOG.error(msg, {'flavor': parsed_args.flavor, 'e': e})

        flavor = resource_flavor._info.copy()
        flavor.update({'access_project_ids': access_projects})

        flavor['properties'] = resource_flavor.get_keys()

        display_columns, columns = _get_flavor_columns(flavor)
        data = utils.get_dict_properties(flavor,
                                         columns,
                                         formatters=_formatters,
                                         mixed_case_fields=[
                                             'OS-FLV-DISABLED:disabled',
                                             'OS-FLV-EXT-DATA:ephemeral'
                                         ])

        return (display_columns, data)
Ejemplo n.º 4
0
 def take_action(self, parsed_args):
     volume_client = self.app.client_manager.volume
     volume_type = utils.find_resource(volume_client.volume_types,
                                       parsed_args.volume_type)
     properties = utils.format_dict(volume_type._info.pop(
         'extra_specs', {}))
     volume_type._info.update({'properties': properties})
     access_project_ids = None
     if not volume_type.is_public:
         try:
             volume_type_access = volume_client.volume_type_access.list(
                 volume_type.id)
             project_ids = [
                 utils.get_field(item, 'project_id')
                 for item in volume_type_access
             ]
             # TODO(Rui Chen): This format list case can be removed after
             # patch https://review.openstack.org/#/c/330223/ merged.
             access_project_ids = utils.format_list(project_ids)
         except Exception as e:
             msg = _('Failed to get access project list for volume type '
                     '%(type)s: %(e)s')
             LOG.error(msg % {'type': volume_type.id, 'e': e})
     volume_type._info.update({'access_project_ids': access_project_ids})
     return zip(*sorted(six.iteritems(volume_type._info)))
Ejemplo n.º 5
0
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.sdk_connection.compute
        flavor = compute_client.find_flavor(parsed_args.flavor,
                                            get_extra_specs=True,
                                            ignore_missing=False)

        access_projects = None
        # get access projects list of this flavor
        if not flavor.is_public:
            try:
                flavor_access = compute_client.get_flavor_access(
                    flavor=flavor.id)
                access_projects = [
                    utils.get_field(access, 'tenant_id')
                    for access in flavor_access
                ]
            except Exception as e:
                msg = _("Failed to get access projects list "
                        "for flavor '%(flavor)s': %(e)s")
                LOG.error(msg, {'flavor': parsed_args.flavor, 'e': e})

        # Since we need to inject "access_project_id" into resource - convert
        # it to dict and treat it respectively
        flavor = flavor.to_dict()
        flavor['access_project_ids'] = access_projects

        display_columns, columns = _get_flavor_columns(flavor)
        data = utils.get_dict_properties(flavor,
                                         columns,
                                         formatters=_formatters)

        return (display_columns, data)
Ejemplo n.º 6
0
 def take_action(self, parsed_args):
     volume_client = self.app.client_manager.volume
     volume_type = utils.find_resource(volume_client.volume_types,
                                       parsed_args.volume_type)
     properties = format_columns.DictColumn(
         volume_type._info.pop('extra_specs', {}))
     volume_type._info.update({'properties': properties})
     access_project_ids = None
     if not volume_type.is_public:
         try:
             volume_type_access = volume_client.volume_type_access.list(
                 volume_type.id)
             project_ids = [
                 utils.get_field(item, 'project_id')
                 for item in volume_type_access
             ]
             # TODO(Rui Chen): This format list case can be removed after
             # patch https://review.opendev.org/#/c/330223/ merged.
             access_project_ids = format_columns.ListColumn(project_ids)
         except Exception as e:
             msg = _('Failed to get access project list for volume type '
                     '%(type)s: %(e)s')
             LOG.error(msg % {'type': volume_type.id, 'e': e})
     volume_type._info.update({'access_project_ids': access_project_ids})
     if parsed_args.encryption_type:
         # show encryption type information for this volume type
         try:
             encryption = volume_client.volume_encryption_types.get(
                 volume_type.id)
             encryption._info.pop("volume_type_id", None)
             volume_type._info.update({
                 'encryption':
                 format_columns.DictColumn(encryption._info)
             })
         except Exception as e:
             LOG.error(
                 _("Failed to display the encryption information "
                   "of this volume type: %s"), e)
     volume_type._info.pop("os-volume-type-access:is_public", None)
     return zip(*sorted(six.iteritems(volume_type._info)))
 def take_action(self, parsed_args):
     volume_client = self.app.client_manager.volume
     volume_type = utils.find_resource(
         volume_client.volume_types, parsed_args.volume_type)
     properties = utils.format_dict(
         volume_type._info.pop('extra_specs', {}))
     volume_type._info.update({'properties': properties})
     access_project_ids = None
     if not volume_type.is_public:
         try:
             volume_type_access = volume_client.volume_type_access.list(
                 volume_type.id)
             project_ids = [utils.get_field(item, 'project_id')
                            for item in volume_type_access]
             # TODO(Rui Chen): This format list case can be removed after
             # patch https://review.openstack.org/#/c/330223/ merged.
             access_project_ids = utils.format_list(project_ids)
         except Exception as e:
             msg = _('Failed to get access project list for volume type '
                     '%(type)s: %(e)s')
             LOG.error(msg % {'type': volume_type.id, 'e': e})
     volume_type._info.update({'access_project_ids': access_project_ids})
     return zip(*sorted(six.iteritems(volume_type._info)))
Ejemplo n.º 8
0
    def resource_providers(self):
        URL = '/resource_providers'
        data = self.get(URL).json()
        resources = utils.get_field(data, 'resource_providers')

        return resources