Skip to content

Commit 0d9ace6

Browse files
committed
Add CreateVolume class to v3
This patch acts as a base framework to add the parameters needed for manage volume support. This includes 2 changes: 1. Move get_parser and take_action code to common methods which can be utilized by both v2 and v3 2. Make _check_size_arg as a static method and move it inside CreateVolume class since it's not used by other classes. [2] was initially thought to be a follow up change but since we are implementing changes into the _check_size_arg method for v3, it makes sense to just include it in CreateVolume class to avoid adding a new additional method. Similar changes are done for v2 as well. Change-Id: I9315e457ebd6c5ba4cc67452f92c9dc8c139ee3c
1 parent 5e5b89f commit 0d9ace6

3 files changed

Lines changed: 59 additions & 21 deletions

File tree

openstackclient/volume/v2/volume.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,27 @@ def human_readable(self):
8888
return msg
8989

9090

91-
def _check_size_arg(args):
92-
"""Check whether --size option is required or not.
93-
94-
Require size parameter only in case when snapshot or source
95-
volume is not specified.
96-
"""
91+
class CreateVolume(command.ShowOne):
92+
_description = _("Create new volume")
9793

98-
if (
99-
args.snapshot or args.source or args.backup
100-
) is None and args.size is None:
101-
msg = _(
102-
"--size is a required option if snapshot, backup "
103-
"or source volume are not specified."
104-
)
105-
raise exceptions.CommandError(msg)
94+
@staticmethod
95+
def _check_size_arg(args):
96+
"""Check whether --size option is required or not.
10697
98+
Require size parameter only in case when snapshot or source
99+
volume is not specified.
100+
"""
107101

108-
class CreateVolume(command.ShowOne):
109-
_description = _("Create new volume")
102+
if (
103+
args.snapshot or args.source or args.backup
104+
) is None and args.size is None:
105+
msg = _(
106+
"--size is a required option if snapshot, backup "
107+
"or source volume are not specified."
108+
)
109+
raise exceptions.CommandError(msg)
110110

111-
def get_parser(self, prog_name):
111+
def _get_parser(self, prog_name):
112112
parser = super().get_parser(prog_name)
113113
parser.add_argument(
114114
"name",
@@ -216,10 +216,14 @@ def get_parser(self, prog_name):
216216
action="store_true",
217217
help=_("Set volume to read-write access mode (default)"),
218218
)
219+
return parser, source_group
220+
221+
def get_parser(self, prog_name):
222+
parser, _ = self._get_parser(prog_name)
219223
return parser
220224

221-
def take_action(self, parsed_args):
222-
_check_size_arg(parsed_args)
225+
def _take_action(self, parsed_args):
226+
CreateVolume._check_size_arg(parsed_args)
223227
# size is validated in the above call to
224228
# _check_size_arg where we check that size
225229
# should be passed if we are not creating a
@@ -355,6 +359,9 @@ def take_action(self, parsed_args):
355359
volume._info.pop("links", None)
356360
return zip(*sorted(volume._info.items()))
357361

362+
def take_action(self, parsed_args):
363+
return self._take_action(parsed_args)
364+
358365

359366
class DeleteVolume(command.Command):
360367
_description = _("Delete volume(s)")

openstackclient/volume/v3/volume.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from osc_lib import utils
2424

2525
from openstackclient.i18n import _
26-
26+
from openstackclient.volume.v2 import volume as volume_v2
2727

2828
LOG = logging.getLogger(__name__)
2929

@@ -113,3 +113,34 @@ def take_action(self, parsed_args):
113113
)
114114

115115
volume_client.revert_volume_to_snapshot(volume, snapshot)
116+
117+
118+
class CreateVolume(volume_v2.CreateVolume):
119+
_description = _("Create new volume")
120+
121+
@staticmethod
122+
def _check_size_arg(args):
123+
"""Check whether --size option is required or not.
124+
125+
Require size parameter in case if any of the following is not specified:
126+
* snapshot
127+
* source volume
128+
* backup
129+
* remote source (volume to be managed)
130+
"""
131+
132+
if (
133+
args.snapshot or args.source or args.backup or args.remote_source
134+
) is None and args.size is None:
135+
msg = _(
136+
"--size is a required option if none of --snapshot, "
137+
"--backup, --source, or --remote-source are provided."
138+
)
139+
raise exceptions.CommandError(msg)
140+
141+
def get_parser(self, prog_name):
142+
parser, _ = self._get_parser(prog_name)
143+
return parser
144+
145+
def take_action(self, parsed_args):
146+
return self._take_action(parsed_args)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ openstack.volume.v3 =
765765
consistency_group_snapshot_list = openstackclient.volume.v2.consistency_group_snapshot:ListConsistencyGroupSnapshot
766766
consistency_group_snapshot_show = openstackclient.volume.v2.consistency_group_snapshot:ShowConsistencyGroupSnapshot
767767

768-
volume_create = openstackclient.volume.v2.volume:CreateVolume
768+
volume_create = openstackclient.volume.v3.volume:CreateVolume
769769
volume_delete = openstackclient.volume.v2.volume:DeleteVolume
770770
volume_list = openstackclient.volume.v2.volume:ListVolume
771771
volume_migrate = openstackclient.volume.v2.volume:MigrateVolume

0 commit comments

Comments
 (0)