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

Commit

Permalink
Fix AttributeErrors in nic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dwettstein committed Nov 12, 2020
1 parent 23388db commit c5c0766
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions pyvcloud/vcd/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -1380,27 +1381,29 @@ def update_nic(self, network_name, nic_id=0,
# get network connection section.
net_conn_section = self.get_resource().NetworkConnectionSection
nic_index = 0
nic_found = False
for network in net_conn_section.NetworkConnection:
if network.get('network') == network_name:
if network.NetworkConnectionIndex == nic_id:
nic_found = True
if ip_address is not None:
network.IpAddress = E.IpAddress(ip_address)
network.IsConnected = E.IsConnected(is_connected)
if ip_address_mode is not None:
network.IpAddressAllocationMode = \
E.IpAddressAllocationMode(ip_address_mode)
if adapter_type is not None:
network.NetworkAdapterType = E.NetworkAdapterType(
adapter_type)
if is_primary:
nic_index = network.NetworkConnectionIndex
break

if nic_found is False:
nic_not_found = True
if hasattr(net_conn_section, 'NetworkConnection'):
for nc in net_conn_section.NetworkConnection:
if nc.get('network') == network_name:
if int(nc.NetworkConnectionIndex.text) == nic_id:
nic_not_found = False
if ip_address is not None:
nc.IpAddress = E.IpAddress(ip_address)
nc.IsConnected = E.IsConnected(is_connected)
if ip_address_mode is not None:
nc.IpAddressAllocationMode = \
E.IpAddressAllocationMode(ip_address_mode)
if adapter_type is not None:
nc.NetworkAdapterType = E.NetworkAdapterType(
adapter_type)
if is_primary:
nic_index = nc.NetworkConnectionIndex
break

if nic_not_found:
raise EntityNotFoundException(
'Vapp with name \'%s\' not found.' % network_name)
'Nic with name \'%s\' and index \'%s\' is not found in the VM \'%s\'' %
(network_name, nic_id, self.get_resource().get('name')))

if is_primary:
nic_index = int(nic_index.text)
Expand Down

0 comments on commit c5c0766

Please sign in to comment.