Example #1
0
 def populate_network_choices(self, request, context):
     try:
         pt_list = []
         pts = client.policy_target_list(request,
             tenant_id=request.user.tenant_id)
         for pt in pts:
             pt.set_id_as_name_if_empty()
             subnet_dedails = None
             for subnet_id in pt.subnets:
                 try:
                     subnet = api.neutron.subnet_get(request, subnet_id)
                     if subnet_dedails is None:
                         subnet_dedails = subnet['cidr']
                     else:
                         subnet_dedails += ";" + subnet['cidr']
                     allocation_pools = subnet['allocation_pools']
                     if allocation_pools:
                         start = allocation_pools[0]['start']
                         end = allocation_pools[0]['end']
                         subnet_dedails = subnet_dedails + "," + start
                         subnet_dedails = subnet_dedails + "," + end
                 except Exception as e:
                     LOG.error(str(e))
                     pass
             pt.id = pt.id + ":" + subnet_dedails
             pt_list.append((pt.id, pt.name))
         return sorted(pt_list, key=lambda obj: obj[1])
     except Exception:
         msg = _("Failed to retrieve groups")
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=shortcuts.redirect)
Example #2
0
 def get_policy_targetstable_data(self):
     policy_targets = []
     try:
         policy_targets = client.policy_target_list(self.tab_group.request)
         a = lambda x, y: gfilters.update_policy_target_attributes(x, y)
         policy_targets = [a(self.request, item) for item in policy_targets]
     except Exception as e:
         msg = _('Unable to retrieve policy_target list. %s') % (str(e))
         exceptions.handle(self.tab_group.request, msg)
         for policy_target in policy_targets:
             policy_target.set_id_as_name_if_empty()
     return policy_targets
