summaryrefslogtreecommitdiff
path: root/openstackclient/volume/v1
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-09-27 12:27:05 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-09-28 10:13:56 +0800
commitc9e0c01f67a00e63bb5d8b5781d7e8e87b39136c (patch)
treee7eba5ad18742e06fa3232214ab252cb6726ad23 /openstackclient/volume/v1
parent8d63b8b263ca4011761b062331d53d9b53b5031d (diff)
downloadpython-openstackclient-c9e0c01f67a00e63bb5d8b5781d7e8e87b39136c.tar.gz
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 <rvasilets@mirantis.com> Change-Id: I2c4c3073195d33774e477f4d7f22e383b14b41dd
Diffstat (limited to 'openstackclient/volume/v1')
-rw-r--r--openstackclient/volume/v1/volume.py30
1 files changed, 22 insertions, 8 deletions
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='<size>',
- 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='<volume-type>',
help=_("Set the type of volume"),
)
- parser.add_argument(
+ source_group = parser.add_mutually_exclusive_group()
+ source_group.add_argument(
'--image',
metavar='<image>',
help=_('Use <image> as source of volume (name or ID)'),
)
- snapshot_group = parser.add_mutually_exclusive_group()
- snapshot_group.add_argument(
+ source_group.add_argument(
'--snapshot',
metavar='<snapshot>',
help=_('Use <snapshot> as source of volume (name or ID)'),
)
- snapshot_group.add_argument(
+ source_group.add_argument(
'--snapshot-id',
metavar='<snapshot-id>',
help=argparse.SUPPRESS,
)
- parser.add_argument(
+ source_group.add_argument(
'--source',
metavar='<volume>',
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