aboutsummaryrefslogtreecommitdiff
path: root/rpkid/portal-gui/scripts/rpkigui-flatten-roas.py
blob: e94484cfeefa5b224cbf181ed6fcf5c490100ac2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from django.db import transaction
from django.db.models import Count
from rpki.gui.app.models import ROARequest
from rpki.irdb.zookeeper import Zookeeper

handles = set()


@transaction.commit_on_success
def flatten():
    for roa in ROARequest.objects.annotate(num_prefixes=Count('prefixes')).filter(num_prefixes__gt=1):
        print 'splitting roa for AS%d' % roa.asn
        for pfx in roa.prefixes.all():
            # create new roa objects for each prefix
            newroa = ROARequest.objects.create(
                issuer=roa.issuer,
                asn=roa.asn)
            newroa.prefixes.create(
                version=pfx.version,
                prefix=pfx.prefix,
                prefixlen=pfx.prefixlen,
                max_prefixlen=pfx.max_prefixlen
            )
        roa.delete()
        handles.add(roa.issuer.handle)

flatten()

if handles:
    # poke rpkid to run the cron job for each handle that had a roa change
    z = Zookeeper()
    for h in handles:
        z.reset_identity(h)
        z.run_rpkid_now()