Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

add "if" conditional to avoid looping with a non-existent attribute #737

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions pyvcloud/vcd/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,15 +1158,17 @@ def list_virtual_hardware_section(self, is_cpu=True, is_memory=True,
uri = self.href + '/virtualHardwareSection/disks'
disk_list = self.client.get_resource(uri)

for disk in disk_list.Item:
if disk['{' + NSMAP['rasd'] + '}Description'] == 'Hard disk':
vhs_disk_info = {
'diskElementName': str(disk[
'{' + NSMAP['rasd'] + '}ElementName']),
'diskVirtualQuantityInBytes': int(disk[
'{' + NSMAP['rasd'] + '}VirtualQuantity'])
}
result.append(vhs_disk_info)
if hasattr(disk_list, 'Item'):
for disk in disk_list.Item:
if disk['{' + NSMAP['rasd'] + '}Description'] \
== 'Hard disk':
vhs_disk_info = {
'diskElementName': str(disk[
'{' + NSMAP['rasd'] + '}ElementName']),
'diskVirtualQuantityInBytes': int(disk[
'{' + NSMAP['rasd'] + '}VirtualQuantity'])
}
result.append(vhs_disk_info)

if is_media:
uri = self.href + '/virtualHardwareSection/media'
Expand Down