コード例 #1
0
    def take_action(self, parsed_args):
        # TODO(s0ru): the table shows 'Field', 'Value'
        share_client = self.app.client_manager.share

        share_type = None
        if parsed_args.share_type:
            share_type = apiutils.find_resource(share_client.share_types,
                                                parsed_args.share_type).id

        share_network = None
        if parsed_args.share_network:
            share_network = apiutils.find_resource(
                share_client.share_networks, parsed_args.share_network).id

        share_group = None
        if parsed_args.share_group:
            share_group = apiutils.find_resource(share_client.share_groups,
                                                 parsed_args.share_group).id

        size = parsed_args.size

        snapshot_id = None
        if parsed_args.snapshot_id:
            snapshot = apiutils.find_resource(share_client.share_snapshots,
                                              parsed_args.snapshot_id)
            snapshot_id = snapshot.id
            size = max(size or 0, snapshot.size)

        body = {
            'share_proto': parsed_args.share_proto,
            'size': size,
            'snapshot_id': snapshot_id,
            'name': parsed_args.name,
            'description': parsed_args.description,
            'metadata': parsed_args.property,
            'share_network': share_network,
            'share_type': share_type,
            'is_public': parsed_args.public,
            'availability_zone': parsed_args.availability_zone,
            'share_group_id': share_group
        }

        share = share_client.shares.create(**body)

        if parsed_args.wait:
            if not oscutils.wait_for_status(status_f=share_client.shares.get,
                                            res_id=share.id,
                                            success_status=['available']):
                LOG.error(_("ERROR: Share is in error state."))

            share = apiutils.find_resource(share_client.shares, share.id)

        printable_share = share._info
        printable_share.pop('links', None)
        printable_share.pop('shares_type', None)

        return self.dict2columns(printable_share)
コード例 #2
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        snapshot = apiutils.find_resource(share_client.share_snapshots,
                                          parsed_args.snapshot)
        share = apiutils.find_resource(share_client.shares, snapshot.share_id)
        try:
            share.revert_to_snapshot(snapshot)
        except Exception as e:
            raise exceptions.CommandError(
                _("Failed to revert share to snapshot: %s" % (e)))
コード例 #3
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        kwargs = {
            'service_host': parsed_args.service_host,
            'protocol': parsed_args.protocol,
            'export_path': parsed_args.export_path,
            'name': parsed_args.name,
            'description': parsed_args.description
        }

        share_type = None
        if parsed_args.share_type:
            share_type = apiutils.find_resource(share_client.share_types,
                                                parsed_args.share_type).id
            kwargs['share_type'] = share_type

        driver_options = None
        if parsed_args.driver_options:
            driver_options = utils.extract_properties(
                parsed_args.driver_options)
            kwargs['driver_options'] = driver_options

        if parsed_args.public:
            if share_client.api_version >= api_versions.APIVersion("2.8"):
                kwargs['public'] = True
            else:
                raise exceptions.CommandError(
                    'Setting share visibility while adopting a share is '
                    'available only for API microversion >= 2.8')

        if parsed_args.share_server_id:
            if share_client.api_version >= api_versions.APIVersion("2.49"):
                kwargs['share_server_id'] = parsed_args.share_server_id
            else:
                raise exceptions.CommandError(
                    'Selecting a share server ID is available only for '
                    'API microversion >= 2.49')

        share = share_client.shares.manage(**kwargs)

        if parsed_args.wait:
            if not oscutils.wait_for_status(
                    status_f=share_client.shares.get,
                    res_id=share.id,
                    success_status=['available'],
                    error_status=['manage_error', 'error']):
                LOG.error(_("ERROR: Share is in error state."))

            share = apiutils.find_resource(share_client.shares, share.id)
        share._info.pop('links', None)

        return self.dict2columns(share._info)
コード例 #4
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share = apiutils.find_resource(share_client.shares, parsed_args.share)
        properties = {}
        if parsed_args.properties:
            if share_client.api_version >= api_versions.APIVersion("2.45"):
                properties = utils.extract_properties(parsed_args.properties)
            else:
                raise exceptions.CommandError(
                    "Adding properties to access rules is supported only "
                    "with API microversion 2.45 and beyond")
        try:
            share_access_rule = share.allow(
                access_type=parsed_args.access_type,
                access=parsed_args.access_to,
                access_level=parsed_args.access_level,
                metadata=properties)
            share_access_rule.update({
                'properties':
                utils.format_properties(share_access_rule.pop('metadata', {}))
            })
            return (ACCESS_RULE_ATTRIBUTES,
                    oscutils.get_dict_properties(share_access_rule,
                                                 ACCESS_RULE_ATTRIBUTES))
        except Exception as e:
            raise exceptions.CommandError("Failed to create access to share "
                                          "'%s': %s" % (share, e))
