def verified_keystone(self): """Ensure keystone endpoints are valid and then authenticate :returns: Keystone Client """ try: # Ensure that user is admin client = self.keystone() roles = client.auth_ref['user']['roles'] if not any('admin' == role['name'] for role in roles): raise exceptions.InvalidAdminException( username=self.endpoint.username) except keystone_exceptions.Unauthorized: raise exceptions.InvalidEndpointsException() except keystone_exceptions.AuthorizationFailure: raise exceptions.HostUnreachableException( url=self.endpoint.auth_url) return client
def verified_keystone(self): """Ensure keystone endpoints are valid and then authenticate :returns: Keystone Client """ from keystoneclient import exceptions as keystone_exceptions try: # Ensure that user is admin if "admin" not in [role.lower() for role in self.keystone.auth_ref.role_names]: raise exceptions.InvalidAdminException( username=self.credential.username) except keystone_exceptions.Unauthorized: raise exceptions.InvalidEndpointsException() except keystone_exceptions.AuthorizationFailure: raise exceptions.HostUnreachableException( url=self.credential.auth_url) return self.keystone()
def verified_keystone(self): """Ensure keystone endpoints are valid and then authenticate :returns: Keystone Client """ try: # Ensure that user is admin client = self.keystone() if 'admin' not in [ role.lower() for role in client.auth_ref.role_names ]: raise exceptions.InvalidAdminException( username=self.endpoint.username) except keystone_exceptions.Unauthorized: raise exceptions.InvalidEndpointsException() except keystone_exceptions.AuthorizationFailure: raise exceptions.HostUnreachableException( url=self.endpoint.auth_url) return client