summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-12-02 18:49:37 +0000
committerGerrit Code Review <review@openstack.org>2016-12-02 18:49:37 +0000
commitd1f1f092c4e9073f750f4c32d1b343b19b463ded (patch)
treebb2eaf3c644ac2932832dab8b19c4c0f5fb5ed51 /openstackclient/volume
parent2daeb30296198d50587888f75adbf994f3758e4a (diff)
parent4b14f3d0cb26dc89d7b62c70302eefaabc7cf2e3 (diff)
downloadpython-openstackclient-d1f1f092c4e9073f750f4c32d1b343b19b463ded.tar.gz
Merge "Add "--type" and "--retype-policy" options to "volume set" command"
Diffstat (limited to 'openstackclient/volume')
-rw-r--r--openstackclient/volume/v2/volume.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py
index 0531e0aa..80abfb55 100644
--- a/openstackclient/volume/v2/volume.py
+++ b/openstackclient/volume/v2/volume.py
@@ -509,6 +509,19 @@ class SetVolume(command.Command):
'in the database with no regard to actual status, '
'exercise caution when using)'),
)
+ parser.add_argument(
+ '--type',
+ metavar='<volume-type>',
+ help=_('New volume type (name or ID)'),
+ )
+ parser.add_argument(
+ '--retype-policy',
+ metavar='<retype-policy>',
+ choices=['never', 'on-demand'],
+ help=_('Migration policy while re-typing volume '
+ '("never" or "on-demand", default is "never" ) '
+ '(available only when "--type" option is specified)'),
+ )
bootable_group = parser.add_mutually_exclusive_group()
bootable_group.add_argument(
"--bootable",
@@ -590,6 +603,28 @@ class SetVolume(command.Command):
LOG.error(_("Failed to set volume read-only access "
"mode flag: %s"), e)
result += 1
+ if parsed_args.type:
+ # get the migration policy
+ migration_policy = 'never'
+ if parsed_args.retype_policy:
+ migration_policy = parsed_args.retype_policy
+ try:
+ # find the volume type
+ volume_type = utils.find_resource(
+ volume_client.volume_types,
+ parsed_args.type)
+ # reset to the new volume type
+ volume_client.volumes.retype(
+ volume.id,
+ volume_type.id,
+ migration_policy)
+ except Exception as e:
+ LOG.error(_("Failed to set volume type: %s"), e)
+ result += 1
+ elif parsed_args.retype_policy:
+ # If the "--retype-policy" is specified without "--type"
+ LOG.warning(_("'--retype-policy' option will not work "
+ "without '--type' option"))
kwargs = {}
if parsed_args.name: