def populate_segment_choices(request): """Returns a list of segment info tuples for creating select options This creates the list based on current project :param request: request info - request.user.project_id :return: [(segment_obj, segment_display_string)] eg1. Has a segment name [{'segment_id':u'tenant_id', 'segment_name': u'segment_name'}, u'segment_name (segment_id)'] eg2. No segment name [{'segment_id':u'tenant_id', 'segment_name': u'segment_name'}, u'segment_name (segment_id)'] """ networks = osneutron.network_list(request, tenant_id=request.user.project_id, shared=False) segment_list = [] for network in networks: value = {'segment_id': network.id, 'segment_name': network.name} if network.name: # segment_name (segment_id) display = '%s (%s)' % (network.name, network.id) else: # (segment_id) display = '(%s)' % network.id segment_list.append((value, display)) if segment_list: segment_list.insert(0, ("", _("Select a Segment"))) else: segment_list.insert(0, ("", _("No segments available"))) return segment_list
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 neutron.floating_ip_supported(request): floating_ips = neutron.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 = neutron.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_networks_data(self): try: opts = self._get_search_opts() networks = neutron.network_list(self.tab_group.request, **opts) except Exception: networks = [] msg = _('Unable to get tenant network list.') exceptions.check_message(["Connection", "refused"], msg) raise if networks: self.exception = False tenant_dict = self._get_tenant_list() for n in networks: # Set tenant name tenant = tenant_dict.get(n.tenant_id, None) n.tenant_name = getattr(tenant, 'name', None) # If name is empty use UUID as name n.set_id_as_name_if_empty() # Get number of DHCP agents n.num_agents = self._get_agents_data(n.id) if self.exception: msg = _('Unable to list dhcp agents hosting network.') exceptions.handle(self.request, msg) return networks
def make_generated_parameters(self): wanted_generated_params = self.list_generated_parameters( with_prefix=False) # Generate keystone certificates generated_params = self._make_keystone_certificates( wanted_generated_params) # Generate passwords and control plane id for (key, param) in wanted_generated_params.items(): if _should_generate_password(param): generated_params[key] = password_generator() elif _should_generate_neutron_control_plane(param): generated_params[key] = neutron.network_list( self._request, name='ctlplane')[0].id # Fill all the Tuskar parameters with generated content. There are # parameters that has just different prefix, such parameters should # have the same values. wanted_prefixed_params = self.list_generated_parameters( with_prefix=True) tuskar_params = {} for (key, param) in wanted_prefixed_params.items(): tuskar_params[key] = generated_params[strip_prefix(key)] return tuskar_params
def get_share_networks_data(self): try: share_networks = manila.share_network_list( self.request, detailed=True, search_opts={'all_tenants': True}) if base.is_service_enabled(self.request, 'network'): neutron_net_names = dict((net.id, net.name) for net in neutron.network_list(self.request)) neutron_subnet_names = dict((net.id, net.name) for net in neutron.subnet_list(self.request)) for sn in share_networks: sn.neutron_net = neutron_net_names.get( sn.neutron_net_id) or sn.neutron_net_id or "-" sn.neutron_subnet = neutron_subnet_names.get( sn.neutron_subnet_id) or sn.neutron_subnet_id or "-" else: nova_net_names = dict( [(net.id, net.label) for net in network.network_list(self.request)]) for sn in share_networks: sn.nova_net = nova_net_names.get( sn.nova_net_id) or sn.nova_net_id or "-" except Exception: share_networks = [] exceptions.handle(self.request, _("Unable to retrieve share networks")) utils.set_project_name_to_objects(self.request, share_networks) return share_networks
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 neutron.floating_ip_supported(request): floating_ips = neutron.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 = neutron.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 make_generated_parameters(self): wanted_generated_params = self.list_generated_parameters( with_prefix=False) # Generate keystone certificates generated_params = self._make_keystone_certificates( wanted_generated_params) # Generate passwords and control plane id for (key, param) in wanted_generated_params.items(): if _should_generate_password(param): generated_params[key] = password_generator() elif _should_generate_neutron_control_plane(param): generated_params[key] = neutron.network_list( self._request, name='ctlplane')[0].id # Fill all the Tuskar parameters with generated content. There are # parameters that has just different prefix, such parameters should # have the same values. wanted_prefixed_params = self.list_generated_parameters( with_prefix=True) tuskar_params = {} for (key, param) in wanted_prefixed_params.items(): tuskar_params[key] = generated_params[strip_prefix(key)] return tuskar_params
def get_share_networks_data(self): try: share_networks = manila.share_network_list( self.request, detailed=True, search_opts={'all_tenants': True}) if base.is_service_enabled(self.request, 'network'): neutron_net_names = dict( (net.id, net.name) for net in neutron.network_list(self.request)) neutron_subnet_names = dict( (net.id, net.name) for net in neutron.subnet_list(self.request)) for sn in share_networks: sn.neutron_net = neutron_net_names.get( sn.neutron_net_id) or sn.neutron_net_id or "-" sn.neutron_subnet = neutron_subnet_names.get( sn.neutron_subnet_id) or sn.neutron_subnet_id or "-" else: nova_net_names = dict([ (net.id, net.label) for net in network.network_list(self.request) ]) for sn in share_networks: sn.nova_net = nova_net_names.get( sn.nova_net_id) or sn.nova_net_id or "-" except Exception: share_networks = [] exceptions.handle(self.request, _("Unable to retrieve share networks")) utils.set_tenant_name_to_objects(self.request, share_networks) return share_networks
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 populate_segment_choices(self, request): networks = osneutron.network_list(request, tenant_id=request.user.project_id, shared=False) segment_list = [(network.name, network.name) for network in networks] if segment_list: segment_list.insert(0, ("", _("Select a Segment"))) else: segment_list.insert(0, ("", _("No segments available"))) return segment_list
def get_networks_data(self): try: networks = neutron.network_list(self.request) except neutron_exc.ConnectionFailed: networks = [] exceptions.handle(self.request) except Exception: networks = [] exceptions.handle(self.request, _('Unable to retrieve networks.')) return networks
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 __init__(self, request, *args, **kwargs): super(CreateShareNetworkForm, self).__init__(request, *args, **kwargs) net_choices = neutron.network_list(request) subnet_choices = neutron.subnet_list(request) self.fields['neutron_net_id'].choices = [(' ', ' ')] + \ [(choice.id, choice.name_or_id) for choice in net_choices] self.fields['neutron_subnet_id'].choices = [(' ', ' ')] + \ [(choice.id, choice.name_or_id) for choice in subnet_choices] tenants, has_more = keystone.tenant_list(request) self.fields['project'].choices = [(' ', ' ')] + \ [(choice.id, choice.name) for choice in tenants]
def __init__(self, request, *args, **kwargs): super(Action, self).__init__(request, *args, **kwargs) params = api.tuskar.OvercloudPlan.template_parameters(request).items() params.sort() for name, data in params: # workaround for this parameter, which needs a preset taken from # neutron if name == 'NeutronControlPlaneID': networks = neutron.network_list(request) for network in networks: if network.name == 'ctlplane': data['Default'] = network.id break self.fields[name] = make_field(name, **data)
def __init__(self, request, *args, **kwargs): super(CreateShareNetworkForm, self).__init__( request, *args, **kwargs) net_choices = neutron.network_list(request) subnet_choices = neutron.subnet_list(request) self.fields['neutron_net_id'].choices = [(' ', ' ')] + \ [(choice.id, choice.name_or_id) for choice in net_choices] self.fields['neutron_subnet_id'].choices = [(' ', ' ')] + \ [(choice.id, choice.name_or_id) for choice in subnet_choices] tenants, has_more = keystone.tenant_list(request) self.fields['project'].choices = [(' ', ' ')] + \ [(choice.id, choice.name) for choice in tenants]
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_share_networks_data(self): try: share_networks = manila.share_network_list( self.request, detailed=True) if base.is_service_enabled(self.request, 'network'): neutron_net_names = dict((net.id, net.name) for net in neutron.network_list(self.request)) neutron_subnet_names = dict((net.id, net.name) for net in neutron.subnet_list(self.request)) for sn in share_networks: sn.neutron_net = neutron_net_names.get( sn.neutron_net_id) or sn.neutron_net_id or "-" sn.neutron_subnet = neutron_subnet_names.get( sn.neutron_subnet_id) or sn.neutron_subnet_id or "-" except Exception: share_networks = [] exceptions.handle( self.request, _("Unable to retrieve share networks")) return share_networks
def _get_networks(self, auto_network_name): """Gets the required networks :param request: The request object :param auto_network_name: The name of the autonetwork :return: The public, private and tenant's network """ public_network = None private_network = None network = None LOG.debug("Servers._get_networks()") networks = network_list(self.request) for net in networks: if net.name == "public": #TODO: add to settings public_network = net elif net.name == PRIVATE_NETWORK: private_network = net # check if the automatic network already exists elif self._does_automatic_network_exist(net, auto_network_name): network = net return public_network, private_network, network
def get_share_networks_data(self): try: share_networks = manila.share_network_list(self.request, detailed=True) if base.is_service_enabled(self.request, 'network'): neutron_net_names = dict( (net.id, net.name) for net in neutron.network_list(self.request)) neutron_subnet_names = dict( (net.id, net.name) for net in neutron.subnet_list(self.request)) for sn in share_networks: sn.neutron_net = neutron_net_names.get( sn.neutron_net_id) or sn.neutron_net_id or "-" sn.neutron_subnet = neutron_subnet_names.get( sn.neutron_subnet_id) or sn.neutron_subnet_id or "-" except Exception: share_networks = [] exceptions.handle(self.request, _("Unable to retrieve share networks")) return share_networks
def network_list(request): return neutron.network_list(request)
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 get(self, request): """List networks for current project. The listing result is an object with property "items". """ networks = neutron.network_list(request) return {'items': networks}
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 dispose_project(request, project_id): # TODO missing check for VMs, Volumes and images try: flow_step = 0 prj_subnets = set() for s_item in neutron_api.subnet_list(request, tenant_id=project_id, project_id=project_id ): prj_subnets.add(s_item.id) for r_item in neutron_api.router_list(request): for p_item in neutron_api.port_list(request, tenant_id=project_id, project_id=project_id, device_id=r_item.id ): for ip_item in p_item.fixed_ips: if ip_item.get('subnet_id') in prj_subnets: LOG.info('Removing port %s' % ip_item.get('ip_address')) #neutron_api.router_remove_interface(request, r_item.id, None, p_item.id) flow_step = 1 for s_item in prj_subnets: LOG.info('Removing subnet %s' % s_item) #neutron_api.subnet_delete(request, s_item) flow_step = 2 for n_item in neutron_api.network_list(request, tenant_id=project_id, project_id=project_id ): LOG.info('Removing network %s' % n_item.name) #neutron_api.network_delete(request, n_item.id) flow_step = 3 #TODO release FIPs except: if flow_step == 0: err_msg = _("Cannot remove router interfaces") elif flow_step == 1: err_msg = _("Cannot remove subnets") elif flow_step == 2: err_msg = _("Cannot remove networks") else: err_msg = _("Cannot release FIPs") LOG.error(err_msg, exc_info=True) messages.error(request, err_msg) try: for agg_item in nova_api.aggregate_details_list(request): if agg_item.metadata.get('filter_tenant_id', '') == project_id: for agg_host in agg_item.hosts: LOG.info('Removing host %s from %s' % (agg_host, agg_item.name)) #nova_api.remove_host_from_aggregate(request, # agg_item.id, # agg_host #) LOG.info('Removing aggregate %s' % agg_item.name) #nova_api.aggregate_delete(request, agg_item.id) except: err_msg = _("Cannot delete host aggregate") LOG.error(err_msg, exc_info=True) messages.error(request, err_msg) return True
def get_network_name_mapping(request, **params): networks = neutron.network_list(request, **params) return create_network_name_mapping(networks)
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 get(self, request): """List networks for current project. The listing result is an object with property "items". """ networks = neutron.network_list(request) return {'items': networks}