def _create_session(self): """Establish session with the server.""" # Another thread might have created the session while the current one # was waiting for the lock. if self._session_id and self.is_current_session_active(): LOG.debug("Current session: %s is active.", _trunc_id(self._session_id)) return session_manager = self.vim.service_content.sessionManager # Login and create new session with the server for making API calls. LOG.debug("Logging into host: %s.", self._host) session = self.vim.Login(session_manager, userName=self._server_username, password=self._server_password) self._session_id = session.key # We need to save the username in the session since we may need it # later to check active session. The SessionIsActive method requires # the username parameter to be exactly same as that in the session # object. We can't use the username used for login since the Login # method ignores the case. self._session_username = session.userName LOG.info(_LI("Successfully established new session; session ID is " "%s."), _trunc_id(self._session_id)) # Set PBM client cookie. if self._pbm is not None: self._pbm.set_soap_cookie(self._vim.get_http_cookie())
def _create_session(self): """Establish session with the server.""" # Another thread might have created the session while the current one # was waiting for the lock. if self._session_id and self.is_current_session_active(): LOG.debug("Current session: %s is active.", _trunc_id(self._session_id)) return session_manager = self.vim.service_content.sessionManager # Login and create new session with the server for making API calls. LOG.debug("Logging in with username = %s.", self._server_username) session = self.vim.Login(session_manager, userName=self._server_username, password=self._server_password) self._session_id = session.key # We need to save the username in the session since we may need it # later to check active session. The SessionIsActive method requires # the username parameter to be exactly same as that in the session # object. We can't use the username used for login since the Login # method ignores the case. self._session_username = session.userName LOG.info( _LI("Successfully established new session; session ID is " "%s."), _trunc_id(self._session_id)) # Set PBM client cookie. if self._pbm is not None: self._pbm.set_soap_cookie(self._vim.get_http_cookie())
def _client_request(self, client, method, uri, params, headers, encode_params): retries = max(self.retries, 1) delay = 0.5 for attempt in range(1, retries + 1): if attempt != 1: time.sleep(delay) delay = min(2 * delay, 60) try: return client(method, uri, params, headers, encode_params) except exceptions.ServiceConflict as e: if attempt == retries: raise e LOG.info(_LI('NSXv: conflict on request. Trying again.'))
def logout(self): """Log out and terminate the current session.""" if self._session_id: LOG.info(_LI("Logging out and terminating the current session " "with ID = %s."), _trunc_id(self._session_id)) try: self.vim.Logout(self.vim.service_content.sessionManager) self._session_id = None except Exception: LOG.exception(_LE("Error occurred while logging out and " "terminating the current session with " "ID = %s."), _trunc_id(self._session_id)) else: LOG.debug("No session exists to log out.")
def logout(self): """Log out and terminate the current session.""" if self._session_id: LOG.info( _LI("Logging out and terminating the current session " "with ID = %s."), _trunc_id(self._session_id)) try: self.vim.Logout(self.vim.service_content.sessionManager) self._session_id = None except Exception: LOG.exception( _LE("Error occurred while logging out and " "terminating the current session with " "ID = %s."), _trunc_id(self._session_id)) else: LOG.debug("No session exists to log out.")
def pbm_wsdl_loc_set(self, pbm_wsdl_loc): self._pbm_wsdl_loc = pbm_wsdl_loc self._pbm = None LOG.info(_LI('PBM WSDL updated to %s'), pbm_wsdl_loc)