Update modules/parse.py

This commit is contained in:
Blackwhitebear8 2025-09-17 20:05:46 +02:00
parent 7417be581e
commit 3db549d76d

View file

@ -9,7 +9,8 @@ VYOS_API_KEY = os.getenv("VYOS_API_KEY")
def _run_curl(endpoint, data_payload): def _run_curl(endpoint, data_payload):
curl_command = [ curl_command = [
"curl", "-k", "--location", "--request", "POST", f"{VYOS_API_URL}{endpoint}", "curl", "-s", "-k",
"--location", "--request", "POST", f"{VYOS_API_URL}{endpoint}",
"--form", f"data={json.dumps(data_payload)}", "--form", f"data={json.dumps(data_payload)}",
"--form", f"key={VYOS_API_KEY}" "--form", f"key={VYOS_API_KEY}"
] ]
@ -30,6 +31,15 @@ def get_bgp_neighbor_config_path(neighbor_ip):
else: else:
return ["protocols", "bgp", "neighbor", neighbor_ip] return ["protocols", "bgp", "neighbor", neighbor_ip]
def get_route_summary_path(ip_version):
vrf_name = os.getenv("BGP_VRF_NAME")
path = [ip_version, "route"]
if vrf_name:
path.extend(["vrf", vrf_name, "summary"])
else:
path.append("summary")
return path
def run_bgp_curl_command(): def run_bgp_curl_command():
path = get_bgp_base_path() + ["summ"] path = get_bgp_base_path() + ["summ"]
return _run_curl("/show", {"op": "show", "path": path}) return _run_curl("/show", {"op": "show", "path": path})
@ -90,4 +100,12 @@ def run_firewall_ipv4_curl_command():
return _run_curl("/show", {"op": "show", "path": ["firewall", "ipv4"]}) return _run_curl("/show", {"op": "show", "path": ["firewall", "ipv4"]})
def run_firewall_ipv6_curl_command(): def run_firewall_ipv6_curl_command():
return _run_curl("/show", {"op": "show", "path": ["firewall", "ipv6"]}) return _run_curl("/show", {"op": "show", "path": ["firewall", "ipv6"]})
def run_ipv4_route_summary_curl_command():
path = get_route_summary_path("ip")
return _run_curl("/show", {"op": "show", "path": path})
def run_ipv6_route_summary_curl_command():
path = get_route_summary_path("ipv6")
return _run_curl("/show", {"op": "show", "path": path})