Skip to content

Commit 1f2aa3e

Browse files
committed
VMWare: Use get_hardware_devices throughout
Instead of retrieving the hardware devices through a get_object_property directly, and then inconsistently handling the normalisation in the called function or in the caller, use get_hardware_devices everywhere and handle the normalisation there. Change-Id: I221013216c4bdd241a894fb0a68c95d98d649c33
1 parent 370830e commit 1f2aa3e

File tree

5 files changed

+18
-69
lines changed

5 files changed

+18
-69
lines changed

nova/tests/unit/virt/vmwareapi/test_vm_util.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,8 @@ def test_get_scsi_adapter_type(self):
376376
devices.append(ide_controller)
377377
fake._update_object("VirtualMachine", vm)
378378
# return the scsi type, not ide
379-
hardware_device = vm.get("config.hardware.device")
380379
self.assertEqual(constants.DEFAULT_ADAPTER_TYPE,
381-
vm_util.get_scsi_adapter_type(hardware_device))
380+
vm_util.get_scsi_adapter_type(devices))
382381

383382
def test_get_scsi_adapter_type_with_error(self):
384383
vm = fake.VirtualMachine()
@@ -392,10 +391,9 @@ def test_get_scsi_adapter_type_with_error(self):
392391
# has exceeded SCSI_MAX_CONNECT_NUMBER
393392
for i in range(0, constants.SCSI_MAX_CONNECT_NUMBER):
394393
scsi_controller.device.append('device' + str(i))
395-
hardware_device = vm.get("config.hardware.device")
396394
self.assertRaises(exception.StorageError,
397395
vm_util.get_scsi_adapter_type,
398-
hardware_device)
396+
devices)
399397

400398
def test_find_allocated_slots(self):
401399
disk1 = fake.VirtualDisk(200, 0)
@@ -1715,10 +1713,7 @@ def test_get_vm_boot_spec(self):
17151713
self.assertEqual(expected, result)
17161714

17171715
def _get_devices(self, filename):
1718-
devices = fake._create_array_of_type('VirtualDevice')
1719-
devices.VirtualDevice = self._vmdk_path_and_adapter_type_devices(
1720-
filename)
1721-
return devices
1716+
return self._vmdk_path_and_adapter_type_devices(filename)
17221717

17231718
def test_find_rescue_device(self):
17241719
filename = '[test_datastore] uuid/uuid-rescue.vmdk'

nova/virt/vmwareapi/vif.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ def get_vif_info(session, cluster, vif_model, network_info):
123123

124124
def get_network_device(hardware_devices, mac_address):
125125
"""Return the network device with MAC 'mac_address'."""
126-
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
127-
hardware_devices = hardware_devices.VirtualDevice
128126
for device in hardware_devices:
129127
if device.__class__.__name__ in vm_util.ALL_SUPPORTED_NETWORK_DEVICES:
130128
if hasattr(device, 'macAddress'):

