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