diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 193e82f013..1b5e4666cb 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -107,7 +107,7 @@ class CreateVolume(command.ShowOne): ) raise exceptions.CommandError(msg) - def _get_parser(self, prog_name): + def get_parser(self, prog_name): parser = super().get_parser(prog_name) parser.add_argument( "name", @@ -216,14 +216,10 @@ class CreateVolume(command.ShowOne): default=None, 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): - CreateVolume._check_size_arg(parsed_args) + self._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 diff --git a/openstackclient/volume/v3/volume.py b/openstackclient/volume/v3/volume.py index 64aa5f076f..653ab64b2e 100644 --- a/openstackclient/volume/v3/volume.py +++ b/openstackclient/volume/v3/volume.py @@ -31,7 +31,6 @@ from osc_lib import utils from openstackclient.common import pagination from openstackclient.i18n import _ from openstackclient.identity import common as identity_common -from openstackclient.volume.v2 import volume as volume_v2 LOG = logging.getLogger(__name__) @@ -91,7 +90,7 @@ class AttachmentsColumn(cliff_columns.FormattableColumn): return msg -class CreateVolume(volume_v2.CreateVolume): +class CreateVolume(command.ShowOne): _description = _("Create new volume") @staticmethod @@ -117,8 +116,48 @@ class CreateVolume(volume_v2.CreateVolume): raise exceptions.CommandError(msg) def get_parser(self, prog_name): - parser, source_group = self._get_parser(prog_name) - + parser = super().get_parser(prog_name) + parser.add_argument( + "name", + metavar="", + nargs="?", + help=_("Volume name"), + ) + parser.add_argument( + "--size", + metavar="", + type=int, + help=_( + "Volume size in GB (required unless --snapshot or " + "--source specified)" + ), + ) + parser.add_argument( + "--type", + metavar="", + help=_("Set the type of volume"), + ) + source_group = parser.add_mutually_exclusive_group() + source_group.add_argument( + "--image", + metavar="", + help=_("Use as source of volume (name or ID)"), + ) + source_group.add_argument( + "--snapshot", + metavar="", + help=_("Use as source of volume (name or ID)"), + ) + source_group.add_argument( + "--source", + metavar="", + help=_("Volume to clone (name or ID)"), + ) + source_group.add_argument( + "--source-replicated", + metavar="", + help=argparse.SUPPRESS, + ) source_group.add_argument( "--backup", metavar="", @@ -138,6 +177,72 @@ class CreateVolume(volume_v2.CreateVolume): "--remote-source source-id=test_id')" ), ) + parser.add_argument( + "--description", + metavar="", + help=_("Volume description"), + ) + parser.add_argument( + "--availability-zone", + metavar="", + help=_("Create volume in "), + ) + parser.add_argument( + "--consistency-group", + metavar="consistency-group>", + help=_("Consistency group where the new volume belongs to"), + ) + parser.add_argument( + "--property", + metavar="", + action=parseractions.KeyValueAction, + dest="properties", + help=_( + "Set a property to this volume " + "(repeat option to set multiple properties)" + ), + ) + parser.add_argument( + "--hint", + metavar="", + action=KeyValueHintAction, + help=_( + "Arbitrary scheduler hint key-value pairs to help creating " + "a volume. Repeat the option to set multiple hints. " + "'same_host' and 'different_host' get values appended when " + "repeated, all other keys take the last given value" + ), + ) + bootable_group = parser.add_mutually_exclusive_group() + bootable_group.add_argument( + "--bootable", + action="store_true", + dest="bootable", + default=None, + help=_("Mark volume as bootable"), + ) + bootable_group.add_argument( + "--non-bootable", + action="store_false", + dest="bootable", + default=None, + help=_("Mark volume as non-bootable (default)"), + ) + readonly_group = parser.add_mutually_exclusive_group() + readonly_group.add_argument( + "--read-only", + action="store_true", + dest="read_only", + default=None, + help=_("Set volume to read-only access mode"), + ) + readonly_group.add_argument( + "--read-write", + action="store_false", + dest="read_only", + default=None, + help=_("Set volume to read-write access mode (default)"), + ) parser.add_argument( "--host", metavar="", @@ -160,7 +265,7 @@ class CreateVolume(volume_v2.CreateVolume): return parser def take_action(self, parsed_args): - CreateVolume._check_size_arg(parsed_args) + self._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 @@ -351,11 +456,33 @@ class CreateVolume(volume_v2.CreateVolume): return zip(*sorted(volume._info.items())) -class DeleteVolume(volume_v2.DeleteVolume): +class DeleteVolume(command.Command): _description = _("Delete volume(s)") def get_parser(self, prog_name): parser = super().get_parser(prog_name) + parser.add_argument( + "volumes", + metavar="", + nargs="+", + help=_("Volume(s) to delete (name or ID)"), + ) + group = parser.add_mutually_exclusive_group() + group.add_argument( + "--force", + action="store_true", + help=_( + "Attempt forced removal of volume(s), regardless of state " + "(defaults to False)" + ), + ) + group.add_argument( + "--purge", + action="store_true", + help=_( + "Remove any snapshots along with volume(s) (defaults to False)" + ), + ) parser.add_argument( '--remote', action='store_true',