Skip to content

Commit 3dd9613

Browse files
emontyDean Troyer
authored andcommitted
Pass volume snapshot size to volume create
When creating a volume from a snapshot, the size parameter is required and type is checked. Since we have to pass something and it needs to be a valid data type (None is not acceptable) grab the size from the snapshot object and pass it. Change-Id: Ie23e3d23828919234e40336b5c65b22e140d337c
1 parent ee35409 commit 3dd9613

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def test_volume_create_with_snapshot(self):
430430
columns, data = self.cmd.take_action(parsed_args)
431431

432432
self.volumes_mock.create.assert_called_once_with(
433-
size=None,
433+
size=snapshot.size,
434434
snapshot_id=snapshot.id,
435435
name=self.new_volume.name,
436436
description=None,

openstackclient/volume/v2/volume.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,21 @@ def take_action(self, parsed_args):
186186
image_client.images,
187187
parsed_args.image).id
188188

189+
size = parsed_args.size
190+
189191
snapshot = None
190192
if parsed_args.snapshot:
191-
snapshot = utils.find_resource(
193+
snapshot_obj = utils.find_resource(
192194
volume_client.volume_snapshots,
193-
parsed_args.snapshot).id
195+
parsed_args.snapshot)
196+
snapshot = snapshot_obj.id
197+
# Cinder requires a value for size when creating a volume
198+
# even if creating from a snapshot. Cinder will create the
199+
# volume with at least the same size as the snapshot anyway,
200+
# so since we have the object here, just override the size
201+
# value if it's either not given or is smaller than the
202+
# snapshot size.
203+
size = max(size or 0, snapshot_obj.size)
194204

195205
project = None
196206
if parsed_args.project:
@@ -205,7 +215,7 @@ def take_action(self, parsed_args):
205215
parsed_args.user).id
206216

207217
volume = volume_client.volumes.create(
208-
size=parsed_args.size,
218+
size=size,
209219
snapshot_id=snapshot,
210220
name=parsed_args.name,
211221
description=parsed_args.description,

0 commit comments

Comments
 (0)