aboutsummaryrefslogtreecommitdiff
path: root/potpourri/rpkigui-flatten-roas.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2014-04-05 22:42:12 +0000
committerRob Austein <sra@hactrn.net>2014-04-05 22:42:12 +0000
commitfe0bf509f528dbdc50c7182f81057c6a4e15e4bd (patch)
tree07c9a923d4a0ccdfea11c49cd284f6d5757c5eda /potpourri/rpkigui-flatten-roas.py
parentaa28ef54c271fbe4d52860ff8cf13cab19e2207c (diff)
Source tree reorg, phase 1. Almost everything moved, no file contents changed.
svn path=/branches/tk685/; revision=5757
Diffstat (limited to 'potpourri/rpkigui-flatten-roas.py')
-rw-r--r--potpourri/rpkigui-flatten-roas.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/potpourri/rpkigui-flatten-roas.py b/potpourri/rpkigui-flatten-roas.py
new file mode 100644
index 00000000..e21c368b
--- /dev/null
+++ b/potpourri/rpkigui-flatten-roas.py
@@ -0,0 +1,37 @@
+from rpki.gui.script_util import setup
+setup()
+
+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()