Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

AS path model #30

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -7,6 +7,7 @@

from .policy.app_probe import AppProbeMapItem, AppProbeParcel
from .policy.application_list import ApplicationFamilyListEntry, ApplicationListEntry, ApplicationListParcel
from .policy.as_path import AsPathParcel
from .policy.color_list import ColorEntry, ColorParcel
from .policy.data_prefix import DataPrefixEntry, DataPrefixParcel
from .policy.expanded_community_list import ExpandedCommunityParcel
Expand Down Expand Up @@ -39,6 +40,7 @@
URLParcel,
ApplicationListParcel,
AppProbeParcel,
AsPathParcel,
ColorParcel,
DataPrefixParcel,
ExpandedCommunityParcel,
Expand Down Expand Up @@ -72,6 +74,7 @@
"AppProbeEntry",
"AppProbeMapItem",
"AppProbeParcel",
"AsPathParcel",
"BaseURLListEntry",
"ColorEntry",
"ColorParcel",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from typing import List, Literal

from pydantic import AliasPath, BaseModel, ConfigDict, Field

from catalystwan.api.configuration_groups.parcel import Global, _ParcelBase, as_global


class AsPathEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)
as_path: Global[str] = Field(validation_alias="asPath", serialization_alias="asPath")


class AsPathParcel(_ParcelBase):
type_: Literal["as-path"] = Field(default="as-path", exclude=True)
as_path_list_num: Global[int] = Field(validation_alias=AliasPath("data", "asPathListNum"))
entries: List[AsPathEntry] = Field(validation_alias=AliasPath("data", "entries"))

def add_as_path(self, as_path: str):
self.entries.append(AsPathEntry(as_path=as_global(as_path)))
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
AnyPolicyObjectParcel,
ApplicationListParcel,
AppProbeParcel,
AsPathParcel,
ColorParcel,
DataPrefixParcel,
ExpandedCommunityParcel,
Expand All @@ -31,6 +32,7 @@
AnyPolicyList,
AppList,
AppProbeClassList,
ASPathList,
ClassMapList,
ColorList,
CommunityList,
Expand Down Expand Up @@ -76,7 +78,13 @@ def app_list(in_: AppList) -> ApplicationListParcel:
return out


# TODO: def as_path(in_: ASPathList):
def as_path(in_: ASPathList) -> AsPathParcel:
out = AsPathParcel(**_get_parcel_name_desc(in_))
for entry in in_.entries:
out.add_as_path(entry.as_path)
return out


def class_map(in_: ClassMapList) -> FowardingClassParcel:
out = FowardingClassParcel(**_get_parcel_name_desc(in_))
for entry in in_.entries:
Expand Down Expand Up @@ -258,6 +266,7 @@ class ConvertAllResult(NamedTuple):
CONVERTERS: Mapping[Type[Input], Callable[[Any], Output]] = {
AppProbeClassList: app_probe,
AppList: app_list,
ASPathList: as_path,
ClassMapList: class_map,
ColorList: color,
CommunityList: community,
Expand Down