|
| 1 | +from ttp import ttp |
| 2 | +import json |
| 3 | + |
| 4 | +def parse_running_config(data, template): |
| 5 | + parser = ttp(data=data, template=template) |
| 6 | + parser.parse() |
| 7 | + result = parser.result()[0][0] |
| 8 | + return result |
| 9 | + |
| 10 | +def parse_vpn_config(vrf, config, map_name="cryto_map_common"): |
| 11 | + try: |
| 12 | + iface_id = config["interfaces"][vrf]["66.66.66.66"]["id"] |
| 13 | + except: |
| 14 | + iface_id = config["interfaces"][vrf]["66.66.66.65"]["id"] |
| 15 | + result = config["ipsec"][map_name][iface_id] |
| 16 | + result["acl"] = config["acl"]["acc_acl_" + vrf] |
| 17 | + result["isa_profile"] = config["isakmp"]["profile"]["isa_profile_" + vrf] |
| 18 | + result["isa_profile"]["keyring"] = config["isakmp"]["keyring"]["keyring_" + vrf] |
| 19 | + result["route"] = config["route"].get(vrf, []) |
| 20 | + return result |
| 21 | + |
| 22 | +config = parse_running_config("./test.log", "./1.txt") |
| 23 | +with open("result.json", 'w') as f: |
| 24 | + f.write(json.dumps(config)) |
| 25 | + |
| 26 | +# for i in config["ipsec"]["cryto_map_common"].values(): |
| 27 | +# print(i.get("isa_profile"),i.get("is_complete","1")) |
| 28 | + |
| 29 | + |
| 30 | +result = parse_vpn_config("9e3rszehv0qlxijzv03bd5rhz", config) |
| 31 | +from pprint import pprint |
| 32 | +pprint(result) |
| 33 | + |
| 34 | +# import csv |
| 35 | + |
| 36 | + |
| 37 | +# def get_device_list(filename): |
| 38 | +# """csv to dict""" |
| 39 | +# with open(filename) as f: |
| 40 | +# reader = csv.DictReader(f) |
| 41 | +# return list(reader) |
| 42 | + |
| 43 | +# from netmiko import ConnectHandler as ch |
| 44 | + |
| 45 | +# CISCO_CMD = "show run" |
| 46 | +# H3C_CMD = "dis curr" |
| 47 | + |
| 48 | + |
0 commit comments