def get_data(self):
     request = self.request
     try:
         gw_port = self._get_gateway_port_data()
         gw_vlans = neutron.nuage_gateway_vlan_list(
             self.request, gw_port.id)
         vlans = []
         for vlan in gw_vlans:
             if vlan.get('vport'):
                 dict = vlan.to_dict()
                 vport = neutron.nuage_gateway_vport_get(request,
                                                         vlan['vport'])
                 dict['vport'] = vport
                 if vport and vport.get('subnet'):
                     subnet = neutron.subnet_get(request,
                                                 vport.get('subnet'))
                     dict['subnet'] = subnet
                     if vport.get('port'):
                         try:
                             port = neutron.port_get(request,
                                                    vport['port'])
                             dict['port'] = port
                         except Exception:
                             dict['port'] = None
                 vlan = neutron.NuageGatewayVlan(dict)
             vlans.append(vlan)
     except Exception:
         vlans = []
         msg = _('Nuage Gateway Vlan list can not be retrieved.')
         exceptions.handle(request, msg)
     return vlans
 def get_context_data(self, **kwargs):
     context = super(AddAllowedAddressPair, self).get_context_data(**kwargs)
     context["port_id"] = self.kwargs['port_id']
     context['submit_url'] = reverse(self.submit_url,
                                     args=(self.kwargs['port_id'],))
     port = neutron.port_get(self.request, context['port_id'])
     subnet_id = port['fixed_ips'][0]['subnet_id']
     context['subnet'] = neutron.subnet_get(self.request, subnet_id)
     return context
 def allowed(self, request, port):
     allowed = super(AddAllowedAddressPair, self).allowed(request, port)
     if not allowed:
         return allowed
     if not port:
         port_id = self.table.kwargs['port_id']
         port = neutron.port_get(request, port_id)
     subnet_id = port['fixed_ips'][0]['subnet_id']
     subnet = neutron.subnet_get(request, subnet_id, fields=['vsd_managed',
                                                             'ip_version'])
     return not subnet['vsd_managed']
def get_data(self):
    subnet_id = self.kwargs['subnet_id']
    try:
        fields = ["vsd_managed", "name", "enable_dhcp", "network_id",
                  "tenant_id", "dns_nameservers", "gateway_ip",
                  "ipv6_ra_mode", "allocation_pools", "host_routes",
                  "ip_version", "ipv6_address_mode", "cidr", "id",
                  "subnetpool_id", "underlay"]
        subnet = neutron.subnet_get(self.request, subnet_id, fields=fields)
    except Exception:
        subnet = []
        msg = _('Unable to retrieve subnet details.')
        exceptions.handle(self.request, msg,
                          redirect=self.get_redirect_url())
    else:
        if subnet.ip_version == 6:
            ipv6_modes = utils.get_ipv6_modes_menu_from_attrs(
                subnet.ipv6_ra_mode, subnet.ipv6_address_mode)
            subnet.ipv6_modes_desc = utils.IPV6_MODE_MAP.get(ipv6_modes)
    return subnet