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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user