nova/virt/vmwareapi/vm_util.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,6 @@ def get_scsi_adapter_type(hardware_devices):
744744
"""Selects a proper iscsi adapter type from the existing
745745
hardware devices
746746
"""
747-
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
748-
hardware_devices = hardware_devices.VirtualDevice
749-
750747
for device in hardware_devices:
751748
if device.__class__.__name__ in scsi_controller_classes:
752749
# find the controllers which still have available slots
@@ -840,9 +837,6 @@ def allocate_controller_key_and_unit_number(client_factory, devices,
840837

841838
def get_rdm_disk(hardware_devices, uuid):
842839
"""Gets the RDM disk key."""
843-
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
844-
hardware_devices = hardware_devices.VirtualDevice
845-
846840
for device in hardware_devices:
847841
if (device.__class__.__name__ == "VirtualDisk" and
848842
device.backing.__class__.__name__ ==
@@ -1277,9 +1271,6 @@ def propset_dict(propset):
12771271

12781272

12791273
def get_vmdk_backed_disk_device(hardware_devices, uuid):
1280-
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
1281-
hardware_devices = hardware_devices.VirtualDevice
1282-
12831274
for device in hardware_devices:
12841275
if (device.__class__.__name__ == "VirtualDisk" and
12851276
device.backing.__class__.__name__ ==
@@ -1289,9 +1280,6 @@ def get_vmdk_backed_disk_device(hardware_devices, uuid):
12891280

12901281

12911282
def get_vmdk_volume_disk(hardware_devices, path=None):
1292-
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
1293-
hardware_devices = hardware_devices.VirtualDevice
1294-
12951283
for device in hardware_devices:
12961284
if (device.__class__.__name__ == "VirtualDisk"):
12971285
if not path or path == device.backing.fileName:
@@ -1544,7 +1532,7 @@ def find_rescue_device(hardware_devices, instance):
15441532
:param instance: nova.objects.instance.Instance object
15451533
:return: the rescue disk device object
15461534
"""
1547-
for device in hardware_devices.VirtualDevice:
1535+
for device in hardware_devices:
15481536
if (device.__class__.__name__ == "VirtualDisk" and
15491537
device.backing.__class__.__name__ ==
15501538
'VirtualDiskFlatVer2BackingInfo' and
@@ -1583,13 +1571,7 @@ def detach_devices_from_vm(session, vm_ref, devices):
15831571

15841572
def get_ephemerals(session, vm_ref):
15851573
devices = []
1586-
hardware_devices = session._call_method(vutil,
1587-
"get_object_property",
1588-
vm_ref,
1589-
"config.hardware.device")
1590-
1591-
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
1592-
hardware_devices = hardware_devices.VirtualDevice
1574+
hardware_devices = get_hardware_devices(session, vm_ref)
15931575

15941576
for device in hardware_devices:
15951577
if device.__class__.__name__ == "VirtualDisk":
@@ -1601,11 +1583,7 @@ def get_ephemerals(session, vm_ref):
16011583

16021584

16031585
def get_swap(session, vm_ref):
1604-
hardware_devices = session._call_method(vutil, "get_object_property",
1605-
vm_ref, "config.hardware.device")
1606-
1607-
if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
1608-
hardware_devices = hardware_devices.VirtualDevice
1586+
hardware_devices = get_hardware_devices(session, vm_ref)
16091587

16101588
for device in hardware_devices:
16111589
if (device.__class__.__name__ == "VirtualDisk" and

nova/virt/vmwareapi/vmops.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,7 @@ def _attach_cdrom_to_vm(self, vm_ref, instance,
885885
datastore, file_path):
886886
"""Attach cdrom to VM by reconfiguration."""
887887
client_factory = self._session.vim.client.factory
888-
devices = self._session._call_method(vutil,
889-
"get_object_property",
890-
vm_ref,
891-
"config.hardware.device")
888+
devices = vm_util.get_hardware_devices(self._session, vm_ref)
892889
(controller_key, unit_number,
893890
controller_spec) = vm_util.allocate_controller_key_and_unit_number(
894891
client_factory,
@@ -1189,10 +1186,7 @@ def resume(self, instance):
11891186
raise exception.InstanceResumeFailure(reason=reason)
11901187

11911188
def _get_rescue_device(self, instance, vm_ref):
1192-
hardware_devices = self._session._call_method(vutil,
1193-
"get_object_property",
1194-
vm_ref,
1195-
"config.hardware.device")
1189+
hardware_devices = vm_util.get_hardware_devices(self._session, vm_ref)
11961190
return vm_util.find_rescue_device(hardware_devices,
11971191
instance)
11981192

@@ -1649,8 +1643,7 @@ def live_migration(self, context, instance, dest,
16491643
network_info = instance.get_network_info()
16501644
client_factory = self._session.vim.client.factory
16511645
devices = []
1652-
hardware_devices = self._session._call_method(
1653-
vutil, "get_object_property", vm_ref, "config.hardware.device")
1646+
hardware_devices = vm_util.get_hardware_devices(self._session, vm_ref)
16541647
vif_model = instance.image_meta.properties.get('hw_vif_model',
16551648
constants.DEFAULT_VIF_MODEL)
16561649
for vif in network_info:
@@ -1959,11 +1952,8 @@ def detach_interface(self, context, instance, vif):
19591952
"VM") % vif['id']
19601953
raise exception.NotFound(msg)
19611954

1962-
hardware_devices = self._session._call_method(
1963-
vutil,
1964-
"get_object_property",
1965-
vm_ref,
1966-
"config.hardware.device")
1955+
hardware_devices = vm_util.get_hardware_devices(self._session,
1956+
vm_ref)
19671957
device = vmwarevif.get_network_device(hardware_devices,
19681958
vif['address'])
19691959
if device is None:

nova/virt/vmwareapi/volumeops.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ def attach_disk_to_vm(self, vm_ref, instance,
4646
"""Attach disk to VM by reconfiguration."""
4747
instance_name = instance.name
4848
client_factory = self._session.vim.client.factory
49-
devices = self._session._call_method(vutil,
50-
"get_object_property",
51-
vm_ref,
52-
"config.hardware.device")
49+
devices = vm_util.get_hardware_devices(self._session, vm_ref)
5350
(controller_key, unit_number,
5451
controller_spec) = vm_util.allocate_controller_key_and_unit_number(
5552
client_factory,
@@ -309,11 +306,8 @@ def _get_volume_ref(self, volume_ref_name):
309306

310307
def _get_vmdk_base_volume_device(self, volume_ref):
311308
# Get the vmdk file name that the VM is pointing to
312-
hardware_devices = self._session._call_method(
313-
vutil,
314-
"get_object_property",
315-
volume_ref,
316-
"config.hardware.device")
309+
hardware_devices = vm_util.get_hardware_devices(self._session,
310+
volume_ref)
317311
return vm_util.get_vmdk_volume_disk(hardware_devices)
318312

319313
def _attach_volume_vmdk(self, connection_info, instance,
@@ -364,8 +358,8 @@ def _attach_volume_iscsi(self, connection_info, instance,
364358
reason=_("Unable to find iSCSI Target"))
365359
if adapter_type is None:
366360
# Get the vmdk file name that the VM is pointing to
367-
hardware_devices = self._session._call_method(
368-
vutil, "get_object_property", vm_ref, "config.hardware.device")
361+
hardware_devices = vm_util.get_hardware_devices(self._session,
362+
vm_ref)
369363
adapter_type = vm_util.get_scsi_adapter_type(hardware_devices)
370364

371365
self.attach_disk_to_vm(vm_ref, instance,
@@ -491,10 +485,7 @@ def _consolidate_vmdk_volume(self, instance, vm_ref, device, volume_ref,
491485

492486
def _get_vmdk_backed_disk_device(self, vm_ref, connection_info_data):
493487
# Get the vmdk file name that the VM is pointing to
494-
hardware_devices = self._session._call_method(vutil,
495-
"get_object_property",
496-
vm_ref,
497-
"config.hardware.device")
488+
hardware_devices = vm_util.get_hardware_devices(self._session, vm_ref)
498489

499490
# Get disk uuid
500491
disk_uuid = self._get_volume_uuid(vm_ref,
@@ -560,10 +551,7 @@ def _detach_volume_iscsi(self, connection_info, instance):
560551
reason=_("Unable to find iSCSI Target"))
561552

562553
# Get the vmdk file name that the VM is pointing to
563-
hardware_devices = self._session._call_method(vutil,
564-
"get_object_property",
565-
vm_ref,
566-
"config.hardware.device")
554+
hardware_devices = vm_util.get_hardware_devices(self._session, vm_ref)
567555
device = vm_util.get_rdm_disk(hardware_devices, uuid)
568556
if device is None:
569557
raise exception.DiskNotFound(message=_("Unable to find volume"))

0 commit comments

Comments
 (0)