@@ -31,17 +31,16 @@ def __init__(self,
3131 self .port_group_configurer = port_group_configurer
3232 self .default_network = default_network
3333
34- def get_service_instance (self , vcenter_name ):
34+ def _get_service_instance (self , vcenter_name ):
3535 """
3636 Get vCenter connection
37- :param vcenter_name:
3837 :return: VmWare SI (Service Instance)
3938 """
40- connection_details = self .connection_retriever .connection_details (vcenter_name )
39+ connection_details = self .connection_retriever .connection_details ()
4140 si = self .pyvmomi_service .connect (connection_details .host ,
42- connection_details .username ,
43- connection_details .password ,
44- connection_details .port )
41+ connection_details .username ,
42+ connection_details .password ,
43+ connection_details .port )
4544 return si
4645
4746 def remove_vnic (self , vcenter_name , vm_uuid , network_name = None ):
@@ -53,27 +52,30 @@ def remove_vnic(self, vcenter_name, vm_uuid, network_name=None):
5352 :return:
5453 """
5554 _logger .debug (u"Revoking ALL Interfaces from VM '{}'..." .format (vm_uuid ))
56- si = self .get_service_instance (vcenter_name )
55+ si = self ._get_service_instance (vcenter_name )
5756 vm = self .pyvmomi_service .find_by_uuid (si , vm_uuid )
5857
59- condition = lambda device : VNicService .device_is_attached_to_network (device , network_name ) if network_name else lambda \
60- x : True
58+ condition = lambda device : VNicService .device_is_attached_to_network (device ,
59+ network_name ) if network_name else lambda \
60+ x : True
6161 return self .remove_interfaces_from_vm_task (vm , condition )
6262
63- def disconnect_all (self , vcenter_name , vm_uuid ):
63+ def disconnect_all (self , vcenter_name , vm_uuid , vm = None ):
6464 return self .disconnect (vcenter_name , vm_uuid , None )
6565
66- def disconnect (self , vcenter_name , vm_uuid , network_name = None ):
66+ def disconnect (self , vcenter_name , vm_uuid , network_name = None , vm = None ):
6767 """
6868 disconnect network adapter of the vm. If 'network_name' = None - disconnect ALL interfaces
6969 :param <str> vcenter_name: the name of the vCenter to connect to
7070 :param <str> vm_uuid: the uuid of the vm
7171 :param <str | None> network_name: the name of the specific network to disconnect
72+ :param <pyvmomi vm object> vm: If the vm obj is None will use vm_uuid to fetch the object
7273 :return: Started Task
7374 """
7475 _logger .debug (u"Disconnect Interface VM: '{}' Network: '{}' ..." .format (vm_uuid , network_name or "ALL" ))
75- si = self .get_service_instance (vcenter_name )
76- vm = self .pyvmomi_service .find_by_uuid (si , vm_uuid )
76+ si = self ._get_service_instance (vcenter_name )
77+ if vm is None :
78+ vm = self .pyvmomi_service .find_by_uuid (si , vm_uuid )
7779
7880 if network_name :
7981 network = self .pyvmomi_service .vm_get_network_by_name (vm , network_name )
0 commit comments