From bbe9a04f46db2759539e008302869d9e1fbb0bec Mon Sep 17 00:00:00 2001 From: David Wettstein Date: Thu, 12 Nov 2020 23:21:47 +0100 Subject: [PATCH 1/2] Add method delete_all_nics --- pyvcloud/vcd/vm.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pyvcloud/vcd/vm.py b/pyvcloud/vcd/vm.py index acb2d2a4..227fdaa7 100644 --- a/pyvcloud/vcd/vm.py +++ b/pyvcloud/vcd/vm.py @@ -739,6 +739,27 @@ def delete_nic(self, index): net_conn_section, RelationType.EDIT, EntityType.NETWORK_CONNECTION_SECTION.value, net_conn_section) + def delete_all_nics(self): + """Deletes all nics from the VM. + + :return: an object containing EntityType.TASK XML data which represents + the asynchronous task deleting all nics. + + :rtype: lxml.objectify.ObjectifiedElement + """ + # get network connection section. + net_conn_section = self.get_resource().NetworkConnectionSection + + if hasattr(net_conn_section, 'NetworkConnection'): + for nc in net_conn_section.NetworkConnection: + net_conn_section.remove(nc) + else: + raise InvalidStateException( + 'No nics found in the VM' % (self.get_resource().get('name'))) + return self.client.put_linked_resource( + net_conn_section, RelationType.EDIT, + EntityType.NETWORK_CONNECTION_SECTION.value, net_conn_section) + def install_vmware_tools(self): """Install vmware tools in the vm. From bb5294cdbad265925acb2d08ff3c80767ad4387b Mon Sep 17 00:00:00 2001 From: David Wettstein Date: Wed, 22 Dec 2021 21:12:14 +0100 Subject: [PATCH 2/2] fix: don't raise if no nics found --- pyvcloud/vcd/vm.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyvcloud/vcd/vm.py b/pyvcloud/vcd/vm.py index 227fdaa7..f6ce2303 100644 --- a/pyvcloud/vcd/vm.py +++ b/pyvcloud/vcd/vm.py @@ -753,9 +753,6 @@ def delete_all_nics(self): if hasattr(net_conn_section, 'NetworkConnection'): for nc in net_conn_section.NetworkConnection: net_conn_section.remove(nc) - else: - raise InvalidStateException( - 'No nics found in the VM' % (self.get_resource().get('name'))) return self.client.put_linked_resource( net_conn_section, RelationType.EDIT, EntityType.NETWORK_CONNECTION_SECTION.value, net_conn_section)