Example #3
0
    def get(self, request):
        policy_targets = client.policy_target_list(
            request, tenant_id=request.user.tenant_id)

        proxy_group_ids = [
            pt.get('proxy_group_id') for pt in policy_targets
            if pt.get('proxy_group_id')
        ]

        try:
            policy_target_objects = []

            for policy_target in policy_targets:
                if not self.is_proxy_group(policy_target, proxy_group_ids):
                    subnet_objects = []

                    for subnet_id in policy_target.subnets:
                        try:
                            subnet = api.neutron.subnet_get(request, subnet_id)
                            allocation_pool_objects = []

                            allocation_pools = subnet['allocation_pools']
                            if allocation_pools:
                                for allocation_pool in allocation_pools:
                                    allocation_pool_object = {
                                        "start": allocation_pool['start'],
                                        "end": allocation_pool['end']
                                    }
                                    allocation_pool_objects.append(
                                        allocation_pool_object)

                            subnet_object = {
                                "cidr": subnet['cidr'],
                                "allocation_pools": allocation_pool_objects
                            }
                            subnet_objects.append(subnet_object)
                        except Exception:
                            LOG.exception("Unable to retrieve subnet.")

                    policy_target_object = {
                        "id": policy_target.id,
                        "name_or_id": policy_target.name_or_id,
                        "subnets": subnet_objects
                    }
                    policy_target_objects.append(policy_target_object)

            return rest_utils.JSONResponse(policy_target_objects)
        except Exception:
            msg = _("Failed to retrieve groups")
            LOG.error(msg)
            exceptions.handle(request, msg, redirect=shortcuts.redirect)
    def get(self, request):
        policy_targets = client.policy_target_list(
            request, tenant_id=request.user.tenant_id
        )

        proxy_group_ids = [pt.get('proxy_group_id') for pt in policy_targets
                           if pt.get('proxy_group_id')]

        try:
            policy_target_objects = []

            for policy_target in policy_targets:
                if not self.is_proxy_group(policy_target, proxy_group_ids):
                    subnet_objects = []

                    for subnet_id in policy_target.subnets:
                        try:
                            subnet = api.neutron.subnet_get(request, subnet_id)
                            allocation_pool_objects = []

                            allocation_pools = subnet['allocation_pools']
                            if allocation_pools:
                                for allocation_pool in allocation_pools:
                                    allocation_pool_object = {
                                        "start": allocation_pool['start'],
                                        "end": allocation_pool['end']
                                    }
                                    allocation_pool_objects.append(
                                        allocation_pool_object)

                            subnet_object = {
                                "cidr": subnet['cidr'],
                                "allocation_pools": allocation_pool_objects
                            }
                            subnet_objects.append(subnet_object)
                        except Exception:
                            LOG.exception("Unable to retrieve subnet.")

                    policy_target_object = {
                        "id": policy_target.id,
                        "name_or_id": policy_target.name_or_id,
                        "subnets": subnet_objects
                    }
                    policy_target_objects.append(policy_target_object)

            return rest_utils.JSONResponse(policy_target_objects)
        except Exception:
            msg = _("Failed to retrieve groups")
            LOG.error(msg)
            exceptions.handle(request, msg, redirect=shortcuts.redirect)
 def populate_network_choices(self, request, context):
     try:
         pt_list = []
         pts = client.policy_target_list(request,
                                         tenant_id=request.user.tenant_id)
         proxy_groups = [
             pt.get('proxy_group_id') for pt in pts
             if pt.get('proxy_group_id')
         ]
         for pt in pts:
             if hasattr(settings,
                        'GBPUI_HIDE_PTG_NAMES_FROM_MEMBER_CREATE'):
                 regexs = "(" + ")|(".join(
                     settings.GBPUI_HIDE_PTG_NAMES_FROM_MEMBER_CREATE) \
                     + ")"
                 if re.match(regexs, pt.get('name')):
                     continue
             if pt.id in proxy_groups or pt.get('proxied_group_id'):
                 continue
             pt.set_id_as_name_if_empty()
             subnet_dedails = None
             for subnet_id in pt.subnets:
                 try:
                     subnet = api.neutron.subnet_get(request, subnet_id)
                     subnet_name = subnet.name.split("_")
                     if subnet_name[-1] in proxy_groups:
                         continue
                     if subnet_dedails is None:
                         subnet_dedails = subnet['cidr']
                     else:
                         subnet_dedails += ";" + subnet['cidr']
                     allocation_pools = subnet['allocation_pools']
                     if allocation_pools:
                         start = allocation_pools[0]['start']
                         end = allocation_pools[0]['end']
                         subnet_dedails = subnet_dedails + "," + start
                         subnet_dedails = subnet_dedails + "," + end
                 except Exception as e:
                     LOG.error(str(e))
                     pass
             pt.id = pt.id + ":" + subnet_dedails
             pt_list.append((pt.id, pt.name))
         return sorted(pt_list, key=lambda obj: obj[1])
     except Exception:
         msg = _("Failed to retrieve groups")
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=shortcuts.redirect)
Example #6
0
 def __init__(self, request, *args, **kwargs):
     super(CreateServiceChainInstanceForm, self).__init__(
         request, *args, **kwargs)
     try:
         sc_specs = client.servicechainspec_list(request)
         ptgs = client.policy_target_list(request)
         ptgs = [(item.id, item.name) for item in ptgs]
         classifiers = client.policyclassifier_list(request)
         self.fields['servicechain_spec'].choices = [
             (item.id, item.name) for item in sc_specs]
         self.fields['provider_ptg'].choices = ptgs
         self.fields['consumer_ptg'].choices = ptgs
         self.fields['classifier'].choices = [
             (item.id, item.name) for item in classifiers]
     except Exception:
         msg = _("Failed to retrive policy targets")
         LOG.error(msg)
 def populate_network_choices(self, request, context):
     try:
         pt_list = []
         pts = client.policy_target_list(request,
             tenant_id=request.user.tenant_id)
         proxy_groups = [pt.get('proxy_group_id') for pt in pts
                         if pt.get('proxy_group_id')]
         for pt in pts:
             if hasattr(settings,
                        'GBPUI_HIDE_PTG_NAMES_FROM_MEMBER_CREATE'):
                 regexs = "(" + ")|(".join(
                     settings.GBPUI_HIDE_PTG_NAMES_FROM_MEMBER_CREATE) \
                     + ")"
                 if re.match(regexs, pt.get('name')):
                     continue
             if pt.id in proxy_groups or pt.get('proxied_group_id'):
                 continue
             pt.set_id_as_name_if_empty()
             subnet_dedails = None
             for subnet_id in pt.subnets:
                 try:
                     subnet = api.neutron.subnet_get(request, subnet_id)
                     subnet_name = subnet.name.split("_")
                     if subnet_name[-1] in proxy_groups:
                         continue
                     if subnet_dedails is None:
                         subnet_dedails = subnet['cidr']
                     else:
                         subnet_dedails += ";" + subnet['cidr']
                     allocation_pools = subnet['allocation_pools']
                     if allocation_pools:
                         start = allocation_pools[0]['start']
                         end = allocation_pools[0]['end']
                         subnet_dedails = subnet_dedails + "," + start
                         subnet_dedails = subnet_dedails + "," + end
                 except Exception as e:
                     LOG.error(str(e))
                     pass
             pt.id = pt.id + ":" + subnet_dedails
             pt_list.append((pt.id, pt.name))
         return sorted(pt_list, key=lambda obj: obj[1])
     except Exception:
         msg = _("Failed to retrieve groups")
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=shortcuts.redirect)