コード例 #5
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        share = apiutils.find_resource(share_client.shares, parsed_args.share)
        share_size = share._info['size']
        new_size = parsed_args.new_size

        if share_size > new_size:
            try:
                share_client.shares.shrink(share, new_size)
            except Exception as e:
                raise exceptions.CommandError(_("Share resize failed: %s" % e))
        elif share_size < new_size:
            try:
                share_client.shares.extend(share, new_size)
            except Exception as e:
                raise exceptions.CommandError(_("Share resize failed: %s" % e))
        else:
            raise exceptions.CommandError(
                _("Share size is already at %s GiBs" % new_size))
        if parsed_args.wait:
            if not oscutils.wait_for_status(status_f=share_client.shares.get,
                                            res_id=share.id,
                                            success_status=['available']):
                raise exceptions.CommandError(
                    _("Share not available after resize attempt."))
コード例 #6
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_obj = apiutils.find_resource(share_client.shares,
                                           parsed_args.share)

        export_locations = share_client.share_export_locations.list(share_obj)
        export_locations = (cliutils.transform_export_locations_to_string_view(
            export_locations))

        data = share_obj._info
        data['export_locations'] = export_locations
        # Special mapping for columns to make the output easier to read:
        # 'metadata' --> 'properties'
        data.update(
            {
                'properties': format_columns.DictColumn(
                    data.pop('metadata', {})),
            }, )

        # Remove key links from being displayed
        data.pop("links", None)
        data.pop("shares_type", None)

        return self.dict2columns(data)
コード例 #7
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for share in parsed_args.shares:
            try:
                share_obj = apiutils.find_resource(share_client.shares, share)
                share_group_id = (share_group_id
                                  if parsed_args.share_group else None)
                if parsed_args.force:
                    share_client.shares.force_delete(share_obj)
                else:
                    share_client.shares.delete(share_obj, share_group_id)
                if parsed_args.wait:
                    if not oscutils.wait_for_delete(
                            manager=share_client.shares, res_id=share_obj.id):
                        result += 1

            except Exception as exc:
                result += 1
                LOG.error(
                    _("Failed to delete share with "
                      "name or ID '%(share)s': %(e)s"), {
                          'share': share,
                          'e': exc
                      })

        if result > 0:
            total = len(parsed_args.shares)
            msg = (_("%(result)s of %(total)s shares failed "
                     "to delete.") % {
                         'result': result,
                         'total': total
                     })
            raise exceptions.CommandError(msg)
コード例 #8
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for share_group_type in parsed_args.share_group_types:
            try:
                share_group_type_obj = apiutils.find_resource(
                    share_client.share_group_types, share_group_type)

                share_client.share_group_types.delete(share_group_type_obj)
            except Exception as e:
                result += 1
                LOG.error(
                    _("Failed to delete share group type with "
                      "name or ID '%(share_group_type)s': %(e)s"), {
                          'share_group_type': share_group_type,
                          'e': e
                      })

        if result > 0:
            total = len(parsed_args.share_group_types)
            msg = (_("%(result)s of %(total)s share group types failed "
                     "to delete.") % {
                         'result': result,
                         'total': total
                     })
            raise exceptions.CommandError(msg)
コード例 #9
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        share_obj = apiutils.find_resource(share_client.shares,
                                           parsed_args.share)
        result = 0
        kwargs = {}
        if parsed_args.name:
            kwargs['display_name'] = None
        if parsed_args.description:
            kwargs['display_description'] = None
        if kwargs:
            try:
                share_client.shares.update(share_obj.id, **kwargs)
            except Exception as e:
                LOG.error(_("Failed to unset share display name "
                            "or display description"), e)
                result += 1

        if parsed_args.property:
            for key in parsed_args.property:
                try:
                    share_client.shares.delete_metadata(
                        share_obj.id, [key])
                except Exception as e:
                    LOG.error(_("Failed to unset share property "
                                "'%(key)s': %(e)s"),
                              {'key': key, 'e': e})
                    result += 1

        if result > 0:
            raise exceptions.CommandError(_(
                "One or more of the "
                "unset operations failed"))
