def main_roagen(args, config, database): if args.protocol == 4: routes = (database.get(*spec) for spec in database.list() if spec[0] == "route") elif args.protocol == 6: routes = (database.get(*spec) for spec in database.list() if spec[0] == "route6") if args.flush: print("flush roa table {table}".format(table=args.table)) print("\n".join(lglass.generators.roa.roa_table(routes, args.table)))
def main_show_object(args, config, database): try: obj = database.get(args.type, args.primary_key) except KeyError: print("{} {} not found".format(args.type, args.primary_key), file=sys.stderr) exit(1) else: sys.stdout.write(obj.pretty_print(kv_padding=args.padding))
def main_format_object(args, config, database): try: obj = database.get(args.type, args.primary_key) except KeyError: print("{} {} not found".format(args.type, args.primary_key), file=sys.stderr) exit(1) else: database.save(obj)
def main_find_inverse(args, config, database): try: obj = database.get(args.type, args.primary_key) schema = database.schema(obj.type) except KeyError: print("{} {} not found".format(args.type, args.primary_key)) exit(1) else: inverses = set(obj.inverses(database)) for inverse in inverses: print("{}\t{}".format(*inverse.spec))
def main_validate_object(args, config, database): try: obj = database.get(args.type, args.primary_key) schema = database.schema(args.type) except KeyError: print("{} {} not found".format(args.type, args.primary_key)) exit(111) else: try: schema.validate(obj) except lglass.rpsl.SchemaValidationError as e: print("{} {} is invalid: Key {}: {}".format(args.type, args.primary_key, e.key, e.message)) exit(1) else: print("{} {} is valid".format(args.type, args.primary_key)) exit(0)
def main_edit_object(args, config, database): try: obj = database.get(args.type, args.primary_key) except KeyError: print("{} {} not found".format(args.type, args.primary_key)) exit(111) obj = _edit_object(args.editor, obj) if args.validate: try: schema = database.schema(obj.type) schema.validate(obj) except KeyError: print("Schema for {} not found".format(obj.type), file=sys.stderr) exit(111) except lglass.rpsl.SchemaValidationError as e: print("{} {} is invalid: Key {}: {}".format(args.type, args.primary_key, e.key, e.message)) exit(1) database.save(obj)