def switch_domain(self, domain):
"""
Switch from one domain to another. You can call session.login() with a domain
key value to log directly into the domain of choice or alternatively switch
from domain to domain. The user must have permissions to the domain or
unauthorized will be returned.
::
session.login() # Log in to 'Shared Domain'
...
session.switch_domain('MyDomain')
:raises SMCConnectionError: Error logging in to specified domain.
This typically means the domain either doesn't exist or the
user does not have privileges to that domain.
"""
if self.domain != domain:
# Do we already have a session
if domain not in self._sessions:
logger.info('Creating session for domain: %s', domain)
credentials = self._get_login_params()
credentials.update(domain=domain)
self.login(**credentials)
else:
logger.info('Switching to existing domain session: %s', domain)
self._session = self._sessions.get(domain)
self._domain = domain
评论列表
文章目录