Skip to content

Commit

Permalink
Feat(cv_deploy): Add CV Pathfinder AVT hop count to metadata studio (#…
Browse files Browse the repository at this point in the history
…4071)

Co-authored-by: gmuloc <gmulocher@arista.com>
  • Loading branch information
ClausHolbechArista and gmuloc authored Jul 23, 2024
1 parent 0187ec9 commit d8c0d45
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,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 @@ -648,6 +648,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 @@ -643,6 +643,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 @@ -671,6 +671,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 @@ -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
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 @@ -12047,6 +12047,10 @@
"lossrate": {
"type": "string",
"title": "Lossrate"
},
"hop_count": {
"type": "string",
"title": "Hop Count"
}
},
"additionalProperties": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7138,6 +7138,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 @@ -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 @@ -29955,6 +29955,10 @@
"lossrate": {
"type": "string",
"title": "Lossrate"
},
"hop_count": {
"type": "string",
"title": "Hop Count"
}
},
"additionalProperties": false,
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

0 comments on commit d8c0d45

Please sign in to comment.