diff options
Diffstat (limited to 'openstackclient/volume')
| -rw-r--r-- | openstackclient/volume/v1/volume.py | 30 | ||||
| -rw-r--r-- | openstackclient/volume/v2/consistency_group.py | 57 | ||||
| -rw-r--r-- | openstackclient/volume/v2/volume.py | 67 |
3 files changed, 140 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/consistency_group.py b/openstackclient/volume/v2/consistency_group.py new file mode 100644 index 00000000..39f2d577 --- /dev/null +++ b/openstackclient/volume/v2/consistency_group.py @@ -0,0 +1,57 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""Volume v2 consistency group action implementations""" + +from osc_lib.command import command +from osc_lib import utils + +from openstackclient.i18n import _ + + +class ListConsistencyGroup(command.Lister): + """List consistency groups.""" + + def get_parser(self, prog_name): + parser = super(ListConsistencyGroup, self).get_parser(prog_name) + parser.add_argument( + '--all-projects', + action="store_true", + help=_('Show detail for all projects. Admin only. ' + '(defaults to False)') + ) + parser.add_argument( + '--long', + action="store_true", + help=_('List additional fields in output') + ) + return parser + + def take_action(self, parsed_args): + if parsed_args.long: + columns = ['ID', 'Status', 'Availability Zone', + 'Name', 'Description', 'Volume Types'] + else: + columns = ['ID', 'Status', 'Name'] + volume_client = self.app.client_manager.volume + consistency_groups = volume_client.consistencygroups.list( + detailed=True, + search_opts={'all_tenants': parsed_args.all_projects} + ) + + return (columns, ( + utils.get_item_properties( + s, columns, + formatters={'Volume Types': utils.format_list}) + for s in consistency_groups)) 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( |
