@@ -698,6 +698,63 @@ def list_nics(self):
698698 nics .append (nic )
699699 return nics
700700
701+ def update_nic (self , network_name , nic_id = 0 ,
702+ is_connected = False ,
703+ is_primary = False ,
704+ ip_address_mode = None ,
705+ ip_address = None ,
706+ adapter_type = None ):
707+ """Updates a nic of the VM.
708+
709+ :param str network_name: name of the network to be modified.
710+ :param bool is_connected: True, if the nic has to be connected.
711+ :param bool is_primary: True, if its a primary nic of the VM.
712+ :param str ip_address_mode: One of DHCP|POOL|MANUAL|NONE.
713+ :param str ip_address: to be set an ip in case of MANUAL mode.
714+ :param str adapter_type: nic adapter type.One of NetworkAdapterType
715+ values.
716+
717+ :return: an object containing EntityType.TASK XML data which represents
718+ the asynchronous task adding a nic.
719+
720+ :rtype: lxml.objectify.ObjectifiedElement
721+ """
722+ # get network connection section.
723+ net_conn_section = self .get_resource ().NetworkConnectionSection
724+ nic_index = 0
725+ nic_not_found = True
726+ if hasattr (net_conn_section , 'NetworkConnection' ):
727+ for nc in net_conn_section .NetworkConnection :
728+ if nc .get ('network' ) == network_name :
729+ if int (nc .NetworkConnectionIndex .text ) == nic_id :
730+ nic_not_found = False
731+ if ip_address is not None :
732+ nc .IpAddress = E .IpAddress (ip_address )
733+ nc .IsConnected = E .IsConnected (is_connected )
734+ if ip_address_mode is not None :
735+ nc .IpAddressAllocationMode = \
736+ E .IpAddressAllocationMode (ip_address_mode )
737+ if adapter_type is not None :
738+ nc .NetworkAdapterType = E .NetworkAdapterType (
739+ adapter_type )
740+ if is_primary :
741+ nic_index = nc .NetworkConnectionIndex
742+ break
743+
744+ if nic_not_found :
745+ raise EntityNotFoundException (
746+ 'Nic with name \' %s\' and index \' %s\' is not found in the VM \' %s\' ' %
747+ (network_name , nic_id , self .get_resource ().get ('name' )))
748+
749+ if is_primary :
750+ nic_index = int (nic_index .text )
751+ net_conn_section .PrimaryNetworkConnectionIndex = \
752+ E .PrimaryNetworkConnectionIndex (nic_index )
753+
754+ return self .client .put_linked_resource (
755+ net_conn_section , RelationType .EDIT ,
756+ EntityType .NETWORK_CONNECTION_SECTION .value , net_conn_section )
757+
701758 def delete_nic (self , index ):
702759 """Deletes a nic from the VM.
703760
@@ -1358,63 +1415,6 @@ def relocate(self, datastore_id):
13581415 EntityType .RELOCATE_PARAMS .value ,
13591416 relocate_params )
13601417
1361- def update_nic (self , network_name , nic_id = 0 ,
1362- is_connected = False ,
1363- is_primary = False ,
1364- ip_address_mode = None ,
1365- ip_address = None ,
1366- adapter_type = None ):
1367- """Updates a nic of the VM.
1368-
1369- :param str network_name: name of the network to be modified.
1370- :param bool is_connected: True, if the nic has to be connected.
1371- :param bool is_primary: True, if its a primary nic of the VM.
1372- :param str ip_address_mode: One of DHCP|POOL|MANUAL|NONE.
1373- :param str ip_address: to be set an ip in case of MANUAL mode.
1374- :param str adapter_type: nic adapter type.One of NetworkAdapterType
1375- values.
1376-
1377- :return: an object containing EntityType.TASK XML data which represents
1378- the asynchronous task adding a nic.
1379-
1380- :rtype: lxml.objectify.ObjectifiedElement
1381- """
1382- # get network connection section.
1383- net_conn_section = self .get_resource ().NetworkConnectionSection
1384- nic_index = 0
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 :
1405- raise EntityNotFoundException (
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' )))
1408-
1409- if is_primary :
1410- nic_index = int (nic_index .text )
1411- net_conn_section .PrimaryNetworkConnectionIndex = \
1412- E .PrimaryNetworkConnectionIndex (nic_index )
1413-
1414- return self .client .put_linked_resource (
1415- net_conn_section , RelationType .EDIT ,
1416- EntityType .NETWORK_CONNECTION_SECTION .value , net_conn_section )
1417-
14181418 def get_operating_system_section (self ):
14191419 """Get operating system section of VM.
14201420
0 commit comments