From c9e0c01f67a00e63bb5d8b5781d7e8e87b39136c Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Tue, 27 Sep 2016 12:27:05 +0800 Subject: Add and modify options for "volume create" command 1.Add mutually exclusive options into a mutually exclusive group. 2.Add "--source-replicated", "--consistency-group", "--hint" and "multi-attach" options 3.Make --size option to be optional under some cases Closes-Bug: #1568005 Closes-Bug: #1627913 Implements: bp implement-cinder-features Co-Authored-By: Roman Vasilets Change-Id: I2c4c3073195d33774e477f4d7f22e383b14b41dd --- openstackclient/volume/v1/volume.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'openstackclient/volume/v1') diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py index 89fa2014..cafe8ce6 100644 --- a/openstackclient/volume/v1/volume.py +++ b/openstackclient/volume/v1/volume.py @@ -30,6 +30,20 @@ from openstackclient.i18n import _ LOG = logging.getLogger(__name__) +def _check_size_arg(args): + """Check whether --size option is required or not. + + Require size parameter only in case when snapshot or source + volume is not specified. + """ + + if ((args.snapshot or args.source) + is None and args.size is None): + msg = _("--size is a required option if snapshot " + "or source volume is not specified.") + raise exceptions.CommandError(msg) + + class CreateVolume(command.ShowOne): """Create new volume""" @@ -43,32 +57,32 @@ class CreateVolume(command.ShowOne): parser.add_argument( '--size', metavar='', - required=True, type=int, - help=_('Volume size in GB'), + help=_("Volume size in GB (Required unless --snapshot or " + "--source is specified)"), ) parser.add_argument( '--type', metavar='', help=_("Set the type of volume"), ) - parser.add_argument( + source_group = parser.add_mutually_exclusive_group() + source_group.add_argument( '--image', metavar='', help=_('Use as source of volume (name or ID)'), ) - snapshot_group = parser.add_mutually_exclusive_group() - snapshot_group.add_argument( + source_group.add_argument( '--snapshot', metavar='', help=_('Use as source of volume (name or ID)'), ) - snapshot_group.add_argument( + source_group.add_argument( '--snapshot-id', metavar='', help=argparse.SUPPRESS, ) - parser.add_argument( + source_group.add_argument( '--source', metavar='', help=_('Volume to clone (name or ID)'), @@ -104,7 +118,7 @@ class CreateVolume(command.ShowOne): return parser def take_action(self, parsed_args): - + _check_size_arg(parsed_args) identity_client = self.app.client_manager.identity image_client = self.app.client_manager.image volume_client = self.app.client_manager.volume -- cgit v1.2.1