def cgtsclient(context, version=1, endpoint=None): """Constructs a cgts client object for making API requests. :param context: The FM request context for auth. :param version: API endpoint version. :param endpoint: Optional If the endpoint is not available, it will be retrieved from session """ global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, config.sysinv_group.name) auth_token = context.auth_token if endpoint is None: auth = context.get_auth_plugin() service_type, service_name, interface = \ CONF.sysinv.catalog_info.split(':') service_parameters = { 'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.sysinv.os_region_name } endpoint = _SESSION.get_endpoint(auth, **service_parameters) return cgts_client.Client(version=version, endpoint=endpoint, token=auth_token)
def _get_cgtsclient(self): _ksclient = self._get_ksclient() token = _ksclient.auth_token return cgts_client_v1.Client( endpoint=self._get_cgts_url(), token=token, username=cfg.CONF.KEYSTONE_AUTHTOKEN.admin_user, password=cfg.CONF.KEYSTONE_AUTHTOKEN.admin_password, tenant_name=cfg.CONF.KEYSTONE_AUTHTOKEN.admin_tenant_name, auth_url=cfg.CONF.KEYSTONE_AUTHTOKEN.identity_uri + "v2.0")
def _get_primary_cgtsclient(self): # import the module in the function that uses it # as the cgtsclient is only installed on the controllers from cgtsclient.v1 import client as cgts_client # get region one name from platform.conf region1_name = get_region_name('region_1_name') if region1_name is None: region1_name = 'RegionOne' auth_ref = self._get_keystoneclient().auth_ref if auth_ref is None: raise exception.InventoryException( _("Unable to get auth ref from keystone client")) auth_token = auth_ref.service_catalog.get_token() endpoint = (auth_ref.service_catalog. get_endpoints(service_type='platform', endpoint_type='internal', region_name=region1_name)) endpoint = endpoint['platform'][0] version = 1 return cgts_client.Client(version=version, endpoint=endpoint['url'], auth_url=self.auth_url, token=auth_token['id'])