예제 #1
0
def _vpnservice_list(request,
                     expand_subnet=False,
                     expand_router=False,
                     expand_conns=False,
                     **kwargs):
    vpnservices = neutronclient(request).list_vpnservices(
        **kwargs).get('vpnservices')
    if expand_subnet:
        subnets = neutron.subnet_list(request)
        subnet_dict = SortedDict((s.id, s) for s in subnets)
        for s in vpnservices:
            s['subnet_name'] = subnet_dict.get(s['subnet_id']).cidr
    if expand_router:
        routers = neutron.router_list(request)
        router_dict = SortedDict((r.id, r) for r in routers)
        for s in vpnservices:
            s['router_name'] = router_dict.get(s['router_id']).name_or_id
    if expand_conns:
        ipsecsiteconns = _ipsecsiteconnection_list(request, **kwargs)
        sslvpnconns = _sslvpnconnection_list(request, **kwargs)
        for s in vpnservices:
            s['ipsecsiteconns'] = [
                c.id for c in ipsecsiteconns if c.vpnservice_id == s['id']
            ]
            s['sslvpnconns'] = [
                c.id for c in sslvpnconns if c.vpnservice_id == s['id']
            ]
    return [VPNService(v) for v in vpnservices]
예제 #2
0
def get_avail_networks(request):

    unit_table = getattr(settings, 'UNIT_TABLE', {})

    used_nets = dict()
    for subdict in neutron_api.subnet_list(request):
        cidr_match = CIDR_PATTERN.search(subdict['cidr'])
        if not cidr_match:
            continue
        if not cidr_match.group(1) in used_nets:
            used_nets[cidr_match.group(1)] = list()
        used_nets[cidr_match.group(1)].append(int(cidr_match.group(2)))

    avail_nets = dict()

    for unit_id, unit_data in unit_table.items():

        result = list()

        used_ipprefs = used_nets.get(unit_data['lan_net_pool'], [])
        max_avail = max(used_ipprefs) if len(used_ipprefs) > 0 else 0

        if max_avail < 255:
            tmpl = list(set(range(1, max_avail + MAX_AVAIL + 1)) - set(used_ipprefs))
            tmpl.sort(lambda x,y: x-y)
            for idx in tmpl:
                result.append("%s.%d.0/24" % (unit_data['lan_net_pool'], idx))

        avail_nets[unit_id] = result

    return avail_nets
예제 #3
0
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))
예제 #4
0
 def __init__(self, request, *args, **kwargs):
     super(Create, self).__init__(request, *args, **kwargs)
     self.neutron_enabled = base.is_service_enabled(request, 'network')
     net_choices = network.network_list(request)
     if self.neutron_enabled:
         self.fields['neutron_net_id'] = forms.ChoiceField(
             choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
                                     for choice in net_choices],
             label=_("Neutron Net"),
             widget=forms.Select(attrs={
                 'class': 'switchable',
                 'data-slug': 'net'
             }))
         for net in net_choices:
             # For each network create switched choice field with
             # the its subnet choices
             subnet_field_name = 'subnet-choices-%s' % net.id
             subnet_field = forms.ChoiceField(
                 choices=(),
                 label=_("Neutron Subnet"),
                 widget=forms.Select(
                     attrs={
                         'class': 'switched',
                         'data-switch-on': 'net',
                         'data-net-%s' % net.id: _("Neutron Subnet")
                     }))
             self.fields[subnet_field_name] = subnet_field
             subnet_choices = neutron.subnet_list(request,
                                                  network_id=net.id)
             self.fields[subnet_field_name].choices = [(' ', ' ')] + [
                 (choice.id, choice.name_or_id) for choice in subnet_choices
             ]
def get_avail_networks(request):

    unit_table = getattr(settings, 'UNIT_TABLE', {})

    used_nets = dict()
    for subdict in neutron_api.subnet_list(request):
        cidr_match = CIDR_PATTERN.search(subdict['cidr'])
        if not cidr_match:
            continue
        if not cidr_match.group(1) in used_nets:
            used_nets[cidr_match.group(1)] = list()
        used_nets[cidr_match.group(1)].append(int(cidr_match.group(2)))

    avail_nets = dict()

    for unit_id, unit_data in unit_table.items():

        result = list()

        used_ipprefs = used_nets.get(unit_data['lan_net_pool'], [])
        max_avail = max(used_ipprefs) if len(used_ipprefs) > 0 else 0

        if max_avail < 255:
            tmpl = list(set(range(1, max_avail + MAX_AVAIL + 1)) - set(used_ipprefs))
            tmpl.sort(lambda x,y: x-y)
            for idx in tmpl:
                result.append("%s.%d.0/24" % (unit_data['lan_net_pool'], idx))

        avail_nets[unit_id] = result

    return avail_nets
