def get_floating_ips_data(self): try: floating_ips = network.tenant_floating_ip_list(self.request) except Exception: floating_ips = [] exceptions.handle(self.request, _('Unable to retrieve floating IP addresses.')) try: floating_ip_pools = network.floating_ip_pools_list(self.request) except Exception: floating_ip_pools = [] messages.warning(self.request, _('Unable to retrieve floating IP pools.')) pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools]) instances = [] try: instances, has_more = nova.server_list(self.request) except Exception: exceptions.handle(self.request, _('Unable to retrieve instance list.')) instances_dict = dict([(obj.id, obj) for obj in instances]) for ip in floating_ips: ip.instance_name = instances_dict[ip.instance_id].name \ if ip.instance_id in instances_dict else None ip.pool_name = pool_dict.get(ip.pool, ip.pool) return floating_ips
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id): enabled_quotas = ((NOVA_NETWORK_QUOTA_FIELDS | NEUTRON_QUOTA_FIELDS) - disabled_quotas) if not enabled_quotas: return # NOTE(amotoki): floatingip is Neutron quota and floating_ips is # Nova quota. We need to check both. if {'floatingip', 'floating_ips'} & enabled_quotas: floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.tenant_floating_ip_list(request) except Exception: pass usages.tally('floating_ips', len(floating_ips)) if 'security_group' not in disabled_quotas: security_groups = [] security_groups = network.security_group_list(request) usages.tally('security_groups', len(security_groups)) if 'network' not in disabled_quotas: networks = neutron.network_list(request, tenant_id=tenant_id) usages.tally('networks', len(networks)) if 'subnet' not in disabled_quotas: subnets = neutron.subnet_list(request, tenant_id=tenant_id) usages.tally('subnets', len(subnets)) if 'router' not in disabled_quotas: routers = neutron.router_list(request, tenant_id=tenant_id) usages.tally('routers', len(routers))
def get_floating_ips_data(self): try: floating_ips = network.tenant_floating_ip_list(self.request) except: floating_ips = [] exceptions.handle(self.request, _('Unable to retrieve floating IP addresses.')) try: floating_ip_pools = network.floating_ip_pools_list(self.request) except: floating_ip_pools = [] messages.warning(self.request, _('Unable to retrieve floating IP pools.')) pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools]) instances = [] try: instances, has_more = nova.server_list(self.request, all_tenants=True) except: exceptions.handle(self.request, _('Unable to retrieve instance list.')) instances_dict = dict([(obj.id, obj) for obj in instances]) for ip in floating_ips: ip.instance_name = instances_dict[ip.instance_id].name \ if ip.instance_id in instances_dict else None ip.pool_name = pool_dict.get(ip.pool, ip.pool) return floating_ips
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id): floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.tenant_floating_ip_list(request) except Exception: pass usages.tally('floating_ips', len(floating_ips)) if 'security_group' not in disabled_quotas: security_groups = [] security_groups = network.security_group_list(request) usages.tally('security_groups', len(security_groups)) if 'network' not in disabled_quotas: networks = [] networks = neutron.network_list(request, shared=False) if tenant_id: networks = filter(lambda net: net.tenant_id == tenant_id, networks) usages.tally('networks', len(networks)) if 'subnet' not in disabled_quotas: subnets = [] subnets = neutron.subnet_list(request) usages.tally('subnets', len(subnets)) if 'router' not in disabled_quotas: routers = [] routers = neutron.router_list(request) if tenant_id: routers = filter(lambda rou: rou.tenant_id == tenant_id, routers) usages.tally('routers', len(routers))
def get_initial(self): self.domain = self.get_domain() results = {'domain_id': self.domain.id, 'domain_name': self.domain.name, } if limit_records_to_fips(): results.update({'fips': tenant_floating_ip_list(self.request), 'instances': server_list(self.request)[0]}) return results
def get_initial(self): self.domain = self.get_domain() results = { 'domain_id': self.domain.id, 'domain_name': self.domain.name, } if limit_records_to_fips(): results.update({ 'fips': tenant_floating_ip_list(self.request), 'instances': server_list(self.request)[0] }) return results
def tenant_quota_usages(request): # Get our quotas and construct our usage object. disabled_quotas = get_disabled_quotas(request) usages = QuotaUsage() for quota in get_tenant_quota_data(request, disabled_quotas=disabled_quotas): usages.add_quota(quota) # Get our usages. floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.tenant_floating_ip_list(request) except Exception: pass flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. missing_flavors = [ instance.flavor['id'] for instance in instances if instance.flavor['id'] not in flavors ] for missing in missing_flavors: if missing not in flavors: try: flavors[missing] = nova.flavor_get(request, missing) except Exception: flavors[missing] = {} exceptions.handle(request, ignore=True) usages.tally('instances', len(instances)) usages.tally('floating_ips', len(floating_ips)) if 'volumes' not in disabled_quotas: volumes = cinder.volume_list(request) snapshots = cinder.volume_snapshot_list(request) usages.tally('gigabytes', sum([int(v.size) for v in volumes])) usages.tally('volumes', len(volumes)) usages.tally('snapshots', len(snapshots)) # Sum our usage based on the flavors of the instances. for flavor in [flavors[instance.flavor['id']] for instance in instances]: usages.tally('cores', getattr(flavor, 'vcpus', None)) usages.tally('ram', getattr(flavor, 'ram', None)) # Initialise the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0) return usages
def add_floating_ip_info(request, loadbalancers): """Add floating IP address info to each load balancer. """ floating_ips = network.tenant_floating_ip_list(request) for lb in loadbalancers: floating_ip = {} associated_ip = next((fip for fip in floating_ips if fip['fixed_ip'] == lb['vip_address']), None) if associated_ip is not None: floating_ip['id'] = associated_ip['id'] floating_ip['ip'] = associated_ip['ip'] lb['floating_ip'] = floating_ip
def tenant_quota_usages(request): # Get our quotas and construct our usage object. disabled_quotas = get_disabled_quotas(request) usages = QuotaUsage() for quota in get_tenant_quota_data( request, disabled_quotas=disabled_quotas): usages.add_quota(quota) # Get our usages. try: floating_ips = network.tenant_floating_ip_list(request) except neutronclient.NeutronClientException: floating_ips = [] flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. missing_flavors = [ instance.flavor['id'] for instance in instances if instance.flavor['id'] not in flavors ] for missing in missing_flavors: if missing not in flavors: try: flavors[missing] = nova.flavor_get(request, missing) except Exception: flavors[missing] = {} exceptions.handle(request, ignore=True) usages.tally('instances', len(instances)) usages.tally('floating_ips', len(floating_ips)) if 'volumes' not in disabled_quotas: volumes = cinder.volume_list(request) snapshots = cinder.volume_snapshot_list(request) usages.tally('gigabytes', sum([int(v.size) for v in volumes])) usages.tally('volumes', len(volumes)) usages.tally('snapshots', len(snapshots)) # Sum our usage based on the flavors of the instances. for flavor in [flavors[instance.flavor['id']] for instance in instances]: usages.tally('cores', getattr(flavor, 'vcpus', None)) usages.tally('ram', getattr(flavor, 'ram', None)) # Initialise the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0) return usages
def add_floating_ip_info(request, loadbalancers): """Add floating IP address info to each load balancer. """ floating_ips = network.tenant_floating_ip_list(request) for lb in loadbalancers: floating_ip = {} associated_ip = next( (fip for fip in floating_ips if fip['fixed_ip'] == lb['vip_address']), None) if associated_ip is not None: floating_ip['id'] = associated_ip['id'] floating_ip['ip'] = associated_ip['ip'] lb['floating_ip'] = floating_ip
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id): floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.tenant_floating_ip_list(request) except Exception: pass usages.tally('floating_ips', len(floating_ips)) if 'security_group' not in disabled_quotas: security_groups = [] security_groups = network.security_group_list(request) usages.tally('security_groups', len(security_groups)) if 'network' not in disabled_quotas: networks = [] networks = neutron.network_list(request, shared=False) if tenant_id: networks = [net for net in networks if net.tenant_id == tenant_id] usages.tally('networks', len(networks)) # get shared networks shared_networks = neutron.network_list(request, shared=True) if tenant_id: shared_networks = [ net for net in shared_networks if net.tenant_id == tenant_id ] usages.tally('networks', len(shared_networks)) if 'subnet' not in disabled_quotas: subnets = neutron.subnet_list(request, shared=False) if tenant_id: subnets = [sub for sub in subnets if sub.tenant_id == tenant_id] # get shared subnets shared_subnets = neutron.subnet_list(request, shared=True) if tenant_id: shared_subnets = [ subnet for subnet in shared_subnets if subnet.tenant_id == tenant_id ] usages.tally('subnets', len(subnets) + len(shared_subnets)) if 'router' not in disabled_quotas: routers = [] routers = neutron.router_list(request) if tenant_id: routers = [rou for rou in routers if rou.tenant_id == tenant_id] usages.tally('routers', len(routers))
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id): floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.tenant_floating_ip_list(request) except Exception: pass usages.tally('floating_ips', len(floating_ips)) if 'security_group' not in disabled_quotas: security_groups = [] security_groups = network.security_group_list(request) usages.tally('security_groups', len(security_groups)) if 'network' not in disabled_quotas: networks = [] networks = neutron.network_list(request, shared=False) if tenant_id: networks = [net for net in networks if net.tenant_id == tenant_id] usages.tally('networks', len(networks)) # get shared networks shared_networks = neutron.network_list(request, shared=True) if tenant_id: shared_networks = [net for net in shared_networks if net.tenant_id == tenant_id] usages.tally('networks', len(shared_networks)) if 'subnet' not in disabled_quotas: subnets = neutron.subnet_list(request, shared=False) if tenant_id: subnets = [sub for sub in subnets if sub.tenant_id == tenant_id] # get shared subnets shared_subnets = neutron.subnet_list(request, shared=True) if tenant_id: shared_subnets = [subnet for subnet in shared_subnets if subnet.tenant_id == tenant_id] usages.tally('subnets', len(subnets) + len(shared_subnets)) if 'router' not in disabled_quotas: routers = [] routers = neutron.router_list(request) if tenant_id: routers = [rou for rou in routers if rou.tenant_id == tenant_id] usages.tally('routers', len(routers))
def tenant_quota_usages(request): # Get our quotas and construct our usage object. disabled_quotas = [] if not is_service_enabled(request, "volume"): disabled_quotas.extend(["volumes", "gigabytes"]) usages = QuotaUsage() for quota in get_tenant_quota_data(request, disabled_quotas): usages.add_quota(quota) # Get our usages. floating_ips = network.tenant_floating_ip_list(request) flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) instances = nova.server_list(request) # Fetch deleted flavors if necessary. missing_flavors = [instance.flavor["id"] for instance in instances if instance.flavor["id"] not in flavors] for missing in missing_flavors: if missing not in flavors: try: flavors[missing] = nova.flavor_get(request, missing) except: flavors[missing] = {} exceptions.handle(request, ignore=True) usages.tally("instances", len(instances)) usages.tally("floating_ips", len(floating_ips)) if "volumes" not in disabled_quotas: volumes = cinder.volume_list(request) usages.tally("gigabytes", sum([int(v.size) for v in volumes])) usages.tally("volumes", len(volumes)) # Sum our usage based on the flavors of the instances. for flavor in [flavors[instance.flavor["id"]] for instance in instances]: usages.tally("cores", getattr(flavor, "vcpus", None)) usages.tally("ram", getattr(flavor, "ram", None)) # Initialise the tally if no instances have been launched yet if len(instances) == 0: usages.tally("cores", 0) usages.tally("ram", 0) return usages
def get_floating_ips_data(self): try: floating_ips = network.tenant_floating_ip_list(self.request) except neutron_exc.ConnectionFailed: floating_ips = [] exceptions.handle(self.request) except Exception: floating_ips = [] exceptions.handle(self.request, _('Unable to retrieve floating IP addresses.')) try: floating_ip_pools = network.floating_ip_pools_list(self.request) except neutron_exc.ConnectionFailed: floating_ip_pools = [] exceptions.handle(self.request) except Exception: floating_ip_pools = [] exceptions.handle(self.request, _('Unable to retrieve floating IP pools.')) pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools]) attached_instance_ids = [ ip.instance_id for ip in floating_ips if ip.instance_id is not None ] if attached_instance_ids: instances = [] try: # TODO(tsufiev): we should pass attached_instance_ids to # nova.server_list as soon as Nova API allows for this instances, has_more = nova.server_list(self.request) except Exception: exceptions.handle(self.request, _('Unable to retrieve instance list.')) instances_dict = dict([(obj.id, obj.name) for obj in instances]) for ip in floating_ips: ip.instance_name = instances_dict.get(ip.instance_id) ip.pool_name = pool_dict.get(ip.pool, ip.pool) return floating_ips
def get_floating_ips_data(self): try: floating_ips = network.tenant_floating_ip_list(self.request) except neutron_exc.ConnectionFailed: floating_ips = [] exceptions.handle(self.request) except Exception: floating_ips = [] exceptions.handle(self.request, _('Unable to retrieve floating IP addresses.')) try: floating_ip_pools = network.floating_ip_pools_list(self.request) except neutron_exc.ConnectionFailed: floating_ip_pools = [] exceptions.handle(self.request) except Exception: floating_ip_pools = [] exceptions.handle(self.request, _('Unable to retrieve floating IP pools.')) pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools]) attached_instance_ids = [ip.instance_id for ip in floating_ips if ip.instance_id is not None] if attached_instance_ids: instances = [] try: # TODO(tsufiev): we should pass attached_instance_ids to # nova.server_list as soon as Nova API allows for this instances, has_more = nova.server_list(self.request) except Exception: exceptions.handle(self.request, _('Unable to retrieve instance list.')) instances_dict = dict([(obj.id, obj.name) for obj in instances]) for ip in floating_ips: ip.instance_name = instances_dict.get(ip.instance_id) ip.pool_name = pool_dict.get(ip.pool, ip.pool) return floating_ips
def get_floating_ips_data(self): try: floating_ips = network.tenant_floating_ip_list(self.request) except neutron_exc.ConnectionFailed: floating_ips = [] exceptions.handle(self.request) except Exception: floating_ips = [] exceptions.handle(self.request, _('Unable to retrieve floating IP addresses.')) try: floating_ip_pools = network.floating_ip_pools_list(self.request) except neutron_exc.ConnectionFailed: floating_ip_pools = [] exceptions.handle(self.request) except Exception: floating_ip_pools = [] exceptions.handle(self.request, _('Unable to retrieve floating IP pools.')) pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools]) instances = [] try: instances, has_more = nova.server_list(self.request) except Exception: exceptions.handle(self.request, _('Unable to retrieve instance list.')) instances_dict = dict([(obj.id, obj.name) for obj in instances]) for ip in floating_ips: ip.instance_name = instances_dict.get(ip.instance_id) ip.pool_name = pool_dict.get(ip.pool, ip.pool) return floating_ips
def tenant_quota_usages(request, tenant_id=None): """Get our quotas and construct our usage object. If no tenant_id is provided, a the request.user.project_id is assumed to be used """ if not tenant_id: tenant_id = request.user.project_id disabled_quotas = get_disabled_quotas(request) usages = QuotaUsage() for quota in get_tenant_quota_data(request, disabled_quotas=disabled_quotas, tenant_id=tenant_id): usages.add_quota(quota) # Get our usages. floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.tenant_floating_ip_list(request) except Exception: pass flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) if tenant_id: instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}, all_tenants=True) else: instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. missing_flavors = [instance.flavor['id'] for instance in instances if instance.flavor['id'] not in flavors] for missing in missing_flavors: if missing not in flavors: try: flavors[missing] = nova.flavor_get(request, missing) except Exception: flavors[missing] = {} exceptions.handle(request, ignore=True) usages.tally('instances', len(instances)) usages.tally('floating_ips', len(floating_ips)) if 'security_group' not in disabled_quotas: security_groups = [] security_groups = network.security_group_list(request) usages.tally('security_groups', len(security_groups)) if 'network' not in disabled_quotas: networks = [] networks = neutron.network_list(request, shared=False) if tenant_id: networks = filter(lambda net: net.tenant_id == tenant_id, networks) usages.tally('networks', len(networks)) if 'subnet' not in disabled_quotas: subnets = [] subnets = neutron.subnet_list(request) usages.tally('subnets', len(subnets)) if 'router' not in disabled_quotas: routers = [] routers = neutron.router_list(request) if tenant_id: routers = filter(lambda rou: rou.tenant_id == tenant_id, routers) usages.tally('routers', len(routers)) if 'volumes' not in disabled_quotas: if tenant_id: opts = {'alltenants': 1, 'tenant_id': tenant_id} volumes = cinder.volume_list(request, opts) snapshots = cinder.volume_snapshot_list(request, opts) else: volumes = cinder.volume_list(request) snapshots = cinder.volume_snapshot_list(request) usages.tally('gigabytes', sum([int(v.size) for v in volumes])) usages.tally('volumes', len(volumes)) usages.tally('snapshots', len(snapshots)) # Sum our usage based on the flavors of the instances. for flavor in [flavors[instance.flavor['id']] for instance in instances]: usages.tally('cores', getattr(flavor, 'vcpus', None)) usages.tally('ram', getattr(flavor, 'ram', None)) # Initialise the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0) return usages
def tenant_quota_usages(request, tenant_id=None): """Get our quotas and construct our usage object.""" disabled_quotas = get_disabled_quotas(request) usages = QuotaUsage() for quota in get_tenant_quota_data(request, disabled_quotas=disabled_quotas, tenant_id=tenant_id): usages.add_quota(quota) # Get our usages. floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.tenant_floating_ip_list(request) except Exception: pass flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) if tenant_id: instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}, all_tenants=True) else: instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. missing_flavors = [instance.flavor['id'] for instance in instances if instance.flavor['id'] not in flavors] for missing in missing_flavors: if missing not in flavors: try: flavors[missing] = nova.flavor_get(request, missing) except Exception: flavors[missing] = {} exceptions.handle(request, ignore=True) usages.tally('instances', len(instances)) usages.tally('floating_ips', len(floating_ips)) if 'security_group' not in disabled_quotas: security_groups = [] security_groups = network.security_group_list(request) usages.tally('security_groups', len(security_groups)) if 'network' not in disabled_quotas: networks = [] networks = neutron.network_list(request, shared=False) if tenant_id: networks = filter(lambda net: net.tenant_id == tenant_id, networks) usages.tally('networks', len(networks)) if 'router' not in disabled_quotas: routers = [] routers = neutron.router_list(request) if tenant_id: routers = filter(lambda rou: rou.tenant_id == tenant_id, routers) usages.tally('routers', len(routers)) if 'volumes' not in disabled_quotas: if tenant_id: opts = {'alltenants': 1, 'tenant_id': tenant_id} volumes = cinder.volume_list(request, opts) snapshots = cinder.volume_snapshot_list(request, opts) else: volumes = cinder.volume_list(request) snapshots = cinder.volume_snapshot_list(request) usages.tally('gigabytes', sum([int(v.size) for v in volumes])) usages.tally('volumes', len(volumes)) usages.tally('snapshots', len(snapshots)) # Sum our usage based on the flavors of the instances. for flavor in [flavors[instance.flavor['id']] for instance in instances]: usages.tally('cores', getattr(flavor, 'vcpus', None)) usages.tally('ram', getattr(flavor, 'ram', None)) # Initialise the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0) return usages
def tenant_quota_usages(request): # Get our quotas and construct our usage object. disabled_quotas = get_disabled_quotas(request) usages = QuotaUsage() for quota in get_tenant_quota_data(request, disabled_quotas=disabled_quotas): usages.add_quota(quota) # Get our usages. floating_ips = network.tenant_floating_ip_list(request) flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) instances = nova.server_list(request) # Fetch deleted flavors if necessary. missing_flavors = [instance.flavor['id'] for instance in instances if instance.flavor['id'] not in flavors] for missing in missing_flavors: if missing not in flavors: try: flavors[missing] = nova.flavor_get(request, missing) except: flavors[missing] = {} exceptions.handle(request, ignore=True) # jt project_id = request.user.tenant_id resources = api.jt.get_used_resources(project_id) floating_ips = resources.get('floating_ips', 0) instances = resources.get('instances', 0) cores = resources.get('cores', 0) ram = resources.get('ram', 0) gigabytes = resources.get('gigabytes', 0) volumes = resources.get('volumes', 0) # jt #usages.tally('instances', len(instances)) #usages.tally('floating_ips', len(floating_ips)) usages.tally('instances', instances) usages.tally('floating_ips', floating_ips) usages.tally('cores', cores) usages.tally('ram', ram) if 'volumes' not in disabled_quotas: # jt #volumes = cinder.volume_list(request) #usages.tally('gigabytes', sum([int(v.size) for v in volumes])) #usages.tally('volumes', len(volumes)) usages.tally('gigabytes', gigabytes) usages.tally('volumes', volumes) # jt # Sum our usage based on the flavors of the instances. #for flavor in [flavors[instance.flavor['id']] for instance in instances]: #usages.tally('cores', getattr(flavor, 'vcpus', None)) #usages.tally('ram', getattr(flavor, 'ram', None)) # jt # Initialise the tally if no instances have been launched yet if instances == 0: #if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0) # Images owned_image_count = api.jt.get_image_count(project_id, request) image_limit = api.jt.get_image_quota(project_id) usages['images']['quota'] = image_limit usages['images']['used'] = owned_image_count usages['images']['available'] = image_limit - owned_image_count # Expiration expiration_date = api.jt.get_expiration_date(project_id) usages['expiration']['quota'] = -1 usages['expiration']['used'] = 0 usages['expiration']['available'] = 0 usages['expiration']['expiration_date'] = expiration_date # Start Date start_date = api.jt.get_start_date(project_id) usages['start']['quota'] = -1 usages['start']['used'] = 0 usages['start']['available'] = 0 usages['start']['start_date'] = start_date # DAIR Notice dair_notice = api.jt.get_dair_notice(project_id) usages['dair_notice']['quota'] = -1 usages['dair_notice']['used'] = 0 usages['dair_notice']['available'] = 0 usages['dair_notice']['dair_notice'] = dair_notice # Object Storage object_mb_usage = api.jt.get_object_mb_usage(project_id) object_mb_limit = api.jt.get_object_mb_quota(project_id) usages['object_mb']['quota'] = object_mb_limit usages['object_mb']['used'] = object_mb_usage usages['object_mb']['available'] = object_mb_limit - object_mb_usage return usages