From f04c4649fd318560f8e30238cc89937a2161b1c9 Mon Sep 17 00:00:00 2001 From: Trent McKenzie Date: Wed, 13 Jan 2021 16:34:27 +1300 Subject: [PATCH 1/3] add if conditional to avoid looping with a non-existant attribute --- pyvcloud/vcd/vm.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pyvcloud/vcd/vm.py b/pyvcloud/vcd/vm.py index 5ad1ec4a0..147c1071c 100644 --- a/pyvcloud/vcd/vm.py +++ b/pyvcloud/vcd/vm.py @@ -1158,15 +1158,16 @@ 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' From de737f86d81687471c5c1b803c0d734f841fcba3 Mon Sep 17 00:00:00 2001 From: Trent McKenzie Date: Tue, 19 Jan 2021 09:03:38 +1300 Subject: [PATCH 2/3] add line continuation to meet flake8 linting --- pyvcloud/vcd/vm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyvcloud/vcd/vm.py b/pyvcloud/vcd/vm.py index 147c1071c..42d8fcd32 100644 --- a/pyvcloud/vcd/vm.py +++ b/pyvcloud/vcd/vm.py @@ -1160,7 +1160,8 @@ def list_virtual_hardware_section(self, is_cpu=True, is_memory=True, if hasattr(disk_list, 'Item'): for disk in disk_list.Item: - if disk['{' + NSMAP['rasd'] + '}Description'] == 'Hard disk': + if disk['{' + NSMAP['rasd'] + '}Description'] \ + == 'Hard disk': vhs_disk_info = { 'diskElementName': str(disk[ '{' + NSMAP['rasd'] + '}ElementName']), From 72d457f329e04f242edaa870011c74e77e07a5f7 Mon Sep 17 00:00:00 2001 From: Trent McKenzie Date: Tue, 19 Jan 2021 15:15:04 +1300 Subject: [PATCH 3/3] correct continuation line indentation --- pyvcloud/vcd/vm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyvcloud/vcd/vm.py b/pyvcloud/vcd/vm.py index 42d8fcd32..7ffe2b0c3 100644 --- a/pyvcloud/vcd/vm.py +++ b/pyvcloud/vcd/vm.py @@ -1161,7 +1161,7 @@ def list_virtual_hardware_section(self, is_cpu=True, is_memory=True, if hasattr(disk_list, 'Item'): for disk in disk_list.Item: if disk['{' + NSMAP['rasd'] + '}Description'] \ - == 'Hard disk': + == 'Hard disk': vhs_disk_info = { 'diskElementName': str(disk[ '{' + NSMAP['rasd'] + '}ElementName']),