def _create_session(self): """Establish session with the server.""" 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) prev_session_id, self._session_id = 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)) # Terminate the previous session (if exists) for preserving sessions # as there is a limit on the number of sessions we can have. if prev_session_id: try: LOG.info(_LI("Terminating the previous session with ID = %s"), _trunc_id(prev_session_id)) self.vim.TerminateSession(session_manager, sessionId=[prev_session_id]) except Exception: # This exception is something we can live with. It is # just an extra caution on our side. The session might # have been cleared already. We could have made a call to # SessionIsActive, but that is an overhead because we # anyway would have to call TerminateSession. LOG.warn(_LW("Error occurred while terminating the previous " "session with ID = %s."), _trunc_id(prev_session_id), exc_info=True) # 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.""" 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) prev_session_id, self._session_id = 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)) # Terminate the previous session (if exists) for preserving sessions # as there is a limit on the number of sessions we can have. if prev_session_id: try: LOG.info(_LI("Terminating the previous session with ID = %s"), _trunc_id(prev_session_id)) self.vim.TerminateSession(session_manager, sessionId=[prev_session_id]) except Exception: # This exception is something we can live with. It is # just an extra caution on our side. The session might # have been cleared already. We could have made a call to # SessionIsActive, but that is an overhead because we # anyway would have to call TerminateSession. LOG.warn(_LW("Error occurred while terminating the previous " "session with ID = %s."), _trunc_id(prev_session_id), exc_info=True) # Set PBM client cookie. if self._pbm is not None: self._pbm.set_soap_cookie(self._vim.get_http_cookie())
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)