From 80ada951e6ff22b0fa6c1704f6c293e68f9b521f Mon Sep 17 00:00:00 2001 From: David Wettstein Date: Thu, 12 Nov 2020 19:47:46 +0100 Subject: [PATCH] Fix AttributeError in delete_nic --- pyvcloud/vcd/vm.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pyvcloud/vcd/vm.py b/pyvcloud/vcd/vm.py index 5ad1ec4a0..4e700ac03 100644 --- a/pyvcloud/vcd/vm.py +++ b/pyvcloud/vcd/vm.py @@ -716,13 +716,14 @@ def delete_nic(self, index): indices = [None] * 10 nic_not_found = True # find the nic with the given index - for nc in net_conn_section.NetworkConnection: - if int(nc.NetworkConnectionIndex.text) == index: - net_conn_section.remove(nc) - nic_not_found = False - else: - indices[int(nc.NetworkConnectionIndex. - text)] = nc.NetworkConnectionIndex.text + if hasattr(net_conn_section, 'NetworkConnection'): + for nc in net_conn_section.NetworkConnection: + if int(nc.NetworkConnectionIndex.text) == index: + net_conn_section.remove(nc) + nic_not_found = False + else: + indices[int(nc.NetworkConnectionIndex. + text)] = nc.NetworkConnectionIndex.text if nic_not_found: raise InvalidParameterException(