def _login(self):
        log = self.logger
        if self.username:
            log.debug('performing a new login')
            auth = '{0}:{1}'.format(self.username, self.password)
            auth = auth.encode('base64')
            headers = [('Authorization', 'Basic %s' % auth)]
            response = self._make_request('POST', '/login', headers=headers)
            # XXX: cookie hard-coded to be "JSESSIONID"
            cookies = response.getheader('Set-Cookie', '')
            for cookie in cookies.split(','):
                parts = [ part.strip() for part in cookie.split(';') ]
                if parts[0].startswith('JSESSIONID='):
                    self._cookie = parts[0]
                    log.debug('login: got JSESSIONID cookie')
                    break
            else:
                log.error('login: JSESSIONID cookie not found!')
                raise RavelloError('login failed')
        elif self.token:
            log.debug('logging in with token')
            self._cookie = self.token
            self.hello()  # Make sure the token works
            log.debug('token is valid')
        else:
            raise RuntimeError('cannot login: no username/password or token')
        # Also figure out the default project.
        if self._project is None:
            projects = self.get_projects()
            projects = sorted(projects, key=lambda pr: int(pr['id']))
            self._project = projects[0]['id']
Low-level login.
dataset/ETHPy150Open ravello/testmill/lib/testmill/ravello.py/RavelloClient._login