コード例 #10
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        share_obj = apiutils.find_resource(share_client.shares,
                                           parsed_args.share)
        result = 0

        if parsed_args.property:
            try:
                share_client.shares.set_metadata(
                    share_obj.id, parsed_args.property)
            except Exception as e:
                LOG.error(_("Failed to set share properties "
                            "'%(properties)s': %(exception)s"),
                          {'properties': parsed_args.property,
                           'exception': e})
                result += 1

        kwargs = {}
        if parsed_args.name is not None:
            kwargs['display_name'] = parsed_args.name
        if parsed_args.description is not None:
            kwargs['display_description'] = parsed_args.description
        if parsed_args.public is not None:
            kwargs['is_public'] = parsed_args.public
        if kwargs:
            try:
                share_client.shares.update(share_obj.id, **kwargs)
            except Exception as e:
                LOG.error(_("Failed to update share display name, visibility "
                          "or display description: %s"), e)
                result += 1

        if result > 0:
            raise exceptions.CommandError(_("One or more of the "
                                          "set operations failed"))
コード例 #11
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        number_of_deletion_failures = 0

        for instance in parsed_args.instance:
            try:
                share_instance = apiutils.find_resource(
                    share_client.share_instances, instance)

                share_client.share_instances.force_delete(share_instance)

                if parsed_args.wait:
                    if not osc_utils.wait_for_delete(
                            manager=share_client.share_instances,
                            res_id=share_instance.id):
                        number_of_deletion_failures += 1

            except Exception as e:
                number_of_deletion_failures += 1
                LOG.error(
                    _("Failed to delete a share instance with "
                      "ID '%(instance)s': %(e)s"), {
                          'instance': instance,
                          'e': e
                      })
        if number_of_deletion_failures > 0:
            msg = (
                _("%(number_of_deletion_failures)s of "
                  "%(total_of_instances)s instances failed "
                  "to delete.") %
                {
                    'number_of_deletion_failures': number_of_deletion_failures,
                    'total_of_instances': len(parsed_args.instance)
                })
            raise exceptions.CommandError(msg)
コード例 #12
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        try:
            share_group_type_obj = apiutils.find_resource(
                share_client.share_group_types, parsed_args.share_group_type)
        except Exception as e:
            msg = LOG.error(
                _("Failed to find the share group type with "
                  "name or ID '%(share_group_type)s': %(e)s"), {
                      'share_group_type': parsed_args.share_group_type,
                      'e': e
                  })
            raise exceptions.CommandError(msg)
        kwargs = {}

        if kwargs:
            share_group_type_obj.set_keys(**kwargs)

        if parsed_args.group_specs:
            group_specs = utils.extract_group_specs(
                extra_specs={}, specs_to_add=parsed_args.group_specs)
            try:
                share_group_type_obj.set_keys(group_specs)
            except Exception as e:
                raise exceptions.CommandError(
                    "Failed to set share group type key: %s" % e)
コード例 #13
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_obj = apiutils.find_resource(share_client.shares,
                                           parsed_args.share)

        export_locations = share_client.share_export_locations.list(share_obj)
        export_locations = cliutils.convert_dict_list_to_string(
            export_locations,
            ignored_keys=[
                'replica_state', 'availability_zone', 'share_replica_id'
            ])

        data = share_obj._info
        data['export_locations'] = export_locations
        # Special mapping for columns to make the output easier to read:
        # 'metadata' --> 'properties'
        data.update(
            {
                'properties': format_columns.DictColumn(
                    data.pop('metadata', {})),
            }, )

        # Remove key links from being displayed
        data.pop("links", None)
        data.pop("shares_type", None)

        return self.dict2columns(data)
コード例 #14
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        identity_client = self.app.client_manager.identity
        result = 0

        share_group_type = apiutils.find_resource(
            share_client.share_group_types, parsed_args.share_group_type)

        for project in parsed_args.projects:
            try:
                project_obj = identity_common.find_project(
                    identity_client, project, parsed_args.project_domain)

                share_client.share_group_type_access.add_project_access(
                    share_group_type, project_obj.id)
            except Exception as e:
                result += 1
                LOG.error(_(
                    "Failed to allow access for project '%(project)s' "
                    "to share group type with name or ID "
                    "'%(share_group_type)s': %(e)s"),
                    {'project': project,
                     'share_group_type': share_group_type, 'e': e})

        if result > 0:
            total = len(parsed_args.projects)
            msg = (_("Failed to allow access to "
                     "%(result)s of %(total)s projects") % {'result': result,
                                                            'total': total})
            raise exceptions.CommandError(msg)
