@contextlib.contextmanager
def _get_xapi_session():
 _xenapi = _check_xenapi()
 xapi_uri = __salt__['config.option']('xapi.uri')
 xapi_login = __salt__['config.option']('xapi.login')
 xapi_password = __salt__['config.option']('xapi.password')
 if (not xapi_uri):
  xapi_uri = 'httpu:///var/run/xend/xen-api.sock'
 if (not xapi_login):
  xapi_login = ''
 if (not xapi_password):
  xapi_password = ''
 try:
  session = _xenapi.Session(xapi_uri)
  session.xenapi.login_with_password(xapi_login, xapi_password)
  (yield session.xenapi)
 except Exception:
  raise CommandExecutionError('Failed to connect to XenAPI socket.')
 finally:
  session.xenapi.session.logout()

@ contextlib . contextmanager def _get_xapi_session ( ) : _xenapi = _check_xenapi ( ) xapi_uri = __salt__ [ 'config.option' ] ( 'xapi.uri' ) xapi_login = __salt__ [ 'config.option' ] ( 'xapi.login' ) xapi_password = __salt__ [ 'config.option' ] ( 'xapi.password' ) if ( not xapi_uri ) : xapi_uri = 'httpu:///var/run/xend/xen-api.sock' if ( not xapi_login ) : xapi_login = '' if ( not xapi_password ) : xapi_password = '' try : session = _xenapi . Session ( xapi_uri ) session . xenapi . login_with_password ( xapi_login , xapi_password ) ( yield session . xenapi ) except Exception : raise CommandExecutionError ( 'Failed to connect to XenAPI socket.' ) finally : session . xenapi . session . logout ( )
get a session to xenapi .