- self._auth_token = None
- self._ks = None
- self.openstack_url = None
- self.user = None
- self.password = None
- self.tenant = None
-
- def _authenticate(self, message=None):
- """Authenticate and/or renew the authentication token."""
- if self._auth_token is not None:
- return self._auth_token
-
- if message is not None:
- values = json.loads(message.value)['access_config']
- self.openstack_url = values['openstack_site']
- self.user = values['user']
- self.password = values['password']
- self.tenant = values['vim_tenant_name']
-
- try:
- # try to authenticate with supplied access_credentials
- self._ks = client.Client(auth_url=self.openstack_url,
- username=self.user,
- password=self.password,
- tenant_name=self.tenant)
- self._auth_token = self._ks.auth_token
- log.info("Authenticating with access_credentials from SO.")
- return self._auth_token
- except Exception as exc:
- log.warn("Authentication failed with access_credentials: %s",
- exc)