예제 #6
0
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))
예제 #7
0
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))
예제 #8
0
 def __init__(self, request, *args, **kwargs):
     super(Create, self).__init__(request, *args, **kwargs)
     self.neutron_enabled = base.is_service_enabled(request, 'network')
     net_choices = network.network_list(request)
     if self.neutron_enabled:
         self.fields['neutron_net_id'] = forms.ChoiceField(
             choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
                                     for choice in net_choices],
             label=_("Neutron Net"), widget=forms.Select(
                 attrs={'class': 'switchable', 'data-slug': 'net'}))
         for net in net_choices:
             # For each network create switched choice field with
             # the its subnet choices
             subnet_field_name = 'subnet-choices-%s' % net.id
             subnet_field = forms.ChoiceField(
                 choices=(), label=_("Neutron Subnet"),
                 widget=forms.Select(attrs={
                     'class': 'switched',
                     'data-switch-on': 'net',
                     'data-net-%s' % net.id: _("Neutron Subnet")
                 }))
             self.fields[subnet_field_name] = subnet_field
             subnet_choices = neutron.subnet_list(
                 request, network_id=net.id)
             self.fields[subnet_field_name].choices = [
                 (' ', ' ')] + [(choice.id, choice.name_or_id)
                                for choice in subnet_choices]
     else:
         self.fields['nova_net_id'] = forms.ChoiceField(
             choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
                                     for choice in net_choices],
             label=_("Nova Net"), widget=forms.Select(
                 attrs={'class': 'switched', 'data-slug': 'net'}))
예제 #9
0
 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
예제 #10
0
 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
예제 #11
0
파일: quotas.py 프로젝트: toanalien/horizon
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))
예제 #12
0
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))
예제 #13
0
def _pool_list(request, expand_subnet=False, expand_vip=False, **kwargs):
    pools = neutronclient(request).list_pools(**kwargs).get('pools')
    if expand_subnet:
        subnets = neutron.subnet_list(request)
        subnet_dict = OrderedDict((s.id, s) for s in subnets)
        for p in pools:
            p['subnet'] = subnet_dict.get(p['subnet_id'])
    if expand_vip:
        vips = vip_list(request)
        vip_dict = OrderedDict((v.id, v) for v in vips)
        for p in pools:
            p['vip'] = _get_vip(request, p, vip_dict)
    return [Pool(p) for p in pools]
예제 #14
0
def _pool_list(request, expand_subnet=False, expand_vip=False, **kwargs):
    pools = neutronclient(request).list_pools(**kwargs).get('pools')
    if expand_subnet:
        subnets = neutron.subnet_list(request)
        subnet_dict = OrderedDict((s.id, s) for s in subnets)
        for p in pools:
            p['subnet'] = subnet_dict.get(p['subnet_id'])
    if expand_vip:
        vips = vip_list(request)
        vip_dict = OrderedDict((v.id, v) for v in vips)
        for p in pools:
            p['vip'] = _get_vip(request, p, vip_dict)
    return [Pool(p) for p in pools]
예제 #15
0
def _pool_list(request, expand_subnet=False, expand_vip=False, **kwargs):
    pools = neutronclient(request).list_pools(**kwargs).get("pools")
    if expand_subnet:
        subnets = neutron.subnet_list(request)
        subnet_dict = SortedDict((s.id, s) for s in subnets)
        for p in pools:
            p["subnet_name"] = subnet_dict.get(p["subnet_id"]).cidr
    if expand_vip:
        vips = vip_list(request)
        vip_dict = SortedDict((v.id, v) for v in vips)
        for p in pools:
            p["vip_name"] = _get_vip(request, p, vip_dict, expand_name_only=True)
    return [Pool(p) for p in pools]
예제 #16
0
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))
예제 #17
0
def _pool_list(request, expand_subnet=False, expand_vip=False, **kwargs):
    pools = neutronclient(request).list_pools(**kwargs).get('pools')
    if expand_subnet:
        subnets = neutron.subnet_list(request)
        subnet_dict = collections.OrderedDict((s.id, s) for s in subnets)
        for p in pools:
            subnet = subnet_dict.get(p['subnet_id'])
            p['subnet_name'] = subnet.cidr if subnet else None
    if expand_vip:
        vips = vip_list(request)
        vip_dict = collections.OrderedDict((v.id, v) for v in vips)
        for p in pools:
            p['vip_name'] = _get_vip(request, p, vip_dict,
                                     expand_name_only=True)
    return [Pool(p) for p in pools]
예제 #18
0
 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]
예제 #19
0
파일: forms.py 프로젝트: jcsp/manila-ui
 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]
예제 #20
0
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))
예제 #21
0
 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
예제 #22
0
파일: vpn.py 프로젝트: michaelrice/horizon
def _vpnservice_list(request, expand_subnet=False, expand_router=False,
                     expand_conns=False, **kwargs):
    vpnservices = neutronclient(request).list_vpnservices(
        **kwargs).get('vpnservices')
    if expand_subnet:
        subnets = neutron.subnet_list(request)
        subnet_dict = OrderedDict((s.id, s) for s in subnets)
        for s in vpnservices:
            s['subnet_name'] = subnet_dict.get(s['subnet_id']).cidr
    if expand_router:
        routers = neutron.router_list(request)
        router_dict = OrderedDict((r.id, r) for r in routers)
        for s in vpnservices:
            s['router_name'] = router_dict.get(s['router_id']).name_or_id
    if expand_conns:
        ipsecsiteconns = _ipsecsiteconnection_list(request, **kwargs)
        for s in vpnservices:
            s['ipsecsiteconns'] = [c.id for c in ipsecsiteconns
                                   if c.vpnservice_id == s['id']]
    return [VPNService(v) for v in vpnservices]
예제 #23
0
 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
예제 #24
0
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
예제 #25
0
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