@@ -716,13 +716,14 @@ def delete_nic(self, index):
716716 indices = [None ] * 10
717717 nic_not_found = True
718718 # find the nic with the given index
719- for nc in net_conn_section .NetworkConnection :
720- if int (nc .NetworkConnectionIndex .text ) == index :
721- net_conn_section .remove (nc )
722- nic_not_found = False
723- else :
724- indices [int (nc .NetworkConnectionIndex .
725- text )] = nc .NetworkConnectionIndex .text
719+ if hasattr (net_conn_section , 'NetworkConnection' ):
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
726727
727728 if nic_not_found :
728729 raise InvalidParameterException (
@@ -1380,27 +1381,29 @@ def update_nic(self, network_name, nic_id=0,
13801381 # get network connection section.
13811382 net_conn_section = self .get_resource ().NetworkConnectionSection
13821383 nic_index = 0
1383- nic_found = False
1384- for network in net_conn_section .NetworkConnection :
1385- if network .get ('network' ) == network_name :
1386- if network .NetworkConnectionIndex == nic_id :
1387- nic_found = True
1388- if ip_address is not None :
1389- network .IpAddress = E .IpAddress (ip_address )
1390- network .IsConnected = E .IsConnected (is_connected )
1391- if ip_address_mode is not None :
1392- network .IpAddressAllocationMode = \
1393- E .IpAddressAllocationMode (ip_address_mode )
1394- if adapter_type is not None :
1395- network .NetworkAdapterType = E .NetworkAdapterType (
1396- adapter_type )
1397- if is_primary :
1398- nic_index = network .NetworkConnectionIndex
1399- break
1400-
1401- if nic_found is False :
1384+ nic_not_found = True
1385+ if hasattr (net_conn_section , 'NetworkConnection' ):
1386+ for nc in net_conn_section .NetworkConnection :
1387+ if nc .get ('network' ) == network_name :
1388+ if int (nc .NetworkConnectionIndex .text ) == nic_id :
1389+ nic_not_found = False
1390+ if ip_address is not None :
1391+ nc .IpAddress = E .IpAddress (ip_address )
1392+ nc .IsConnected = E .IsConnected (is_connected )
1393+ if ip_address_mode is not None :
1394+ nc .IpAddressAllocationMode = \
1395+ E .IpAddressAllocationMode (ip_address_mode )
1396+ if adapter_type is not None :
1397+ nc .NetworkAdapterType = E .NetworkAdapterType (
1398+ adapter_type )
1399+ if is_primary :
1400+ nic_index = nc .NetworkConnectionIndex
1401+ break
1402+
1403+ if nic_not_found :
14021404 raise EntityNotFoundException (
1403- 'Vapp with name \' %s\' not found.' % network_name )
1405+ 'Nic with name \' %s\' and index \' %s\' is not found in the VM \' %s\' ' %
1406+ (network_name , nic_id , self .get_resource ().get ('name' )))
14041407
14051408 if is_primary :
14061409 nic_index = int (nic_index .text )
0 commit comments