def __init__(self, **kwargs): super(GnocchiCollector, self).__init__(**kwargs) adapter_options = {'connect_retries': 3} if CONF.collector_gnocchi.gnocchi_auth_type == 'keystone': auth_plugin = ks_loading.load_auth_from_conf_options( CONF, COLLECTOR_GNOCCHI_OPTS, ) adapter_options['interface'] = CONF.collector_gnocchi.interface else: auth_plugin = gauth.GnocchiBasicPlugin( user=CONF.collector_gnocchi.gnocchi_user, endpoint=CONF.collector_gnocchi.gnocchi_endpoint, ) adapter_options['region_name'] = CONF.collector_gnocchi.region_name verify = True if CONF.collector_gnocchi.cafile: verify = CONF.collector_gnocchi.cafile elif CONF.collector_gnocchi.insecure: verify = False self._conn = gclient.Client( '1', session=custom_session.create_custom_session( { 'auth': auth_plugin, 'verify': verify }, CONF.collector_gnocchi.http_pool_maxsize), adapter_options=adapter_options, )
def get_gnocchiclient(conf, endpoint_override=None): session = keystone_client.get_session(conf) return client.Client('1', session, interface=conf.service_credentials.interface, region_name=conf.service_credentials.region_name, endpoint_override=endpoint_override)
def get_gnocchiclient(conf): group = conf.dispatcher_gnocchi.auth_section session = keystone_client.get_session(conf, group=group) return client.Client('1', session, interface=conf[group].interface, region_name=conf[group].region_name)
def __init__(self, **kwargs): super(GnocchiStorage, self).__init__(**kwargs) conf = kwargs.get('conf') or ck_utils.load_conf( CONF.collect.metrics_conf) self.conf = validate_conf(conf) self.auth = ks_loading.load_auth_from_conf_options( CONF, GNOCCHI_STORAGE_OPTS) self.session = ks_loading.load_session_from_conf_options( CONF, GNOCCHI_STORAGE_OPTS, auth=self.auth) self._conn = gclient.Client( '1', session=self.session, adapter_options={'connect_retries': 3, 'interface': CONF.storage_gnocchi.interface}) self._archive_policy_name = ( CONF.storage_gnocchi.archive_policy_name) self._archive_policy_definition = json.loads( CONF.storage_gnocchi.archive_policy_definition) self._period = kwargs.get('period') or CONF.collect.period self._measurements = dict() self._resource_type_data = dict() self._init_resource_types()
def gnocchiclient(request): (username, domain_name, token_id, auth_url) = get_auth_params_from_request(request) auth = identity.Token(auth_url=auth_url, token=token_id, \ project_name=username, project_domain_name=domain_name) sess = session.Session(auth=auth) return gnocchi_client.Client(version='1', session=sess)
def __init__(self, conf): super(GnocchiBase, self).__init__(conf) self._gnocchi_client = client.Client( '1', keystone_client.get_session(conf), interface=conf.service_credentials.interface, region_name=conf.service_credentials.region_name)
def __init__(self): super(GnocchiFetcher, self).__init__() adapter_options = {'connect_retries': 3} if CONF.fetcher_gnocchi.gnocchi_auth_type == 'keystone': auth_plugin = ks_loading.load_auth_from_conf_options( CONF, FETCHER_GNOCCHI_OPTS, ) adapter_options['interface'] = CONF.fetcher_gnocchi.interface else: auth_plugin = gauth.GnocchiBasicPlugin( user=CONF.fetcher_gnocchi.gnocchi_user, endpoint=CONF.fetcher_gnocchi.gnocchi_endpoint, ) adapter_options['region_name'] = CONF.fetcher_gnocchi.region_name verify = True if CONF.fetcher_gnocchi.cafile: verify = CONF.fetcher_gnocchi.cafile elif CONF.fetcher_gnocchi.insecure: verify = False self._conn = gclient.Client( '1', session_options={ 'auth': auth_plugin, 'verify': verify }, adapter_options=adapter_options, )
def __init__(self, transformers, **kwargs): super(GnocchiCollector, self).__init__(transformers, **kwargs) adapter_options = {'connect_retries': 3} if CONF.gnocchi_collector.gnocchi_auth_type == 'keystone': auth_plugin = ks_loading.load_auth_from_conf_options( CONF, 'gnocchi_collector', ) adapter_options['interface'] = CONF.gnocchi_collector.interface else: auth_plugin = gauth.GnocchiBasicPlugin( user=CONF.gnocchi_collector.gnocchi_user, endpoint=CONF.gnocchi_collector.gnocchi_endpoint, ) adapter_options['region_name'] = CONF.gnocchi_collector.region_name verify = True if CONF.gnocchi_collector.cafile: verify = CONF.gnocchi_collector.cafile elif CONF.gnocchi_collector.insecure: verify = False self._conn = gclient.Client( '1', session_options={'auth': auth_plugin, 'verify': verify}, adapter_options=adapter_options, )
def __init__(self, conf): super(GnocchiBase, self).__init__(conf) self._gnocchi_client = client.Client( '1', keystone_client.get_session(conf), adapter_options={ 'interface': conf.service_credentials.interface, 'region_name': conf.service_credentials.region_name })
def validate_alarm(cls, alarm): super(AggregationMetricByResourcesLookupRule, cls).validate_alarm(alarm) rule = alarm.gnocchi_aggregation_by_resources_threshold_rule # check the query string is a valid json try: query = json.loads(rule.query) except ValueError: raise wsme.exc.InvalidInput('rule/query', rule.query) conf = pecan.request.cfg # Scope the alarm to the project id if needed auth_project = v2_utils.get_auth_project(alarm.project_id) if auth_project: perms_filter = {"=": {"created_by_project_id": auth_project}} external_project_owner = cls.get_external_project_owner() if external_project_owner: perms_filter = {"or": [ perms_filter, {"and": [ {"=": {"created_by_project_id": external_project_owner}}, {"=": {"project_id": auth_project}}]} ]} query = {"and": [perms_filter, query]} rule.query = json.dumps(query) gnocchi_client = client.Client( '1', keystone_client.get_session(conf), adapter_options={ 'interface': conf.service_credentials.interface, 'region_name': conf.service_credentials.region_name}) try: gnocchi_client.metric.aggregation( metrics=rule.metric, query=query, aggregation=rule.aggregation_method, needed_overlap=0, start="-1 day", stop="now", resource_type=rule.resource_type) except exceptions.ClientException as e: if e.code == 404: # NOTE(sileht): We are fine here, we just want to ensure the # 'query' payload is valid for Gnocchi If the metric # doesn't exists yet, it doesn't matter return raise base.ClientSideError(e.message, status_code=e.code) except Exception as e: raise GnocchiUnavailable(e)
def create_client(self, version=None, service_type=None): """Return gnocchi client.""" # NOTE(sumantmurke): gnocchiclient requires keystoneauth1 for # authenticating and creating a session. from gnocchiclient import client as gnocchi service_type = self.choose_service_type(service_type) sess = self._get_keystoneauth_session() gclient = gnocchi.Client(version=self.choose_version( version), session=sess, service_type=service_type) return gclient
def get_gnocchiclient(conf, endpoint_override=None): auth_plugin = ka_loading.load_auth_from_conf_options(conf, 'gnocchi') ks_session = ka_loading.load_session_from_conf_options(conf, 'gnocchi', auth=auth_plugin) return client.Client('1', ks_session, interface=conf.gnocchi.interface, region_name=conf.gnocchi.region_name, endpoint_override=endpoint_override)
def get_gnocchiclient(conf, timeout_override=False): group = conf.dispatcher_gnocchi.auth_section timeout = (None if (not conf.dispatcher_gnocchi.request_timeout or timeout_override) else conf.dispatcher_gnocchi.request_timeout) session = keystone_client.get_session(conf, group=group, timeout=timeout) return client.Client('1', session, interface=conf[group].interface, region_name=conf[group].region_name)
def __init__(self, transformers, **kwargs): super(GnocchiCollector, self).__init__(transformers, **kwargs) self.t_gnocchi = self.transformers['GnocchiTransformer'] self.t_cloudkitty = self.transformers['CloudKittyFormatTransformer'] self.auth = ks_loading.load_auth_from_conf_options( CONF, GNOCCHI_COLLECTOR_OPTS) self.session = ks_loading.load_session_from_conf_options( CONF, GNOCCHI_COLLECTOR_OPTS, auth=self.auth) self._conn = gclient.Client('1', session=self.session)
def _get_metric_client(self): adapter_options = { 'interface': 'public', 'region_name': self.conf.region } args = { 'session': self.identity_client.session, 'adapter_options': adapter_options } return gnocchi_client.Client(version=self.GNOCCHI_VERSION, **args)
def get_gnocchiclient(conf): requests_session = requests.session() for scheme in requests_session.adapters.keys(): requests_session.mount(scheme, ka_session.TCPKeepAliveAdapter( pool_block=True)) session = keystone_client.get_session(requests_session=requests_session) return client.Client('1', session, interface=conf.service_credentials.interface, region_name=conf.service_credentials.region_name, endpoint_override=conf.dispatcher_gnocchi.url)
def get_gnocchiclient(conf, request_timeout=None): group = conf.gnocchi.auth_section session = keystone_client.get_session(conf, group=group, timeout=request_timeout) adapter = keystoneauth1.session.TCPKeepAliveAdapter( pool_maxsize=conf.max_parallel_requests) session.mount("http://", adapter) session.mount("https://", adapter) return client.Client( '1', session, adapter_options={'connect_retries': 3, 'interface': conf[group].interface, 'region_name': conf[group].region_name})
def gnocchi(self): if self._gnocchi: return self._gnocchi gnocchiclient_version = self._get_client_option( 'gnocchi', 'api_version') gnocchiclient_interface = self._get_client_option( 'gnocchi', 'endpoint_type') self._gnocchi = gnclient.Client(gnocchiclient_version, interface=gnocchiclient_interface, session=self.session) return self._gnocchi
def config(self, config): conf = dict((c.key.lower(), c.values[0]) for c in config.children) auth_mode = conf.get('auth_mode', 'basic').lower() if auth_mode == 'keystone': authurl = conf.get("authurl") if authurl is None: raise RuntimeError( "Please specify `authurl` for Keystone auth_mode") kwargs = {} for arg in ("auth_url", "username", "user_id", "project_id", "project_name", "tenant_id", "tenant_name", "password", "user_domain_id", "user_domain_name", "project_domain_id", "project_domain_name"): if arg in conf: kwargs[arg] = conf.get(arg) auth = identity.Password(**kwargs) elif auth_mode == "basic": auth = gnocchiclient.auth.GnocchiBasicPlugin( conf.get("user", "admin"), conf.get("endpoint")) elif auth_mode == "noauth": auth = gnocchiclient.auth.GnocchiNoAuthPlugin( conf.get("userid", "admin"), conf.get("projectid", "admin"), conf.get("roles", "admin"), conf.get("endpoint")) else: raise RuntimeError("Unknown auth_mode `%s'" % auth_mode) s = session.Session(auth=auth) self.g = client.Client(1, s, interface=conf.get('interface'), region_name=conf.get('region_name'), endpoint_override=conf.get('endpoint')) self._resource_type = conf.get("resourcetype", "collectd") try: self.g.resource_type.get("collectd") except exceptions.ResourceTypeNotFound: self.g.resource_type.create({ "name": self._resource_type, "attributes": { "host": { "required": True, "type": "string", }, }, }) self.values = [] self.batch_size = conf.get("batchsize", 10)
def create_client(self, version=None, service_type=None): """Return gnocchi client.""" # NOTE(sumantmurke): gnocchiclient requires keystoneauth1 for # authenticating and creating a session. from gnocchiclient import client as gnocchi service_type = self.choose_service_type(service_type) sess = self.keystone.get_session()[0] gclient = gnocchi.Client( version=self.choose_version(version), session=sess, adapter_options={"service_type": service_type, "interface": self.credential.endpoint_type}) return gclient
def probe(self): try: session_options = dict(auth=self.auth_plugin) adapter_options = dict(interface=self.interface, region_name=self.region_name) gnocchi = client.Client(self.api_version, adapter_options=adapter_options, session_options=session_options) except Exception as e: self.exit_error('cannot get client: ' + str(e)) status = gnocchi.status.get() measures = status.get('storage', {}).get('summary', {}).get('measures') yield osnag.Metric('measures_to_process', measures)
def __init__(self, **kwargs): super(GnocchiStorage, self).__init__(**kwargs) self.auth = ks_loading.load_auth_from_conf_options( CONF, GNOCCHI_STORAGE_OPTS) self.session = ks_loading.load_session_from_conf_options( CONF, GNOCCHI_STORAGE_OPTS, auth=self.auth) self._conn = gclient.Client('1', session=self.session) self._measures = {} self._archive_policy_name = (CONF.storage_gnocchi.archive_policy_name) self._archive_policy_definition = json.loads( CONF.storage_gnocchi.archive_policy_definition) self._period = CONF.collect.period if "period" in kwargs: self._period = kwargs["period"]
def get_gnocchiclient(conf, timeout_override=False): group = conf.dispatcher_gnocchi.auth_section timeout = (None if (not conf.dispatcher_gnocchi.request_timeout or timeout_override) else conf.dispatcher_gnocchi.request_timeout) session = keystone_client.get_session(conf, group=group, timeout=timeout) adapter = keystoneauth1.session.TCPKeepAliveAdapter( pool_maxsize=conf.max_parallel_requests) session.mount("http://", adapter) session.mount("https://", adapter) return client.Client('1', session, interface=conf[group].interface, region_name=conf[group].region_name, adapter_options={'connect_retries': 3})
def _get_aggregation_methods(): conf = pecan.request.cfg gnocchi_client = client.Client( '1', keystone_client.get_session(conf), interface=conf.service_credentials.interface, region_name=conf.service_credentials.region_name) try: return gnocchi_client.capabilities.list().get( 'aggregation_methods', []) except exceptions.ClientException as e: raise base.ClientSideError(e.message, status_code=e.code) except Exception as e: raise GnocchiUnavailable(e)
def __init__(self): ks_loading.register_session_conf_options(CONF, "gnocchi_client") ks_loading.register_auth_conf_options(CONF, "gnocchi_client") self.auth = ks_loading.load_auth_from_conf_options( CONF, "gnocchi_client") self.session = ks_loading.load_session_from_conf_options( CONF, "gnocchi_client", auth=self.auth) self.gnocchi_client = gnocchi_client.Client( version='1', session=self.session, auth=self.auth)
def gnocchi(self): if self._gnocchi: return self._gnocchi gnocchiclient_version = self._get_client_option( 'gnocchi', 'api_version') gnocchiclient_interface = self._get_client_option( 'gnocchi', 'endpoint_type') adapter_options = {"interface": gnocchiclient_interface} self._gnocchi = gnclient.Client(gnocchiclient_version, adapter_options=adapter_options, session=self.session) return self._gnocchi
def create_gnocchi_client(auth_url, username, password, project_name, user_domain_name, project_domain_name): # TODO(kiennt): Working with Keystone V3, should add # check version here. loader = loading.get_plugin_loader('password') auth = loader.load_from_options(auth_url=auth_url, username=username, password=password, project_name=project_name, user_domain_name=user_domain_name, project_domain_name=project_domain_name) sess = session.Session(auth=auth) return client.Client('1', session=sess)
def gnocchiclient(request): """ Initialization of Gnocchi client. """ auth_endpoint = getattr(settings, 'OPENSTACK_KEYSTONE_URL', None) loader = loading.get_plugin_loader('token') auth = loader.load_from_options(auth_url=auth_endpoint, token=request.user.token.id, project_id=request.user.project_id) sess = session.Session(auth=auth) LOG.debug('gnocchiclient connection created using token "%s" ' 'and endpoint "%s"' % (request.user.token.id, auth_endpoint)) return gnocchi_client.Client('1', session=sess)
def validate_alarm(cls, alarm): super(MetricOfResourceRule, cls).validate_alarm(alarm) conf = pecan.request.cfg gnocchi_client = client.Client( '1', keystone_client.get_session(conf), interface=conf.service_credentials.interface, region_name=conf.service_credentials.region_name) rule = alarm.gnocchi_resources_threshold_rule try: gnocchi_client.resource.get(rule.resource_type, rule.resource_id) except exceptions.ClientException as e: raise base.ClientSideError(e.message, status_code=e.code) except Exception as e: raise GnocchiUnavailable(e)
def client(self): # NOTE(sileht): we lazy load the client to not # load/connect auth stuffs if self._client is None: if hasattr(self.options, "endpoint"): endpoint_override = self.options.endpoint else: endpoint_override = None auth_plugin = loading.load_auth_from_argparse_arguments( self.options) session = loading.load_session_from_argparse_arguments( self.options, auth=auth_plugin) self._client = client.Client(self.options.gnocchi_api_version, session=session, interface=self.options.interface, region_name=self.options.region_name, endpoint_override=endpoint_override) return self._client