コード例 #15
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for share in parsed_args.share:
            try:
                share_obj = apiutils.find_resource(share_client.shares, share)
                share_client.shares.unmanage(share_obj)

                if parsed_args.wait:
                    # 'wait_for_delete' checks that the resource is no longer
                    # retrievable with the given 'res_id' so we can use it
                    # to check that the share has been abandoned
                    if not oscutils.wait_for_delete(
                            manager=share_client.shares, res_id=share_obj.id):
                        result += 1

            except Exception as e:
                result += 1
                LOG.error(
                    _("Failed to abandon share with "
                      "name or ID '%(share)s': %(e)s"), {
                          'share': share,
                          'e': e
                      })

        if result > 0:
            total = len(parsed_args.share)
            msg = (_("Failed to abandon %(result)s out of %(total)s shares.") %
                   {
                       'result': result,
                       'total': total
                   })
            raise exceptions.CommandError(msg)
コード例 #16
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        share = apiutils.find_resource(share_client.shares, parsed_args.share)

        export_location = share_client.share_export_locations.get(
            share=share, export_location=parsed_args.export_location)

        return self.dict2columns(export_location._info)
コード例 #17
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        message = apiutils.find_resource(share_client.messages,
                                         parsed_args.message)

        return (MESSAGE_ATTRIBUTES,
                oscutils.get_dict_properties(message._info,
                                             MESSAGE_ATTRIBUTES))
コード例 #18
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_type = apiutils.find_resource(share_client.share_types,
                                            parsed_args.share_type)

        formatted_type = format_share_type(share_type)

        return (ATTRIBUTES,
                oscutils.get_dict_properties(formatted_type._info, ATTRIBUTES))
コード例 #19
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share = apiutils.find_resource(share_client.shares, parsed_args.share)
        try:
            share.deny(parsed_args.id)
        except Exception as e:
            raise exceptions.CommandError(
                "Failed to delete share access rule for share "
                "'%s': %s" % (share, e))
コード例 #20
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        share = apiutils.find_resource(share_client.shares, parsed_args.share)

        export_locations = share_client.share_export_locations.list(
            share=share)

        list_of_keys = ['ID', 'Path', 'Preferred']

        return (list_of_keys, (oscutils.get_item_properties(s, list_of_keys)
                               for s in export_locations))
コード例 #21
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_type = apiutils.find_resource(share_client.share_types,
                                            parsed_args.share_type)

        if parsed_args.extra_specs:
            try:
                share_type.unset_keys(parsed_args.extra_specs)
            except Exception as e:
                raise exceptions.CommandError(
                    "Failed to remove share type extra spec: %s" % e)
コード例 #22
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_type = apiutils.find_resource(share_client.share_types,
                                            parsed_args.share_type)

        try:
            share_client.share_type_access.remove_project_access(
                share_type, parsed_args.project_id)

        except Exception as e:
            raise exceptions.CommandError(
                "Failed to remove access from share type : %s" % e)
コード例 #23
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share = apiutils.find_resource(share_client.shares, parsed_args.share)

        if share_client.api_version >= api_versions.APIVersion("2.45"):
            search_opts = {}
            if parsed_args.properties:
                search_opts = {
                    'metadata':
                    utils.extract_properties(parsed_args.properties)
                }
            access_list = share_client.share_access_rules.access_list(
                share, search_opts)
        elif parsed_args.properties:
            raise exceptions.CommandError(
                "Filtering access rules by properties is supported only "
                "with API microversion 2.45 and beyond.")
        else:
            access_list = share.access_list()

        list_of_keys = [
            'id', 'access_type', 'access_to', 'access_level', 'state'
        ]

        if share_client.api_version >= api_versions.APIVersion("2.21"):
            list_of_keys.append('access_key')

        if share_client.api_version >= api_versions.APIVersion("2.33"):
            list_of_keys.append('created_at')
            list_of_keys.append('updated_at')

        if parsed_args.columns:
            columns = parsed_args.columns.split(',')
            for column in columns:
                if column not in list_of_keys:
                    msg = ("No column named '%s'. Possible columns are: "
                           "'id', 'access_type', 'access_to', "
                           "'access_level', 'state', "
                           "'access_key'(API microversion 2.21 and beyond), "
                           "'created_at'(API microversion 2.33 and beyond), "
                           "'updated_at'(API microversion 2.33 and beyond)." %
                           column)
                    raise exceptions.CommandError(msg)
        else:
            columns = list_of_keys

        values = (oscutils.get_item_properties(a, columns)
                  for a in access_list)

        return (columns, values)
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        snapshot_instance = apiutils.find_resource(
            share_client.share_snapshot_instances,
            parsed_args.snapshot_instance)

        share_snapshot_instance_export_location = (
            share_client.share_snapshot_instance_export_locations.get(
                parsed_args.export_location,
                snapshot_instance=snapshot_instance))

        share_snapshot_instance_export_location._info.pop('links', None)

        return self.dict2columns(share_snapshot_instance_export_location._info)
