From 7e5a98bca91e0734f3440fdbeb12cd59273cd6a4 Mon Sep 17 00:00:00 2001 From: "jiahui.qiang" Date: Sun, 4 Dec 2016 00:29:03 +0800 Subject: Add some options to "volume create" command Add "--bootable", "--non-bootable", "--read-only" and "--read-write" options to "volume create" command for setting some attributes at the time of crration. Change-Id: I71b4e9fccb4ee0ab1a90e7179d6d2d34dbbae909 Implements: bp cinder-command-support --- openstackclient/volume/v1/volume.py | 38 +++++++++++++++++++++++++++++++++++++ openstackclient/volume/v2/volume.py | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) (limited to 'openstackclient/volume') diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py index 0087bad4..739484df 100644 --- a/openstackclient/volume/v1/volume.py +++ b/openstackclient/volume/v1/volume.py @@ -114,6 +114,28 @@ class CreateVolume(command.ShowOne): help=_('Set a property on this volume ' '(repeat option to set multiple properties)'), ) + bootable_group = parser.add_mutually_exclusive_group() + bootable_group.add_argument( + "--bootable", + action="store_true", + help=_("Mark volume as bootable") + ) + bootable_group.add_argument( + "--non-bootable", + action="store_true", + help=_("Mark volume as non-bootable (default)") + ) + readonly_group = parser.add_mutually_exclusive_group() + readonly_group.add_argument( + "--read-only", + action="store_true", + help=_("Set volume to read-only access mode") + ) + readonly_group.add_argument( + "--read-write", + action="store_true", + help=_("Set volume to read-write access mode (default)") + ) return parser @@ -166,6 +188,22 @@ class CreateVolume(command.ShowOne): parsed_args.property, image, ) + + if parsed_args.bootable or parsed_args.non_bootable: + try: + volume_client.volumes.set_bootable( + volume.id, parsed_args.bootable) + except Exception as e: + LOG.error(_("Failed to set volume bootable property: %s"), e) + if parsed_args.read_only or parsed_args.read_write: + try: + volume_client.volumes.update_readonly_flag( + volume.id, + parsed_args.read_only) + except Exception as e: + LOG.error(_("Failed to set volume read-only access " + "mode flag: %s"), e) + # Map 'metadata' column to 'properties' volume._info.update( { diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 80abfb55..301bf5e4 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -132,6 +132,28 @@ class CreateVolume(command.ShowOne): help=_("Allow volume to be attached more than once " "(default to False)") ) + bootable_group = parser.add_mutually_exclusive_group() + bootable_group.add_argument( + "--bootable", + action="store_true", + help=_("Mark volume as bootable") + ) + bootable_group.add_argument( + "--non-bootable", + action="store_true", + help=_("Mark volume as non-bootable (default)") + ) + readonly_group = parser.add_mutually_exclusive_group() + readonly_group.add_argument( + "--read-only", + action="store_true", + help=_("Set volume to read-only access mode") + ) + readonly_group.add_argument( + "--read-write", + action="store_true", + help=_("Set volume to read-write access mode (default)") + ) return parser def take_action(self, parsed_args): @@ -199,6 +221,22 @@ class CreateVolume(command.ShowOne): multiattach=parsed_args.multi_attach, scheduler_hints=parsed_args.hint, ) + + if parsed_args.bootable or parsed_args.non_bootable: + try: + volume_client.volumes.set_bootable( + volume.id, parsed_args.bootable) + except Exception as e: + LOG.error(_("Failed to set volume bootable property: %s"), e) + if parsed_args.read_only or parsed_args.read_write: + try: + volume_client.volumes.update_readonly_flag( + volume.id, + parsed_args.read_only) + except Exception as e: + LOG.error(_("Failed to set volume read-only access " + "mode flag: %s"), e) + # Remove key links from being displayed volume._info.update( { -- cgit v1.2.1