Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(cv_deploy): Add CV Pathfinder AVT hop count to metadata studio #4071

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ metadata:
avts:
- constraints:
jitter: 5
hop_count: lowest
id: 254
name: CUSTOM-CP-POLICY
pathgroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ metadata:
avts:
- constraints:
jitter: 42
hop_count: lowest
id: 2
name: PROD-AVT-POLICY-VOICE
pathgroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ metadata:
avts:
- constraints:
jitter: 42
hop_count: lowest
id: 2
name: PROD-AVT-POLICY-VOICE
pathgroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ metadata:
avts:
- constraints:
jitter: 42
hop_count: lowest
id: 2
name: PROD-AVT-POLICY-VOICE
pathgroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def is_pathfinder_location_supported(studio_schema: InputSchema) -> bool:
return attributes.issubset(pathfinder_group_fields)


def is_avt_hop_count_supported(studio_schema: InputSchema) -> bool:
"""Detect if AVT hop count is supported by the metadata studio"""
return bool(get_v2(studio_schema, "fields.values.avtHopCount"))


def is_internet_exit_zscaler_supported(studio_schema: InputSchema) -> bool:
"""Detect if zscaler internet exit is supported by the metadata studio"""
return bool(get_v2(studio_schema, "fields.values.zscaler"))
Expand All @@ -58,17 +63,26 @@ async def get_metadata_studio_schema(result: DeployToCvResult, cv_client: CVClie
return studio_schema


def update_general_metadata(metadata: dict, studio_inputs: dict) -> None:
def update_general_metadata(metadata: dict, studio_inputs: dict, studio_schema: InputSchema) -> list[str]:
"""
In-place update general metadata in studio_inputs.
"""
warnings = []

# Temporary fix for default values in metadata studio
for vrf in get(metadata, "vrfs", default=[]):
for avt in get(vrf, "avts", default=[]):
constraints: dict = avt.setdefault("constraints", {})
constraints.setdefault("latency", 4294967295)
constraints.setdefault("jitter", 4294967295)
constraints.setdefault("lossrate", 99.0)
if is_avt_hop_count_supported(studio_schema):
constraints["hopCount"] = constraints.pop("hop_count", "")
elif constraints.pop("hop_count", ""):
# hop count is set but not supported by metadata studio.
warning = "deploy_cv_pathfinder_metadata_to_cv: Ignoring AVT hop-count information since it is not supported by metadata studio."
LOGGER.info(warning)
warnings.append(warning)

studio_inputs.update(
{
Expand All @@ -85,6 +99,8 @@ def update_general_metadata(metadata: dict, studio_inputs: dict) -> None:
}
)

return warnings


def upsert_pathfinder(metadata: dict, device: CVDevice, studio_inputs: dict, studio_schema: InputSchema) -> list[str]:
"""
Expand Down Expand Up @@ -329,7 +345,7 @@ async def deploy_cv_pathfinder_metadata_to_cv(cv_pathfinder_metadata: list[CVPat

if pathfinders:
# All pathfinders must have the same be general metadata, so we just set it in the studio based on the first one.
update_general_metadata(metadata=pathfinders[0].metadata, studio_inputs=studio_inputs)
result.warnings.extend(update_general_metadata(metadata=pathfinders[0].metadata, studio_inputs=studio_inputs, studio_schema=studio_schema))

for pathfinder in pathfinders:
result.warnings.extend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jitter</samp>](## "metadata.cv_pathfinder.vrfs.[].avts.[].constraints.jitter") | Integer | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;latency</samp>](## "metadata.cv_pathfinder.vrfs.[].avts.[].constraints.latency") | Integer | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lossrate</samp>](## "metadata.cv_pathfinder.vrfs.[].avts.[].constraints.lossrate") | String | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hop_count</samp>](## "metadata.cv_pathfinder.vrfs.[].avts.[].constraints.hop_count") | String | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;description</samp>](## "metadata.cv_pathfinder.vrfs.[].avts.[].description") | String | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id</samp>](## "metadata.cv_pathfinder.vrfs.[].avts.[].id") | Integer | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name</samp>](## "metadata.cv_pathfinder.vrfs.[].avts.[].name") | String | | | | |
Expand Down Expand Up @@ -144,6 +145,7 @@
jitter: <int>
latency: <int>
lossrate: <str>
hop_count: <str>
description: <str>
id: <int>
name: <str>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ keys:
type: str
convert_types:
- float
hop_count:
type: str
description:
type: str
id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def _metadata_vrfs(self: AvdStructuredConfigMetadata) -> list:
"jitter": lb_policy.get("jitter"),
"latency": lb_policy.get("latency"),
"lossrate": float(lb_policy["loss_rate"]) if "loss_rate" in lb_policy else None,
"hop_count": "lowest" if lb_policy.get("lowest_hop_count") else None,
},
"description": "", # TODO: Not sure we have this field anywhere
"id": profile["id"],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.