Esempio n. 1
0
    def get_initial(self):
        initial = super(UpdateView, self).get_initial()

        subnet = self._get_object()

        initial['network_id'] = self.kwargs['network_id']
        initial['subnet_id'] = subnet['id']
        initial['subnet_name'] = subnet['name']

        for key in ('cidr', 'ip_version', 'enable_dhcp'):
            initial[key] = subnet[key]

        initial['gateway_ip'] = subnet['gateway_ip'] or ''
        initial['no_gateway'] = (subnet['gateway_ip'] is None)

        if initial['ip_version'] == 6:
            initial['ipv6_modes'] = utils.get_ipv6_modes_menu_from_attrs(
                subnet['ipv6_ra_mode'], subnet['ipv6_address_mode'])

        initial['dns_nameservers'] = '\n'.join(subnet['dns_nameservers'])
        pools = [
            '%s,%s' % (p['start'], p['end'])
            for p in subnet['allocation_pools']
        ]
        initial['allocation_pools'] = '\n'.join(pools)
        routes = [
            '%s,%s' % (r['destination'], r['nexthop'])
            for r in subnet['host_routes']
        ]
        initial['host_routes'] = '\n'.join(routes)

        return initial
Esempio n. 2
0
    def get_initial(self):
        initial = super(UpdateView, self).get_initial()

        subnet = self._get_object()

        initial['network_id'] = self.kwargs['network_id']
        initial['subnet_id'] = subnet['id']
        initial['subnet_name'] = subnet['name']

        for key in ('cidr', 'ip_version', 'enable_dhcp'):
            initial[key] = subnet[key]

        initial['gateway_ip'] = subnet['gateway_ip'] or ''
        initial['no_gateway'] = (subnet['gateway_ip'] is None)

        if initial['ip_version'] == 6:
            initial['ipv6_modes'] = utils.get_ipv6_modes_menu_from_attrs(
                subnet['ipv6_ra_mode'], subnet['ipv6_address_mode'])

        initial['dns_nameservers'] = '\n'.join(subnet['dns_nameservers'])
        pools = ['%s,%s' % (p['start'], p['end'])
                 for p in subnet['allocation_pools']]
        initial['allocation_pools'] = '\n'.join(pools)
        routes = ['%s,%s' % (r['destination'], r['nexthop'])
                  for r in subnet['host_routes']]
        initial['host_routes'] = '\n'.join(routes)

        return initial
Esempio n. 3
0
    def get_data(self):
        subnet_id = self.kwargs['subnet_id']
        try:
            subnet = api.neutron.subnet_get(self.request, subnet_id)
        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)

            if ('subnetpool_id' in subnet and subnet.subnetpool_id and
                    # subnetpool_id = prefix_delegation is a special subnetpool
                    # and we cannot retrieve such subnet pool.
                    subnet.subnetpool_id != 'prefix_delegation'
                    and api.neutron.is_extension_supported(
                        self.request, 'subnet_allocation')):
                subnetpool = api.neutron.subnetpool_get(
                    self.request, subnet.subnetpool_id)
                subnet.subnetpool_name = subnetpool.name

        return subnet
Esempio n. 4
0
    def get_data(self):
        subnet_id = self.kwargs['subnet_id']
        try:
            subnet = api.neutron.subnet_get(self.request, subnet_id)
        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)

            if ('subnetpool_id' in subnet and
                subnet.subnetpool_id and
                # subnetpool_id = prefix_delegation is a special subnetpool
                # and we cannot retrieve such subnet pool.
                subnet.subnetpool_id != 'prefix_delegation' and
                api.neutron.is_extension_supported(self.request,
                                                   'subnet_allocation')):
                subnetpool = api.neutron.subnetpool_get(self.request,
                                                        subnet.subnetpool_id)
                subnet.subnetpool_name = subnetpool.name

        return subnet
Esempio n. 5
0
    def get_initial(self):
        initial = super(UpdateView, self).get_initial()

        subnet = self._get_object()

        initial["network_id"] = self.kwargs["network_id"]
        initial["subnet_id"] = subnet["id"]
        initial["subnet_name"] = subnet["name"]

        for key in ("cidr", "ip_version", "enable_dhcp"):
            initial[key] = subnet[key]

        initial["gateway_ip"] = subnet["gateway_ip"] or ""
        initial["no_gateway"] = subnet["gateway_ip"] is None

        if initial["ip_version"] == 6:
            initial["ipv6_modes"] = utils.get_ipv6_modes_menu_from_attrs(
                subnet["ipv6_ra_mode"], subnet["ipv6_address_mode"]
            )

        initial["dns_nameservers"] = "\n".join(subnet["dns_nameservers"])
        pools = ["%s,%s" % (p["start"], p["end"]) for p in subnet["allocation_pools"]]
        initial["allocation_pools"] = "\n".join(pools)
        routes = ["%s,%s" % (r["destination"], r["nexthop"]) for r in subnet["host_routes"]]
        initial["host_routes"] = "\n".join(routes)

        return initial
Esempio n. 6
0
 def get_context_data(self, request):
     subnet_id = self.tab_group.kwargs['subnet_id']
     try:
         subnet = api.neutron.subnet_get(self.request, subnet_id)
     except Exception:
         redirect = reverse('horizon:project:networks:index')
         msg = _('Unable to retrieve subnet details.')
         exceptions.handle(request, msg, redirect=redirect)
     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': subnet}
Esempio n. 7
0
 def get_context_data(self, request):
     subnet_id = self.tab_group.kwargs['subnet_id']
     try:
         subnet = api.neutron.subnet_get(self.request, subnet_id)
     except Exception:
         redirect = reverse('horizon:project:networks:index')
         msg = _('Unable to retrieve subnet details.')
         exceptions.handle(request, msg, redirect=redirect)
     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': subnet}
Esempio n. 8
0
    def get_data(self):
        subnet_id = self.kwargs['subnet_id']
        try:
            subnet = api.neutron.subnet_get(self.request, subnet_id)
        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
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
Esempio n. 10
0
    def get_data(self):
        subnet_id = self.kwargs["subnet_id"]
        try:
            subnet = api.neutron.subnet_get(self.request, subnet_id)
        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)

            if (
                "subnetpool_id" in subnet
                and subnet.subnetpool_id
                and api.neutron.is_extension_supported(self.request, "subnet_allocation")
            ):
                subnetpool = api.neutron.subnetpool_get(self.request, subnet.subnetpool_id)
                subnet.subnetpool_name = subnetpool.name

        return subnet