Skip to content

Commit

Permalink
SD-WAN UX1.0 fixes (#56)
Browse files Browse the repository at this point in the history
* add workaround for policy definition export

* add workaround for template policy vedge extract

* add workaround for localized policy extract

* add workaround for security policy export

* remove unnecessary files and update gitignore

* add workaround for centralized policy

* add header info for cli_device_template object

* simplify elif statement for policy extract

* remove debug print statements
  • Loading branch information
tzarski0 authored Oct 2, 2024
1 parent 647239a commit 99e4ee2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ tmp/

# pyenv
.python-version
__pycache__/
__pycache__/

.idea
52 changes: 47 additions & 5 deletions nac_collector/cisco_client_sdwan.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_from_endpoints(self, endpoints_yaml_file):

if all(
x not in endpoint["endpoint"]
for x in ["%v", "%i", "/v1/feature-profile/", "/template/device/"]
for x in ["%v", "%i", "/v1/feature-profile/", "/template/device/", "/template/policy/definition", "/template/policy/vedge", "/template/policy/vsmart", "/template/policy/security"]
):
response = self.get_request(self.base_url + endpoint["endpoint"])

Expand Down Expand Up @@ -160,6 +160,10 @@ def get_from_endpoints(self, endpoints_yaml_file):
elif endpoint["name"] == "cli_device_template":
endpoint_dict = self.get_device_templates(endpoint, endpoint_dict)
final_dict.update(endpoint_dict)
# policy definitions
elif any(substring in endpoint["endpoint"] for substring in ["/template/policy/definition", "/template/policy/vedge", "/template/policy/vsmart", "/template/policy/security"]):
endpoint_dict = self.get_policy_definitions(endpoint, endpoint_dict)
final_dict.update(endpoint_dict)
# for feature templates and device templates
elif "%i" in endpoint["endpoint"]:
endpoint_dict = self.get_feature_templates(endpoint, endpoint_dict)
Expand All @@ -186,8 +190,7 @@ def get_from_endpoints(self, endpoints_yaml_file):

self.log_response(endpoint, response)
else:
print("5")
input("ACCCCC")
pass
return final_dict

def get_device_templates(self, endpoint, endpoint_dict):
Expand Down Expand Up @@ -228,6 +231,7 @@ def get_device_templates(self, endpoint, endpoint_dict):
try:
endpoint_dict[endpoint["name"]].append(
{
"header": data["header"],
"data": i,
"endpoint": endpoint["endpoint"].split("/%i")[0]
+ "/"
Expand All @@ -236,17 +240,55 @@ def get_device_templates(self, endpoint, endpoint_dict):
)
except TypeError:
endpoint_dict[endpoint["name"]].append(
{"data": i, "endpoint": endpoint["endpoint"]}
{"header": data["header"], "data": i, "endpoint": endpoint["endpoint"]}
)
else:
endpoint_dict[endpoint["name"]].append(
{"data": data["data"], "endpoint": endpoint["endpoint"]}
{"header": data["header"], "data": data["data"], "endpoint": endpoint["endpoint"]}
)

self.log_response(endpoint, response)

return endpoint_dict

def get_policy_definitions(self, endpoint, endpoint_dict):
"""
Process policy definitions
Args:
endpoint (dict): The endpoint to process.
endpoint_dict (dict): The dictionary to append items to.
Returns:
enpdoint_dict: The updated endpoint_dict with the processed policy definitions.
"""
response = self.get_request(self.base_url + endpoint["endpoint"])

for item in response.json()["data"]:
if "definitionId" in item.keys():
new_endpoint = endpoint["endpoint"] + item["definitionId"]
else:
new_endpoint = endpoint["endpoint"] + "definition/" + item["policyId"]
response = self.get_request(self.base_url + new_endpoint)

data = response.json()
try:
endpoint_dict[endpoint["name"]].append(
{
"data": data,
"endpoint": new_endpoint,
}
)
except TypeError:
endpoint_dict[endpoint["name"]].append(
{"data": data, "endpoint": endpoint["endpoint"]}
)

self.log_response(new_endpoint, response)

return endpoint_dict

def get_feature_templates(self, endpoint, endpoint_dict):
"""
Process feature templates and feature device templates
Expand Down

0 comments on commit 99e4ee2

Please sign in to comment.