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_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(self, request, loadbalancer_id): """Get a specific load balancer. http://localhost/api/lbaas/loadbalancers/cc758c90-3d98-4ea1-af44-aab405c9c915 """ loadbalancer = neutronclient(request).show_loadbalancer( loadbalancer_id).get('loadbalancer') if request.GET.get('full') and network.floating_ip_supported(request): add_floating_ip_info(request, [loadbalancer]) return loadbalancer
def get(self, request): """List load balancers for current project. The listing result is an object with property "items". """ tenant_id = request.user.project_id loadbalancers = neutronclient(request).list_loadbalancers( tenant_id=tenant_id).get('loadbalancers') if request.GET.get('full') and network.floating_ip_supported(request): add_floating_ip_info(request, loadbalancers) return {'items': loadbalancers}
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 _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id, region=None): floating_ips = [] try: if network.floating_ip_supported(request): floating_ips = network.floating_ip_list(request, region=region, tenant_id=tenant_id) if tenant_id: floating_ips = filter(lambda fip: fip.tenant_id == tenant_id, floating_ips) except Exception: raise 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, region=region) 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, region=region) if tenant_id: subnets = filter(lambda subnet: subnet.tenant_id == tenant_id, subnets) usages.tally('subnets', len(subnets)) if 'router' not in disabled_quotas: routers = [] routers = neutron.router_list(request, region=region) if tenant_id: routers = filter(lambda rou: rou.tenant_id == tenant_id, routers) usages.tally('routers', len(routers)) if 'pool' not in disabled_quotas: pools = [] pools = lbaas.pool_list(request) if tenant_id: pools = filter(lambda p: p.tenant_id == tenant_id, pools) usages.tally('pool', len(pools))
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, 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): # 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 '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) usages.tally('networks', len(networks)) if 'router' not in disabled_quotas: routers = [] routers = neutron.router_list(request) usages.tally('routers', len(routers)) 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 allowed(self, request): return network.floating_ip_supported(request)
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 '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