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
This commit is contained in:
parent
ee35409069
commit
3dd9613b21
@ -430,7 +430,7 @@ class TestVolumeCreate(TestVolume):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.volumes_mock.create.assert_called_once_with(
|
self.volumes_mock.create.assert_called_once_with(
|
||||||
size=None,
|
size=snapshot.size,
|
||||||
snapshot_id=snapshot.id,
|
snapshot_id=snapshot.id,
|
||||||
name=self.new_volume.name,
|
name=self.new_volume.name,
|
||||||
description=None,
|
description=None,
|
||||||
|
@ -186,11 +186,21 @@ class CreateVolume(command.ShowOne):
|
|||||||
image_client.images,
|
image_client.images,
|
||||||
parsed_args.image).id
|
parsed_args.image).id
|
||||||
|
|
||||||
|
size = parsed_args.size
|
||||||
|
|
||||||
snapshot = None
|
snapshot = None
|
||||||
if parsed_args.snapshot:
|
if parsed_args.snapshot:
|
||||||
snapshot = utils.find_resource(
|
snapshot_obj = utils.find_resource(
|
||||||
volume_client.volume_snapshots,
|
volume_client.volume_snapshots,
|
||||||
parsed_args.snapshot).id
|
parsed_args.snapshot)
|
||||||
|
snapshot = snapshot_obj.id
|
||||||
|
# Cinder requires a value for size when creating a volume
|
||||||
|
# even if creating from a snapshot. Cinder will create the
|
||||||
|
# volume with at least the same size as the snapshot anyway,
|
||||||
|
# so since we have the object here, just override the size
|
||||||
|
# value if it's either not given or is smaller than the
|
||||||
|
# snapshot size.
|
||||||
|
size = max(size or 0, snapshot_obj.size)
|
||||||
|
|
||||||
project = None
|
project = None
|
||||||
if parsed_args.project:
|
if parsed_args.project:
|
||||||
@ -205,7 +215,7 @@ class CreateVolume(command.ShowOne):
|
|||||||
parsed_args.user).id
|
parsed_args.user).id
|
||||||
|
|
||||||
volume = volume_client.volumes.create(
|
volume = volume_client.volumes.create(
|
||||||
size=parsed_args.size,
|
size=size,
|
||||||
snapshot_id=snapshot,
|
snapshot_id=snapshot,
|
||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
description=parsed_args.description,
|
description=parsed_args.description,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user