summaryrefslogtreecommitdiff
path: root/openstackclient/volume/v2
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-07-12 19:23:47 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-07-12 19:23:47 +0800
commite310682235810759c17278365fcb76fac438f582 (patch)
tree820feba8d179819605530868abfeb1ff59fa1db0 /openstackclient/volume/v2
parent5a21eb25558c4820bdf1eec3f0d25fca00e7fd24 (diff)
downloadpython-openstackclient-e310682235810759c17278365fcb76fac438f582.tar.gz
Add "--project" option to "volume type create" command
Add "--project" and "--project-domain" options to "volume type create" command. We can use these options to add the type access to a given project when we create the volume type. Change-Id: I483a6b61dae137682c3d1f7527531b40e508ba92 Closes-Bug: #1602169
Diffstat (limited to 'openstackclient/volume/v2')
-rw-r--r--openstackclient/volume/v2/volume_type.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/openstackclient/volume/v2/volume_type.py b/openstackclient/volume/v2/volume_type.py
index 87f4c547..a1cd8bb5 100644
--- a/openstackclient/volume/v2/volume_type.py
+++ b/openstackclient/volume/v2/volume_type.py
@@ -66,12 +66,23 @@ class CreateVolumeType(command.ShowOne):
help=_('Set a property on this volume type '
'(repeat option to set multiple properties)'),
)
+ parser.add_argument(
+ '--project',
+ metavar='<project>',
+ help=_("Allow <project> to access private type (name or ID) "
+ "(Must be used with --private option)"),
+ )
+ identity_common.add_project_domain_option_to_parser(parser)
return parser
def take_action(self, parsed_args):
-
+ identity_client = self.app.client_manager.identity
volume_client = self.app.client_manager.volume
+ if parsed_args.project and not parsed_args.private:
+ msg = _("--project is only allowed with --private")
+ raise exceptions.CommandError(msg)
+
kwargs = {}
if parsed_args.public:
kwargs['is_public'] = True
@@ -84,6 +95,20 @@ class CreateVolumeType(command.ShowOne):
**kwargs
)
volume_type._info.pop('extra_specs')
+
+ if parsed_args.project:
+ try:
+ project_id = identity_common.find_project(
+ identity_client,
+ parsed_args.project,
+ parsed_args.project_domain,
+ ).id
+ volume_client.volume_type_access.add_project_access(
+ volume_type.id, project_id)
+ except Exception as e:
+ msg = _("Failed to add project %(project)s access to "
+ "type: %(e)s")
+ LOG.error(msg % {'project': parsed_args.project, 'e': e})
if parsed_args.property:
result = volume_type.set_keys(parsed_args.property)
volume_type._info.update({'properties': utils.format_dict(result)})