Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/python
from collections import defaultdict
import argparse
import re
DEVICES = ["core1.ashb"]
OBJECT_TYPES = [
"as-path-set",
"as-set",
"community-set",
"esi-set",
"etag-set",
"extcommunity-set",
"large-community-set",
"mac-set",
"ospf-area-set",
"prefix-set",
"rd-set",
"route-policy",
"tag-set",
]
def main():
args = parse_args()
active = defaultdict(lambda: 0)
inactive = defaultdict(lambda: 0)
unused = defaultdict(lambda: 0)
obj_status = dict() # (device, object) => active | inactive | unused
# TODO - fetch list of devices
for d in DEVICES:
for typ in OBJECT_TYPES:
# TODO - fetch from devices D
sample_text = ""
# Recognize the start of a "the following X are (ACTIVE)"
# - these sections are always present, but may be empty
# - tehse sections always show up in a particular order (ACTIVE, INACTIVE, UNUSED)
RE_SECTION = re.compile("The following {typ}s are [^ ]*\n")
# Recognize the start of a policy object, including the name
RE_TYP = re.compile(f"^{typ} .*", flags=re.M)
_, active_text, inactive_text, unused_text = RE_SECTION.split(sample_text)
for obj in RE_TYP.findall(active_text):
active[obj] += 1
obj_status[d, obj] = "active"
for obj in RE_TYP.findall(inactive_text):
inactive[obj] += 1
obj_status[d, obj] = "inactive"
for obj in RE_TYP.findall(unused_text):
unused[obj] += 1
obj_status[d, obj] = "unused"
# Print out table
all_obj_keys = set(active) | set(inactive) | set(unused)
name_length = max([len(o) for o in all_obj_keys])
print(f"Object ({name_length}) Active Inactive Unused")
for obj in sorted(all_obj_keys):
print(f" {obj} {active[obj]} {inactive[obj]} {unused[obj]}")
# TODO: Excel spreadsheet
def parse_args():
parser = argparse.ArgumentParser(
description="Identify cruft IOS-XR policy across multiple devices"
)
parser.add_argument(
"-d",
"--device",
dest="device",
type=str,
help="Run against a single device [default will query GlobalNOC DB]",
)
parser.add_argument(
"--globalnoc-user",
dest="globalnoc_user",
type=str,
help="Specify username for GlobalNOC DB.",
)
parser.add_argument(
"--device-user",
dest="device_user",
type=str,
help="Specify username for logging into device",
)
return parser.parse_args()
if __name__ == "__main__":
main()