def format_context(self, context, lease_values): ctx = context.to_dict() region_name = CONF.os_region_name auth_url = base.url_for(ctx['service_catalog'], CONF.identity_service, os_region_name=region_name) return dict(user_id=lease_values['user_id'], project_id=lease_values['project_id'], auth_url=auth_url, region_name=region_name)
def __init__(self, **kwargs): """Description BlazarNovaClient can be used in two ways: from context or kwargs. :param version: service client version which we will use :type version: str :param ctx: request context :type ctx: context object :param auth_token: keystone auth token :type auth_token: str :param endpoint_override: endpoint url which we will use :type endpoint_override: str :param username: username to use with nova client :type username: str :param password: password to use with nova client :type password: str :param user_domain_name: domain name of the user :type user_domain_name: str :param project_name: project name to use with nova client :type project_name: str :param project_domain_name: domain name of the project :type project_domain_name: str :param auth_url: keystone url to authenticate against :type auth_url: str """ ctx = kwargs.pop('ctx', None) auth_token = kwargs.pop('auth_token', None) endpoint_override = kwargs.pop('endpoint_override', None) version = kwargs.pop('version', CONF.nova.nova_client_version) username = kwargs.pop('username', None) password = kwargs.pop('password', None) user_domain_name = kwargs.pop('user_domain_name', None) project_name = kwargs.pop('project_name', None) project_domain_name = kwargs.pop('project_domain_name', None) auth_url = kwargs.pop('auth_url', None) if ctx is None: try: ctx = context.current() except RuntimeError: pass if ctx is not None: auth_token = auth_token or ctx.auth_token endpoint_override = endpoint_override or \ base.url_for(ctx.service_catalog, CONF.nova.compute_service, os_region_name=CONF.os_region_name) auth_url = base.url_for(ctx.service_catalog, CONF.identity_service, os_region_name=CONF.os_region_name) kwargs.setdefault('global_request_id', ctx.global_request_id) if auth_url is None: auth_url = "%s://%s:%s" % (CONF.os_auth_protocol, base.get_os_auth_host(CONF), CONF.os_auth_port) if CONF.os_auth_prefix: auth_url += "/%s" % CONF.os_auth_prefix if username: kwargs.setdefault('username', username) kwargs.setdefault('password', password) kwargs.setdefault('project_name', project_name) kwargs.setdefault('auth_url', auth_url) if "v2.0" not in auth_url: kwargs.setdefault('project_domain_name', project_domain_name) kwargs.setdefault('user_domain_name', user_domain_name) else: auth = token_endpoint.Token(endpoint_override, auth_token) sess = session.Session(auth=auth) kwargs.setdefault('session', sess) kwargs.setdefault('endpoint_override', endpoint_override) kwargs.setdefault('version', version) self.nova = nova_client.Client(**kwargs) self.nova.servers = ServerManager(self.nova) self.exceptions = nova_exception
def __init__(self, **kwargs): """Description Return Keystone client for defined in 'identity_service' conf. NOTE: We will use tenant_name until we start using keystone V3 client for all our needs. :param version: service client version which we will use :type version: str :param username: username :type username: str :param password: password :type password: str :param tenant_name: tenant_name :type tenant_name: str :param auth_url: auth_url :type auth_url: str :param ctx: blazar context object :type ctx: dict :param auth_url: keystone auth url :type auth_url: string :param endpoint: keystone management (endpoint) url :type endpoint: string :param trust_id: keystone trust ID :type trust_id: string :param token: user token to use for authentication :type token: string """ ctx = kwargs.pop('ctx', None) if ctx is None: try: ctx = context.current() except RuntimeError: pass kwargs.setdefault('version', cfg.CONF.keystone_client_version) if ctx is not None: kwargs.setdefault('username', ctx.user_name) kwargs.setdefault('tenant_name', ctx.project_name) kwargs.setdefault('global_request_id', ctx.global_request_id) if not kwargs.get('auth_url'): kwargs['auth_url'] = base.url_for( ctx.service_catalog, CONF.identity_service, os_region_name=CONF.os_region_name) if not kwargs.get('trust_id'): try: kwargs.setdefault('endpoint', base.url_for( ctx.service_catalog, CONF.identity_service, endpoint_interface='admin', os_region_name=CONF.os_region_name)) except AttributeError: raise manager_exceptions.NoManagementUrl() if not kwargs.get('password'): kwargs.setdefault('token', ctx.auth_token) # NOTE(dbelova): we need this checking to support current # keystoneclient: token can only be scoped now to either # a trust or project, not both. if kwargs.get('trust_id') and kwargs.get('tenant_name'): kwargs.pop('tenant_name') try: # NOTE(n.s.): we shall remove this try: except: clause when # https://review.openstack.org/#/c/66494/ will be merged self.keystone = keystone_client.Client(**kwargs) self.keystone.session.auth = self.keystone auth_url = self.complement_auth_url(kwargs.get('auth_url', None), kwargs.get('version', None)) self.keystone.authenticate(auth_url=auth_url) except AttributeError: raise manager_exceptions.WrongClientVersion() self.exceptions = keystone_exception