Skip to content

Commit

Permalink
Fix PeeringDB IX import and set the local AS on import
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazoyer committed Nov 24, 2020
1 parent 6d81ce9 commit c1b4169
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
9 changes: 8 additions & 1 deletion peering/forms.py
Expand Up @@ -514,7 +514,14 @@ def __init__(self, *args, **kwargs):

class Meta:
model = InternetExchange
fields = ("peeringdb_id", "name", "slug", "ipv6_address", "ipv4_address")
fields = (
"peeringdb_id",
"local_autonomous_system",
"name",
"slug",
"ipv6_address",
"ipv4_address",
)
labels = {"ipv6_address": "IPv6 Address", "ipv4_address": "IPv4 Address"}
help_texts = {
"name": "Full name of the Internet Exchange point",
Expand Down
23 changes: 12 additions & 11 deletions peering/views.py
Expand Up @@ -286,10 +286,10 @@ def build_queryset(self, request, kwargs):
# which we want to get the peering sessions.
if "asn" in kwargs:
autonomous_system = get_object_or_404(AutonomousSystem, asn=kwargs["asn"])
queryset = (
autonomous_system.internetexchangepeeringsession_set.prefetch_related(
"internet_exchange"
).order_by("internet_exchange", "ip_address")
queryset = autonomous_system.internetexchangepeeringsession_set.prefetch_related(
"internet_exchange"
).order_by(
"internet_exchange", "ip_address"
)

return queryset
Expand Down Expand Up @@ -713,10 +713,10 @@ def get_objects(self, request):
if ix.peeringdb_id:
known_objects.append(ix.peeringdb_id)

ix_networks = (
api.get_ix_networks_for_asn(request.user.preferences.get("context.asn"))
or []
autonomous_system = AutonomousSystem.objects.get(
pk=request.user.preferences.get("context.asn")
)
ix_networks = api.get_ix_networks_for_asn(autonomous_system.asn) or []
slugs_occurences = {}

for ix_network in ix_networks:
Expand All @@ -732,6 +732,7 @@ def get_objects(self, request):
objects.append(
{
"peeringdb_id": ix_network.id,
"local_autonomous_system": autonomous_system,
"name": ix_network.name,
"slug": slug,
"ipv6_address": ix_network.ipaddr6,
Expand Down Expand Up @@ -807,10 +808,10 @@ def build_queryset(self, request, kwargs):
# which we want to get the peering sessions.
if "slug" in kwargs:
internet_exchange = get_object_or_404(InternetExchange, slug=kwargs["slug"])
queryset = (
internet_exchange.internetexchangepeeringsession_set.prefetch_related(
"autonomous_system"
).order_by("autonomous_system", "ip_address")
queryset = internet_exchange.internetexchangepeeringsession_set.prefetch_related(
"autonomous_system"
).order_by(
"autonomous_system", "ip_address"
)

return queryset
Expand Down

0 comments on commit c1b4169

Please sign in to comment.