summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-10-18 14:59:28 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-11-23 10:34:31 +0800
commit4b14f3d0cb26dc89d7b62c70302eefaabc7cf2e3 (patch)
tree395a83ee00ce4ac943a636d32e041109e393e8f4 /openstackclient/volume
parent0b5655fae87b9cf278231fac8febe3114175ff9c (diff)
downloadpython-openstackclient-4b14f3d0cb26dc89d7b62c70302eefaabc7cf2e3.tar.gz
Add "--type" and "--retype-policy" options to "volume set" command
Add "--type" and "--retype-policy" options to "volume set" command in volume v2 (v2 only) to support changing the volume type for a volume Change-Id: I0153abdb967aee790586a57cef31930e32005c1b Implements: bp cinder-command-support
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 4a9192a0..b93af02e 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: