Cleanup _convert_block_devices

_convert_block_devices was instantiating 2 objects for every 1
returned due to the _is_transformable test. This change simplifies the
code by removing the nested function, and at the same time does the
conversion in a single pass, which is more efficient.

Change-Id: Id6b583a1c08d684fcff073dd0289be8e3919ba0a
This commit is contained in:
Matthew Booth
2014-10-01 10:13:40 +01:00
parent c798798c6b
commit c81db5ed0e

View File

@@ -360,17 +360,14 @@ class DriverBlankBlockDevice(DriverVolumeBlockDevice):
def _convert_block_devices(device_type, block_device_mapping):
def _is_transformable(bdm):
devices = []
for bdm in block_device_mapping:
try:
device_type(bdm)
devices.append(device_type(bdm))
except _NotTransformable:
return False
return True
return [device_type(bdm)
for bdm in block_device_mapping
if _is_transformable(bdm)]
pass
return devices
convert_swap = functools.partial(_convert_block_devices,
DriverSwapBlockDevice)