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

Commit efa8c68

Browse files
committed
Fix AttributeErrors in nic methods
1 parent d72c615 commit efa8c68

1 file changed

Lines changed: 30 additions & 27 deletions

File tree

pyvcloud/vcd/vm.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,14 @@ def delete_nic(self, index):
717717
indices = [None] * 10
718718
nic_not_found = True
719719
# find the nic with the given index
720-
for nc in net_conn_section.NetworkConnection:
721-
if int(nc.NetworkConnectionIndex.text) == index:
722-
net_conn_section.remove(nc)
723-
nic_not_found = False
724-
else:
725-
indices[int(nc.NetworkConnectionIndex.
726-
text)] = nc.NetworkConnectionIndex.text
720+
if hasattr(net_conn_section, 'NetworkConnection'):
721+
for nc in net_conn_section.NetworkConnection:
722+
if int(nc.NetworkConnectionIndex.text) == index:
723+
net_conn_section.remove(nc)
724+
nic_not_found = False
725+
else:
726+
indices[int(nc.NetworkConnectionIndex.
727+
text)] = nc.NetworkConnectionIndex.text
727728

728729
if nic_not_found:
729730
raise InvalidParameterException(
@@ -1381,27 +1382,29 @@ def update_nic(self, network_name, nic_id=0,
13811382
# get network connection section.
13821383
net_conn_section = self.get_resource().NetworkConnectionSection
13831384
nic_index = 0
1384-
nic_found = False
1385-
for network in net_conn_section.NetworkConnection:
1386-
if network.get('network') == network_name:
1387-
if network.NetworkConnectionIndex == nic_id:
1388-
nic_found = True
1389-
if ip_address is not None:
1390-
network.IpAddress = E.IpAddress(ip_address)
1391-
network.IsConnected = E.IsConnected(is_connected)
1392-
if ip_address_mode is not None:
1393-
network.IpAddressAllocationMode = \
1394-
E.IpAddressAllocationMode(ip_address_mode)
1395-
if adapter_type is not None:
1396-
network.NetworkAdapterType = E.NetworkAdapterType(
1397-
adapter_type)
1398-
if is_primary:
1399-
nic_index = network.NetworkConnectionIndex
1400-
break
1401-
1402-
if nic_found is False:
1385+
nic_not_found = True
1386+
if hasattr(net_conn_section, 'NetworkConnection'):
1387+
for nc in net_conn_section.NetworkConnection:
1388+
if nc.get('network') == network_name:
1389+
if int(nc.NetworkConnectionIndex.text) == nic_id:
1390+
nic_not_found = False
1391+
if ip_address is not None:
1392+
nc.IpAddress = E.IpAddress(ip_address)
1393+
nc.IsConnected = E.IsConnected(is_connected)
1394+
if ip_address_mode is not None:
1395+
nc.IpAddressAllocationMode = \
1396+
E.IpAddressAllocationMode(ip_address_mode)
1397+
if adapter_type is not None:
1398+
nc.NetworkAdapterType = E.NetworkAdapterType(
1399+
adapter_type)
1400+
if is_primary:
1401+
nic_index = nc.NetworkConnectionIndex
1402+
break
1403+
1404+
if nic_not_found:
14031405
raise EntityNotFoundException(
1404-
'VM Network with name \'%s\' not found.' % network_name)
1406+
'Nic with name \'%s\' and index \'%s\' is not found in the VM \'%s\'' %
1407+
(network_name, nic_id, self.get_resource().get('name')))
14051408

14061409
if is_primary:
14071410
nic_index = int(nic_index.text)

0 commit comments

Comments
 (0)