diff options
Diffstat (limited to 'portal-gui/rpkigui/myrpki/glue.py')
-rw-r--r-- | portal-gui/rpkigui/myrpki/glue.py | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/portal-gui/rpkigui/myrpki/glue.py b/portal-gui/rpkigui/myrpki/glue.py index c25b3055..a8abac89 100644 --- a/portal-gui/rpkigui/myrpki/glue.py +++ b/portal-gui/rpkigui/myrpki/glue.py @@ -2,26 +2,26 @@ from __future__ import with_statement import os import os.path -import csv import math -import rpki.myrpki +import rpki +from rpki.myrpki import csv_writer from rpki.resource_set import resource_range_ipv4 from rpki.ipaddrs import v4addr -import settings +from django.conf import settings -def form_to_conf(data): - """Write out a myrpki.conf based on the given form data.""" - handle = data['handle'] - confdir = settings.MYRPKI_DATA_DIR + '/' + handle - if os.path.exists(confdir): - raise RuntimeError, '%s: directory already exists!' % (confdir, ) - os.makedirs(confdir) - template = open(settings.MYRPKI_DATA_DIR + '/examples/myrpki.conf', 'r').read() - # stuff the appropriate output directory into the dict - data['MYRPKI_DATA_DIR'] = confdir - with open(confdir + '/myrpki.conf', 'w') as conf: - print >>conf, template % data - invoke_rpki(handle, ['initialize']) +#def form_to_conf(data): +# """Write out a myrpki.conf based on the given form data.""" +# handle = data['handle'] +# confdir = settings.MYRPKI_DATA_DIR + '/' + handle +# if os.path.exists(confdir): +# raise RuntimeError, '%s: directory already exists!' % (confdir, ) +# os.makedirs(confdir) +# template = open(settings.MYRPKI_DATA_DIR + '/examples/myrpki.conf', 'r').read() +# # stuff the appropriate output directory into the dict +# data['MYRPKI_DATA_DIR'] = confdir +# with open(confdir + '/myrpki.conf', 'w') as conf: +# print >>conf, template % data +# invoke_rpki(handle, ['initialize']) def invoke_rpki(handle, args): """Invoke the myrpki cli for the specified configuration.""" @@ -40,37 +40,43 @@ def read_identity(handle): def read_child_response(handle, child): fname = '%s/%s/entitydb/children/%s.xml' % (settings.MYRPKI_DATA_DIR, handle, child) with open(fname, 'r') as fp: - data = fp.read() + data = fp.read() return data -def output_asns(handle): +def output_asns(path, handle): '''Write out csv file containing resources delegated to my children.''' - confdir = settings.MYRPKI_DATA_DIR + '/' + handle.handle - f = csv.writer(open(confdir + '/asns.csv', 'w'), delimiter='\t') + f = csv_writer(path) for p in handle.children.all(): for asn in p.asn.all(): if asn.lo == asn.hi: f.writerow([p.handle, asn.lo]) -def output_prefixes(handle): +def output_prefixes(path, handle): '''Write out csv file containing resources delegated to my children.''' confdir = settings.MYRPKI_DATA_DIR + '/' + handle.handle - f = csv.writer(open(confdir + '/prefixes.csv', 'w'), delimiter='\t') + f = csv_writer(path) for p in handle.children.all(): - for prefix in p.address_range.all(): - f.writerow([p.handle, '%s-%s' % (prefix.lo, prefix.hi)]) + for prefix in p.address_range.all(): + f.writerow([p.handle, '%s-%s' % (prefix.lo, prefix.hi)]) -def output_roas(handle): - confdir = settings.MYRPKI_DATA_DIR + '/' + handle.handle - f = csv.writer(open(confdir + '/roas.csv', 'w'), delimiter='\t') +def output_roas(path, handle): + f = csv_writer(path) for r in handle.roas.all(): for addr in r.prefix.all(): - f.writerow([resource_range_ipv4(v4addr(str(addr.lo)), v4addr(str(addr.hi))), - r.asn, handle.handle]) + f.writerow([resource_range_ipv4(v4addr(str(addr.lo)), + v4addr(str(addr.hi))), + r.asn, + '%s-group-%d' % (handle.handle, r.pk)]) def configure_resources(handle): - # write out the .csv files and invoke the myrpki command line tool - output_asns(handle) - output_prefixes(handle) - output_roas(handle) + '''write out the .csv files and invoke the myrpki command line tool.''' + # chdir to the repo dir since the default myrpki.conf uses relative + # pathnames.. + os.chdir(settings.MYRPKI_DATA_DIR + '/' + handle.handle) + cfg = rpki.config.parser('myrpki.conf', 'myrpki') + output_asns(cfg.get('asn_csv'), handle) + output_prefixes(cfg.get('prefix_csv'), handle) + output_roas(cfg.get('roa_csv'), handle) #invoke_rpki(handle.handle, ['configure_daemons']) + +# vim:sw=4 ts=8 expandtab |