示例#1
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))
示例#2
0
def format_share_type(share_type):
    # share_type_access:is_public (true/false) --> visibility (public/private)
    is_public = 'share_type_access:is_public'
    visibility = 'public' if share_type._info.get(is_public) else 'private'
    share_type._info.pop(is_public, None)

    # optional_extra_specs --> extra_specs without required_extra_specs
    # required_extra_specs are displayed separately
    optional_extra_specs = share_type.extra_specs
    for key in share_type.required_extra_specs.keys():
        optional_extra_specs.pop(key, None)

    share_type._info.update({
        'visibility':
        visibility,
        'required_extra_specs':
        utils.format_properties(share_type.required_extra_specs),
        'optional_extra_specs':
        utils.format_properties(optional_extra_specs),
    })
    return share_type
示例#3
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        if share_client.api_version >= api_versions.APIVersion("2.45"):
            access_rule = share_client.share_access_rules.get(
                parsed_args.access_id)
            access_rule._info.update({
                'properties':
                utils.format_properties(access_rule._info.pop('metadata', {}))
            })
            return (ACCESS_RULE_ATTRIBUTES,
                    oscutils.get_dict_properties(access_rule._info,
                                                 ACCESS_RULE_ATTRIBUTES))
        else:
            raise exceptions.CommandError(
                "Displaying share access rule details is only available "
                "with API microversion 2.45 and higher.")
示例#4
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share_type = None
        if parsed_args.share_type:
            if share_client.api_version >= api_versions.APIVersion("2.23"):
                share_type = osc_utils.find_resource(share_client.share_types,
                                                     parsed_args.share_type).id
            else:
                raise exceptions.CommandError(
                    _("Filtering results by share type is only available with "
                      "manila API version >= 2.23"))

        search_opts = {
            'host': parsed_args.host,
            'backend': parsed_args.backend,
            'pool': parsed_args.pool,
            'share_type': share_type,
        }

        pools = share_client.pools.list(detailed=parsed_args.detail,
                                        search_opts=search_opts)

        columns = ["Name", "Host", "Backend", "Pool"]

        if parsed_args.detail:
            columns.append("Capabilities")
            if parsed_args.formatter == 'table':
                for pool in pools:
                    pool._info.update({
                        'capabilities':
                        utils.format_properties(pool.capabilities)
                    })

        data = (osc_utils.get_dict_properties(pool._info, columns)
                for pool in pools)

        return (columns, data)