Add the '-l' flag to also take "local" AS numbers as a list. This allows us to

pass in the ASN lines from the delegated-ripencc-latest file, as well as local
AS numbers (ie 20392,8404,...)

This will be used by the ilines_update.cron bitcron


git-svn-id: svn+ssh://svn.ipng.nl/usr/share/subversion/repositories/ircnet.ipng.ch@33 c5d60b8d-fdcb-4146-b734-af4215e9eb71
This commit is contained in:
pim
2009-09-08 08:51:52 +00:00
parent 6f1b2126bc
commit fba72645fb

View File

@ -4,10 +4,13 @@
and transform a comma separated list of AS-SETs (-as-sets) into IRCnet's
I-Line structure. It will look at all ipv4 and ipv6 route objects in a
certain AS number, and it finds the AS numbers by expanding the AS-SET
members. It uses the class speficied on the commandline (-class)
members. It uses the class speficied on the commandline (-class). You can
also use the flag -asns to specify a list of AS numbers. These two flags
can be combined or used in isolation (as is shown by the examples below.
Example usage:
$ asset_ilines.py -as-sets AS-IP-MAN-PEERING-CIXP,AS-IP-MAN-PEERING-TIX \
-class 210 -output ilines.as-set.conf
$ asset_ilines.py -asns 8404,20932 -class 220 -output ilines.asn.conf
"""
import getopt
@ -22,7 +25,8 @@ import re
def usage():
print """Usage:
-h (-help): Help, this message
-a (-as-sets): The (comma separeted list of) AS set(s) to resolve
-a (-as-sets): A (comma separeted list of) AS set(s) to lookup
-l (-asns): A (comma separated list of) AS numbers to lookup
-o (-output): The output file to write
-y (-class): The Y-line class to put the I line in (default: 200)"""
pass
@ -83,8 +87,8 @@ def asset_to_asn(_asset, _whois_server = "whois.ripe.net",
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "ha:o:y:",
["help", "assets=", "output=", "class="])
opts, args = getopt.getopt(sys.argv[1:], "ha:l:o:y:",
["help", "assets=", "asns=", "output=", "class="])
except getopt.GetoptError, err:
print str(err) # will print something like "option -foo not recognized"
usage()
@ -94,13 +98,22 @@ def main():
"AS-IP-MAN-PEERING-SWISSIX"]
_class = 200
_output = None
_asns = [20932]
for o,a in opts:
if o == "-h" or o == "-help":
usage()
sys.exit(2)
elif o == "-a" or o == "-as-sets":
_assets = a.split(',')
if a == '':
_assets = []
else:
_assets = a.split(',')
elif o == "-l" or o == "-asns":
if a == '':
_asns = []
else:
_asns = a.split(',')
elif o == "-o" or o == "-output":
_output = a
elif o == "-y" or o == "-class":
@ -115,9 +128,10 @@ def main():
if type(_class) != types.IntType:
usage()
assert False, "-y (-class) must be an integer"
if len(_assets) < 1:
if len(_assets) < 1 and len(_asns) < 1:
usage()
assert False, "-a (-as-sets) must be a list of AS-SETs"
assert False,("-a (-as-sets) or -l (-asns) must be a comma "
"separated list")
try:
ofile = open(_output, "w")
@ -133,6 +147,12 @@ def main():
continue
_data['asn'][_asn] = []
_data['as-set']['LOCAL'] = _asns
for _asn in _data['as-set']['LOCAL']:
if _asn in _data['asn']:
continue
_data['asn'][_asn] = []
all_route_list = []
for _asn in _data['asn'].keys():
route_list = asn_to_route (_asn)
@ -150,8 +170,8 @@ def main():
(time.asctime(time.localtime(time.time())),
getpass.getuser(), socket.gethostname()))
ofile.write("# Commandline: %s\n" % ' '.join(sys.argv))
ofile.write("# assets=%s output=%s class=%s\n" %
(','.join(_assets), _output, _class))
ofile.write("# assets=%s asns=%s output=%s class=%s\n" %
(','.join(_assets), ','.join(_asns), _output, _class))
ofile.write("# Objects found: %d route/route6, %d ASn, %d as-set\n\n" %
(len(all_route_list), len(_data['asn']), len(_assets)))