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. In addition, when switching domains, you will
        be logged out of the current domain to close the connection pool associated
        with the previous session. This prevents potentially excessive open
        connections to SMC
        ::
        
            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:
            if self in self.manager: # Exit current domain
                self.logout()
            logger.info('Switching to domain: %r and creating new session', domain)
            params = self.copy()
            params.update(domain=domain)
            self.login(**params)