diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 623a943b59..eaaa40a5a5 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -88,27 +88,27 @@ class AttachmentsColumn(cliff_columns.FormattableColumn): return msg -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.backup - ) is None and args.size is None: - msg = _( - "--size is a required option if snapshot, backup " - "or source volume are not specified." - ) - raise exceptions.CommandError(msg) - - class CreateVolume(command.ShowOne): _description = _("Create new volume") - def get_parser(self, prog_name): + @staticmethod + 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.backup + ) is None and args.size is None: + msg = _( + "--size is a required option if snapshot, backup " + "or source volume are not specified." + ) + raise exceptions.CommandError(msg) + + def _get_parser(self, prog_name): parser = super().get_parser(prog_name) parser.add_argument( "name", @@ -216,10 +216,14 @@ class CreateVolume(command.ShowOne): action="store_true", help=_("Set volume to read-write access mode (default)"), ) + return parser, source_group + + def get_parser(self, prog_name): + parser, _ = self._get_parser(prog_name) return parser - def take_action(self, parsed_args): - _check_size_arg(parsed_args) + def _take_action(self, parsed_args): + CreateVolume._check_size_arg(parsed_args) # size is validated in the above call to # _check_size_arg where we check that size # should be passed if we are not creating a @@ -355,6 +359,9 @@ class CreateVolume(command.ShowOne): volume._info.pop("links", None) return zip(*sorted(volume._info.items())) + def take_action(self, parsed_args): + return self._take_action(parsed_args) + class DeleteVolume(command.Command): _description = _("Delete volume(s)") diff --git a/openstackclient/volume/v3/volume.py b/openstackclient/volume/v3/volume.py index 91d58c3073..7f5a88fcd9 100644 --- a/openstackclient/volume/v3/volume.py +++ b/openstackclient/volume/v3/volume.py @@ -23,7 +23,7 @@ from osc_lib import exceptions from osc_lib import utils from openstackclient.i18n import _ - +from openstackclient.volume.v2 import volume as volume_v2 LOG = logging.getLogger(__name__) @@ -113,3 +113,34 @@ class VolumeRevertToSnapshot(command.Command): ) volume_client.revert_volume_to_snapshot(volume, snapshot) + + +class CreateVolume(volume_v2.CreateVolume): + _description = _("Create new volume") + + @staticmethod + def _check_size_arg(args): + """Check whether --size option is required or not. + + Require size parameter in case if any of the following is not specified: + * snapshot + * source volume + * backup + * remote source (volume to be managed) + """ + + if ( + args.snapshot or args.source or args.backup or args.remote_source + ) is None and args.size is None: + msg = _( + "--size is a required option if none of --snapshot, " + "--backup, --source, or --remote-source are provided." + ) + raise exceptions.CommandError(msg) + + def get_parser(self, prog_name): + parser, _ = self._get_parser(prog_name) + return parser + + def take_action(self, parsed_args): + return self._take_action(parsed_args) diff --git a/setup.cfg b/setup.cfg index bb3bcd50e3..0bca7c1e6e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -765,7 +765,7 @@ openstack.volume.v3 = consistency_group_snapshot_list = openstackclient.volume.v2.consistency_group_snapshot:ListConsistencyGroupSnapshot consistency_group_snapshot_show = openstackclient.volume.v2.consistency_group_snapshot:ShowConsistencyGroupSnapshot - volume_create = openstackclient.volume.v2.volume:CreateVolume + volume_create = openstackclient.volume.v3.volume:CreateVolume volume_delete = openstackclient.volume.v2.volume:DeleteVolume volume_list = openstackclient.volume.v2.volume:ListVolume volume_migrate = openstackclient.volume.v2.volume:MigrateVolume