use already created vsphere connection

If we have connected to this host before, just reconnect.  If the host
is different than what is in the already configured connection, make
sure we are disconnected, and connect to the new one.

Fixes #31776

There is still a memory leak in this somewhere.
This commit is contained in:
Daniel Wallace 2016-03-09 15:06:24 -07:00
parent 26ff46dbc6
commit 070eaf07f0

View file

@ -86,7 +86,7 @@ import salt.utils
# Import Third Party Libs
try:
from pyVim.connect import SmartConnect, Disconnect
from pyVim.connect import GetSi, SmartConnect, Disconnect
from pyVmomi import vim, vmodl
HAS_PYVMOMI = True
except ImportError:
@ -184,6 +184,13 @@ def get_service_instance(host, username, password, protocol=None, port=None):
if port is None:
port = 443
service_instance = GetSi()
if service_instance:
if service_instance._GetStub().host == ':'.join([host, str(port)]):
service_instance._GetStub().GetConnection()
return service_instance
Disconnect(service_instance)
try:
service_instance = SmartConnect(
host=host,