def _get_account_info(self, ksclient, tenants): endpoint = self._get_endpoint(ksclient) if not endpoint: raise StopIteration() for t in tenants: api_method = '%s_account' % self.METHOD yield (t.id, getattr(swift, api_method)(self._neaten_url( endpoint, t.id), keystone_client.get_auth_token(ksclient)))
def _get_ip_floating_sample_data(self, meter_name, parse_url, params, cache): parts = urlparse.ParseResult(params.get('scheme', ['http'])[0], parse_url.netloc, parse_url.path, None, None, None) endpoint = urlparse.urlunparse(parts) extractor = self._get_extractor(meter_name) if extractor is None: return data = self._prepare_cache(endpoint, params, cache) resp = data['n_client'].client.list_floatingips() floatingips = resp.get('floatingips') port_floatingip_map = \ dict((floatingip['port_id'], floatingip) for floatingip in \ floatingips if floatingip['port_id'] is not None and \ floatingip['floating_ip_address'] is not None) for port_id in port_floatingip_map: resp = data['n_client'].client.show_port(port_id) port_info = resp.get('port') if port_info is None or 'device_id' not in port_info: continue vm_fqdn_uuid = port_info['device_id'] vm_interfaces = \ data['o_client'].networks.get_vm_interfaces(vm_fqdn_uuid, token=keystone_client.get_auth_token(data['ks_client'])) if vm_interfaces is None: continue for vmi_fqdn_uuid in vm_interfaces: vmi_fip_stats = \ data['o_client'].networks.get_vmi_fip_stats(vmi_fqdn_uuid, token=keystone_client.get_auth_token(data['ks_client'])) if vmi_fip_stats is None: continue timestamp = timeutils.utcnow().isoformat() floatingip_info = port_floatingip_map[port_id] for sample in \ self._get_floatingip_sample(extractor, port_info, floatingip_info, vmi_fip_stats): if sample is not None: yield sample + (timestamp,)
def _get_account_info(self, ksclient, tenants): endpoint = self._get_endpoint(ksclient) if not endpoint: raise StopIteration() for t in tenants: api_method = '%s_account' % self.METHOD yield (t.id, getattr(swift, api_method) (self._neaten_url(endpoint, t.id), keystone_client.get_auth_token(ksclient)))
def _get_account_info(self, ksclient, tenants): endpoint = self._get_endpoint(self.conf, ksclient) if not endpoint: return swift_api_method = getattr(swift, '%s_account' % self.METHOD) for t in tenants: try: yield (t.id, swift_api_method( self._neaten_url(endpoint, t.id, self.conf.reseller_prefix), keystone_client.get_auth_token(ksclient))) except ClientException as e: if e.http_status == 404: LOG.warning("Swift tenant id %s not found.", t.id) else: raise e
def _get_account_info(self, ksclient, tenants): endpoint = self._get_endpoint(self.conf, ksclient) if not endpoint: raise StopIteration() swift_api_method = getattr(swift, '%s_account' % self.METHOD) for t in tenants: try: yield (t.id, swift_api_method( self._neaten_url(endpoint, t.id, self.conf.reseller_prefix), keystone_client.get_auth_token(ksclient))) except ClientException as e: if e.http_status == 404: LOG.warning("Swift tenant id %s not found.", t.id) else: raise e
def get_kwapi_client(ksclient, endpoint): """Returns a KwapiClient configured with the proper url and token.""" return KwapiClient(endpoint, keystone_client.get_auth_token(ksclient))