asn_import.py (mod_asn-1.6) | : | asn_import.py (mod_asn-1.7) | ||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
import os, os.path, sys | import os, os.path, sys | |||
import psycopg2 | import psycopg2 | |||
import fileinput | import fileinput | |||
# change these | # change these | |||
tablename = 'pfx2asn' | tablename = 'pfx2asn' | |||
# not needed when a MirrorBrain setup exists | # not needed when a MirrorBrain setup exists | |||
conffile = '/etc/asn_import.conf' | conffile = '/etc/asn_import.conf' | |||
MAX_ASN_INT = 65535 | # ASN numbers can be 32 bit since 2007, but the highest numbers | |||
# are reserved for "private use". | ||||
MAX_ASN_INT = 4200000000 | ||||
# is there a MirrorBrain config file? If yes, use that. | # is there a MirrorBrain config file? If yes, use that. | |||
try: | try: | |||
import mb.conf | import mb.conf | |||
mirrorbrain_instance = None | mirrorbrain_instance = None | |||
if '-b' in sys.argv: | if '-b' in sys.argv: | |||
mirrorbrain_instance = sys.argv[sys.argv.index('-b') + 1] | mirrorbrain_instance = sys.argv[sys.argv.index('-b') + 1] | |||
del sys.argv[1:3] | del sys.argv[1:3] | |||
config = mb.conf.Config(instance = mirrorbrain_instance) | config = mb.conf.Config(instance = mirrorbrain_instance) | |||
import mb.conn | import mb.conn | |||
skipping to change at line 62 | skipping to change at line 64 | |||
import psycopg2.errorcodes | import psycopg2.errorcodes | |||
except: | except: | |||
pass | pass | |||
cursor.execute("begin") | cursor.execute("begin") | |||
cursor.execute("delete from %s" % tablename) | cursor.execute("delete from %s" % tablename) | |||
inserted = 0 | inserted = 0 | |||
for line in fileinput.input(): | for line in fileinput.input(): | |||
pfx, asnb, asn = line.split() | pfx, asnb, asn = line.split() | |||
if int(asn) > MAX_ASN_INT: | asn = int(asn) | |||
if (asn >= MAX_ASN_INT) or (asn == 0): | ||||
continue | ||||
if (64512 <= asn <= 65535): | ||||
continue | continue | |||
try: | try: | |||
cursor.execute("INSERT INTO %s VALUES ( %%s, %%s )" % tablename, [pf x, asn]) | cursor.execute("INSERT INTO %s VALUES ( %%s, %%s )" % tablename, [pf x, asn]) | |||
inserted += 1 | inserted += 1 | |||
except psycopg2.IntegrityError, e: | except psycopg2.IntegrityError, e: | |||
print e | print e | |||
if hasattr(psycopg2, 'errorcodes'): | if hasattr(psycopg2, 'errorcodes'): | |||
unique_violation = psycopg2.errorcodes.UNIQUE_VIOLATION | unique_violation = psycopg2.errorcodes.UNIQUE_VIOLATION | |||
else: | else: | |||
unique_violation = '23505' | unique_violation = '23505' | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 7 lines changed or added |