From 0609a0a9ba25c12d7d8e7dcee2a21678d397eac1 Mon Sep 17 00:00:00 2001 From: sbasan Date: Fri, 23 Feb 2024 11:12:30 +0100 Subject: [PATCH] wip --- .../sdwan/policy_object/policy/policier.py | 6 +++- .../policy/prefered_group_color.py | 7 ++++- .../sdwan/policy_object/policy/tloc_list.py | 6 +++- catalystwan/models/policy/lists.py | 28 ++++++++++++++++++- endpoints-md.py | 2 +- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/policier.py b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/policier.py index fa08e4d55..bae02f15d 100644 --- a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/policier.py +++ b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/policier.py @@ -3,7 +3,11 @@ from pydantic import AliasPath, BaseModel, ConfigDict, Field, field_validator from catalystwan.api.configuration_groups.parcel import Global, _ParcelBase, as_global -from catalystwan.models.policy.lists_entries import PolicerExceedAction + +PolicerExceedAction = Literal[ + "drop", + "remark", +] class PolicierEntry(BaseModel): diff --git a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/prefered_group_color.py b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/prefered_group_color.py index 417738298..a96e0b4c5 100644 --- a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/prefered_group_color.py +++ b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/prefered_group_color.py @@ -4,7 +4,12 @@ from catalystwan.api.configuration_groups.parcel import Global, _ParcelBase, as_global from catalystwan.models.common import TLOCColor -from catalystwan.models.policy.lists_entries import PathPreference + +PathPreference = Literal[ + "direct-path", + "multi-hop-path", + "all-paths", +] class Preference(BaseModel): diff --git a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/tloc_list.py b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/tloc_list.py index abb835531..8b4207a1b 100644 --- a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/tloc_list.py +++ b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/policy/tloc_list.py @@ -5,7 +5,11 @@ from catalystwan.api.configuration_groups.parcel import Global, _ParcelBase, as_global from catalystwan.models.common import TLOCColor -from catalystwan.models.policy.lists_entries import EncapType + +EncapType = Literal[ + "ipsec", + "gre", +] class TlocEntry(BaseModel): diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 49ff46003..ea6944b12 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -10,6 +10,8 @@ DataPrefixEntry, DataPrefixParcel, ) +from catalystwan.models.configuration.feature_profile.sdwan.policy_object.policy.tloc_list import TlocParcel +from catalystwan.models.configuration.feature_profile.sdwan.policy_object.security.zone import SecurityZoneListParcel from catalystwan.models.policy.lists_entries import ( AppListEntry, AppProbeClassListEntry, @@ -61,7 +63,7 @@ def _add_entry(self, entry: Any, single: bool = False) -> None: self.entries.append(entry) def to_policy_object_parcel(self) -> Optional[AnyPolicyObjectParcel]: - raise NotImplementedError + return None class DataPrefixList(PolicyListBase): @@ -107,6 +109,9 @@ def add_vpn_range(self, vpn_range: Tuple[int, int]): entry = VPNListEntry(vpn=f"{vpn_range[0]}-{vpn_range[1]}") self._add_entry(entry) + def to_policy_object_parcel(self) -> None: + return None + class ZoneList(PolicyListBase): type: Literal["zone"] = "zone" @@ -118,6 +123,18 @@ def assign_vpns(self, vpns: Set[int]) -> None: def assign_interfaces(self, ifs: Set[InterfaceType]) -> None: self.entries = [ZoneListEntry(interface=interface) for interface in ifs] + def to_policy_object_parcel(self) -> SecurityZoneListParcel: + parcel = SecurityZoneListParcel( + parcel_name=self.name, + parcel_description=self.description, + ) + for e in self.entries: + if e.vpn is not None: + parcel.add_vpn(e.vpn) + if e.interface is not None: + parcel.add_interface(e.interface) + return parcel + class FQDNList(PolicyListBase): type: Literal["fqdn"] = "fqdn" @@ -290,6 +307,15 @@ def add_tloc(self, tloc: IPv4Address, color: TLOCColor, encap: EncapType, prefer _preference = str(preference) if preference is not None else None self.entries.append(TLOCListEntry(tloc=tloc, color=color, encap=encap, preference=_preference)) + def to_policy_object_parcel(self) -> TlocParcel: + parcel = TlocParcel( + parcel_name=self.name, + parcel_description=self.description, + ) + for i in self.entries: + parcel.add_entry(i.tloc, i.color, i.encap, i.preference) + return parcel + class PreferredColorGroupList(PolicyListBase): type: Literal["preferredColorGroup"] = "preferredColorGroup" diff --git a/endpoints-md.py b/endpoints-md.py index 64cd581b9..721f36994 100644 --- a/endpoints-md.py +++ b/endpoints-md.py @@ -199,7 +199,7 @@ def md(self) -> str: # this instantiates APIEndpoints classes triggering method decorators # endpoints not attached to container will be not documented ! - _ = APIEndpointContainter(MagicMock()) + APIEndpointContainter(MagicMock()) endpoint_registry = EndpointRegistry( meta_lookup=request.request_lookup,