summaryrefslogtreecommitdiff
path: root/openstackclient/volume
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
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')
-rw-r--r--openstackclient/volume/v1/volume.py30
-rw-r--r--openstackclient/volume/v2/volume.py67
2 files changed, 83 insertions, 14 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
diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py
index b0067189..e7405114 100644
--- a/openstackclient/volume/v2/volume.py
+++ b/openstackclient/volume/v2/volume.py
@@ -30,6 +30,20 @@ from openstackclient.identity import common as identity_common
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 or args.source_replicated)
+ 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"""
@@ -44,29 +58,35 @@ class CreateVolume(command.ShowOne):
"--size",
metavar="<size>",
type=int,
- required=True,
- help=_("Volume size in GB"),
+ help=_("Volume size in GB (Required unless --snapshot or "
+ "--source or --source-replicated 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)"),
)
- parser.add_argument(
+ source_group.add_argument(
"--snapshot",
metavar="<snapshot>",
help=_("Use <snapshot> as source of volume (name or ID)"),
)
- parser.add_argument(
+ source_group.add_argument(
"--source",
metavar="<volume>",
help=_("Volume to clone (name or ID)"),
)
+ source_group.add_argument(
+ "--source-replicated",
+ metavar="<replicated-volume>",
+ help=_("Replicated volume to clone (name or ID)"),
+ )
parser.add_argument(
"--description",
metavar="<description>",
@@ -88,15 +108,34 @@ class CreateVolume(command.ShowOne):
help=_("Create volume in <availability-zone>"),
)
parser.add_argument(
+ "--consistency-group",
+ metavar="consistency-group>",
+ help=_("Consistency group where the new volume belongs to"),
+ )
+ parser.add_argument(
"--property",
metavar="<key=value>",
action=parseractions.KeyValueAction,
help=_("Set a property to this volume "
"(repeat option to set multiple properties)"),
)
+ parser.add_argument(
+ "--hint",
+ metavar="<key=value>",
+ action=parseractions.KeyValueAction,
+ help=_("Arbitrary scheduler hint key-value pairs to help boot "
+ "an instance (repeat option to set multiple hints)"),
+ )
+ parser.add_argument(
+ "--multi-attach",
+ action="store_true",
+ help=_("Allow volume to be attached more than once "
+ "(default to False)")
+ )
return parser
def take_action(self, parsed_args):
+ _check_size_arg(parsed_args)
identity_client = self.app.client_manager.identity
volume_client = self.app.client_manager.volume
image_client = self.app.client_manager.image
@@ -107,6 +146,18 @@ class CreateVolume(command.ShowOne):
volume_client.volumes,
parsed_args.source).id
+ replicated_source_volume = None
+ if parsed_args.source_replicated:
+ replicated_source_volume = utils.find_resource(
+ volume_client.volumes,
+ parsed_args.source_replicated).id
+
+ consistency_group = None
+ if parsed_args.consistency_group:
+ consistency_group = utils.find_resource(
+ volume_client.consistencygroups,
+ parsed_args.consistency_group).id
+
image = None
if parsed_args.image:
image = utils.find_resource(
@@ -142,7 +193,11 @@ class CreateVolume(command.ShowOne):
availability_zone=parsed_args.availability_zone,
metadata=parsed_args.property,
imageRef=image,
- source_volid=source_volume
+ source_volid=source_volume,
+ consistencygroup_id=consistency_group,
+ source_replica=replicated_source_volume,
+ multiattach=parsed_args.multi_attach,
+ scheduler_hints=parsed_args.hint,
)
# Remove key links from being displayed
volume._info.update(