コード例 #25
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_type = apiutils.find_resource(share_client.share_types,
                                            parsed_args.share_type)

        if share_type._info.get('share_type_access:is_public'):
            raise exceptions.CommandError(
                'Forbidden to get access list for public share type.')

        data = share_client.share_type_access.list(share_type)

        columns = ['Project ID']
        values = (oscutils.get_item_properties(s, columns) for s in data)

        return (columns, values)
コード例 #26
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_group_type = apiutils.find_resource(
            share_client.share_group_types, parsed_args.share_group_type)

        share_group_type_obj = share_client.share_group_types.get(
            share_group_type)

        formatter = parsed_args.formatter

        formatted_group_type = utils.format_share_group_type(
            share_group_type_obj, formatter)

        return (ATTRIBUTES,
                oscutils.get_dict_properties(formatted_group_type, ATTRIBUTES))
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        snapshot_instance = apiutils.find_resource(
            share_client.share_snapshot_instances, parsed_args.instance)

        share_snapshot_instance_export_locations = (
            share_client.share_snapshot_instance_export_locations.list(
                snapshot_instance=snapshot_instance))

        columns = ["ID", "Path", "Is Admin only"]

        return (
            columns,
            (utils.get_item_properties(s, columns) for s in
             share_snapshot_instance_export_locations))
コード例 #28
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        kwargs = {'name': parsed_args.name}

        share_types_list = []
        for share_type in parsed_args.share_types:
            try:
                share_type_obj = apiutils.find_resource(
                    share_client.share_types, share_type)

                share_types_list.append(share_type_obj.name)
            except Exception as e:
                msg = LOG.error(
                    _("Failed to find the share type with "
                      "name or ID '%(share_type)s': %(e)s"), {
                          'share_type': share_type,
                          'e': e
                      })
                raise exceptions.CommandError(msg)

        kwargs['share_types'] = share_types_list

        if parsed_args.public:
            kwargs['is_public'] = strutils.bool_from_string(parsed_args.public,
                                                            default=True)

        group_specs = {}
        if parsed_args.group_specs:
            for item in parsed_args.group_specs:
                group_specs = utils.extract_group_specs(group_specs, [item])

        kwargs['group_specs'] = group_specs

        share_group_type = share_client.share_group_types.create(**kwargs)

        formatter = parsed_args.formatter

        formatted_group_type = utils.format_share_group_type(
            share_group_type, formatter)

        return (ATTRIBUTES,
                oscutils.get_dict_properties(formatted_group_type, ATTRIBUTES))
コード例 #29
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_type = apiutils.find_resource(share_client.share_types,
                                            parsed_args.share_type)

        can_update = (share_client.api_version >=
                      api_versions.APIVersion('2.50'))

        kwargs = {}
        if parsed_args.name is not None:
            if can_update:
                kwargs['name'] = parsed_args.name
            else:
                raise exceptions.CommandError(
                    "Setting (new) name to share type "
                    "is only available with API microversion >= 2.50")
        if parsed_args.description is not None:
            if can_update:
                kwargs['description'] = parsed_args.description
            else:
                raise exceptions.CommandError(
                    "Setting (new) description to share type "
                    "is only available with API microversion >= 2.50")
        if parsed_args.public is not None:
            if can_update:
                kwargs['is_public'] = strutils.bool_from_string(
                    parsed_args.public, default=True)
            else:
                raise exceptions.CommandError(
                    "Setting visibility to share type "
                    "is only available with API microversion >= 2.50")
        if kwargs:
            share_type.update(**kwargs)

        if parsed_args.extra_specs:
            extra_specs = utils.extract_extra_specs(
                extra_specs={}, specs_to_add=parsed_args.extra_specs)
            try:
                share_type.set_keys(extra_specs)
            except Exception as e:
                raise exceptions.CommandError(
                    "Failed to set share type key: %s" % e)
コード例 #30
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        failure_count = 0

        for message in parsed_args.message:
            try:
                message_ref = apiutils.find_resource(share_client.messages,
                                                     message)
                share_client.messages.delete(message_ref)
            except Exception as e:
                failure_count += 1
                LOG.error(_("Delete for message %(message)s failed: %(e)s"), {
                    'message': message,
                    'e': e
                })

        if failure_count > 0:
            raise exceptions.CommandError(
                _("Unable to delete some or all of the specified messages."))