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

Commit

Permalink
include entry definitions within owning policy list
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Mar 14, 2024
1 parent cd1baf9 commit 267269b
Show file tree
Hide file tree
Showing 29 changed files with 469 additions and 455 deletions.
3 changes: 0 additions & 3 deletions catalystwan/models/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from .definition.traffic_data import TrafficDataPolicy, TrafficDataPolicyGetResponse
from .definition.vpn_membership import VPNMembershipPolicy, VPNMembershipPolicyGetResponse
from .definition.zone_based_firewall import ZoneBasedFWPolicy, ZoneBasedFWPolicyGetResponse
from .lists_entries import PathPreference, PolicerExceedAction
from .localized import LocalizedPolicy
from .policy_definition import (
Carrier,
Expand Down Expand Up @@ -212,10 +211,8 @@
"MirrorList",
"MultiRegionRole",
"OriginProtocol",
"PathPreference",
"PathType",
"PLPEntryType",
"PolicerExceedAction",
"PolicerList",
"PolicyActionType",
"PortList",
Expand Down
18 changes: 16 additions & 2 deletions catalystwan/models/policy/list/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
from typing import List, Literal
from typing import List, Literal, Optional

from catalystwan.models.policy.lists_entries import AppListEntry
from pydantic import BaseModel, ConfigDict, Field, model_validator

from catalystwan.models.common import check_fields_exclusive
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class AppListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

app_family: Optional[str] = Field(default=None, serialization_alias="appFamily", validation_alias="appFamily")
app: Optional[str] = None

@model_validator(mode="after")
def check_app_xor_appfamily(self):
check_fields_exclusive(self.__dict__, {"app", "app_family"}, True)
return self


class AppList(PolicyListBase):
type: Literal["app"] = "app"
entries: List[AppListEntry] = []
Expand Down
19 changes: 18 additions & 1 deletion catalystwan/models/policy/list/app_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import AppProbeClassListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.common import TLOCColor
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class ColorDSCPMap(BaseModel):
color: TLOCColor
dscp: int = Field(ge=0, le=63)


class AppProbeClassListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

forwarding_class: str = Field(serialization_alias="forwardingClass", validation_alias="forwardingClass")
map: List[ColorDSCPMap] = []

def add_color_mapping(self, color: TLOCColor, dscp: int) -> None:
self.map.append(ColorDSCPMap(color=color, dscp=dscp))


class AppProbeClassList(PolicyListBase):
type: Literal["appProbe"] = "appProbe"
entries: List[AppProbeClassListEntry] = []
Expand Down
9 changes: 8 additions & 1 deletion catalystwan/models/policy/list/as_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import ASPathListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class ASPathListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

as_path: str = Field(serialization_alias="asPath", validation_alias="asPath")


class ASPathList(PolicyListBase):
type: Literal["asPath"] = "asPath"
entries: List[ASPathListEntry] = []
Expand Down
8 changes: 7 additions & 1 deletion catalystwan/models/policy/list/class_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import ClassMapListEntry
from pydantic import BaseModel, Field

from catalystwan.models.common import IntStr
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class ClassMapListEntry(BaseModel):
queue: IntStr = Field(ge=0, le=7)


class ClassMapList(PolicyListBase):
type: Literal["class"] = "class"
entries: List[ClassMapListEntry] = []
Expand Down
7 changes: 6 additions & 1 deletion catalystwan/models/policy/list/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

from typing import List, Literal

from pydantic import BaseModel

from catalystwan.models.common import TLOCColor
from catalystwan.models.policy.lists_entries import ColorListEntry
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class ColorListEntry(BaseModel):
color: TLOCColor


class ColorList(PolicyListBase):
type: Literal["color"] = "color"
entries: List[ColorListEntry] = []
Expand Down
9 changes: 8 additions & 1 deletion catalystwan/models/policy/list/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

from typing import List, Literal

from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.common import WellKnownBGPCommunities
from catalystwan.models.policy.lists_entries import CommunityListEntry
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class CommunityListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

community: str = Field(examples=["1000:10000", "internet", "local-AS"])


class CommunityListBase(PolicyListBase):
entries: List[CommunityListEntry] = []

Expand Down
9 changes: 8 additions & 1 deletion catalystwan/models/policy/list/data_ipv6_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
from ipaddress import IPv6Interface
from typing import List, Literal

from catalystwan.models.policy.lists_entries import DataIPv6PrefixListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class DataIPv6PrefixListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

ipv6_prefix: IPv6Interface = Field(serialization_alias="ipv6Prefix", validation_alias="ipv6Prefix")


class DataIPv6PrefixList(PolicyListBase):
type: Literal["dataIpv6Prefix"] = "dataIpv6Prefix"
entries: List[DataIPv6PrefixListEntry] = []
Expand Down
9 changes: 8 additions & 1 deletion catalystwan/models/policy/list/data_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
from ipaddress import IPv4Network
from typing import List, Literal

from catalystwan.models.policy.lists_entries import DataPrefixListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class DataPrefixListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

ip_prefix: IPv4Network = Field(serialization_alias="ipPrefix", validation_alias="ipPrefix")


class DataPrefixList(PolicyListBase):
type: Literal["dataPrefix"] = "dataPrefix"
entries: List[DataPrefixListEntry] = []
Expand Down
7 changes: 6 additions & 1 deletion catalystwan/models/policy/list/fqdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import FQDNListEntry
from pydantic import BaseModel

from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class FQDNListEntry(BaseModel):
pattern: str


class FQDNList(PolicyListBase):
type: Literal["fqdn"] = "fqdn"
entries: List[FQDNListEntry] = []
Expand Down
18 changes: 16 additions & 2 deletions catalystwan/models/policy/list/geo_location.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
# Copyright 2022 Cisco Systems, Inc. and its affiliates

from typing import List, Literal
from typing import List, Literal, Optional

from catalystwan.models.policy.lists_entries import GeoLocationListEntry
from pydantic import BaseModel, Field, model_validator

from catalystwan.models.common import check_fields_exclusive
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class GeoLocationListEntry(BaseModel):
country: Optional[str] = Field(default=None, description="ISO-3166 alpha-3 country code eg: FRA")
continent: Optional[str] = Field(
default=None, description="One of 2-letter continent codes: AF, NA, OC, AN, AS, EU, SA"
)

@model_validator(mode="after")
def check_country_xor_continent(self):
check_fields_exclusive(self.__dict__, {"country", "continent"}, True)
return self


class GeoLocationList(PolicyListBase):
type: Literal["geoLocation"] = "geoLocation"
entries: List[GeoLocationListEntry] = []
Expand Down
10 changes: 9 additions & 1 deletion catalystwan/models/policy/list/ips_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import IPSSignatureListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class IPSSignatureListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

generator_id: str = Field(serialization_alias="generatorId", validation_alias="generatorId")
signature_id: str = Field(serialization_alias="signatureId", validation_alias="signatureId")


class IPSSignatureList(PolicyListBase):
type: Literal["ipsSignature"] = "ipsSignature"
entries: List[IPSSignatureListEntry] = []
Expand Down
12 changes: 11 additions & 1 deletion catalystwan/models/policy/list/ipv6_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
from ipaddress import IPv6Interface
from typing import List, Literal, Optional

from catalystwan.models.policy.lists_entries import IPv6PrefixListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.common import IntStr
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class IPv6PrefixListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

ipv6_prefix: IPv6Interface = Field(serialization_alias="ipv6Prefix", validation_alias="ipv6Prefix")
ge: Optional[IntStr] = Field(default=None, ge=0, le=128)
le: Optional[IntStr] = Field(default=None, ge=0, le=128)


class IPv6PrefixList(PolicyListBase):
type: Literal["ipv6prefix"] = "ipv6prefix"
entries: List[IPv6PrefixListEntry] = []
Expand Down
18 changes: 16 additions & 2 deletions catalystwan/models/policy/list/local_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
# Copyright 2022 Cisco Systems, Inc. and its affiliates

from typing import List, Literal
from typing import List, Literal, Optional

from catalystwan.models.policy.lists_entries import LocalAppListEntry
from pydantic import BaseModel, ConfigDict, Field, model_validator

from catalystwan.models.common import check_fields_exclusive
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class LocalAppListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

app_family: Optional[str] = Field(default=None, serialization_alias="appFamily", validation_alias="appFamily")
app: Optional[str] = None

@model_validator(mode="after")
def check_app_xor_appfamily(self):
check_fields_exclusive(self.__dict__, {"app", "app_family"}, True)
return self


class LocalAppList(PolicyListBase):
type: Literal["localApp"] = "localApp"
entries: List[LocalAppListEntry] = []
Expand Down
16 changes: 15 additions & 1 deletion catalystwan/models/policy/list/local_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import LocalDomainListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class LocalDomainListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

name_server: str = Field(
pattern="^[^*+].*",
serialization_alias="nameServer",
validation_alias="nameServer",
max_length=240,
description="Must be valid std regex."
"String cannot start with a '*' or a '+', be empty, or be more than 240 characters",
)


class LocalDomainList(PolicyListBase):
type: Literal["localDomain"] = "localDomain"
entries: List[LocalDomainListEntry] = []
Expand Down
10 changes: 9 additions & 1 deletion catalystwan/models/policy/list/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import MirrorListEntry
from pydantic import BaseModel, ConfigDict, Field, IPvAnyAddress

from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class MirrorListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

remote_dest: IPvAnyAddress = Field(serialization_alias="remoteDest", validation_alias="remoteDest")
source: IPvAnyAddress


class MirrorList(PolicyListBase):
type: Literal["mirror"] = "mirror"
entries: List[MirrorListEntry] = []
Expand Down
17 changes: 16 additions & 1 deletion catalystwan/models/policy/list/policer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import PolicerExceedAction, PolicerListEntry
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.models.common import IntStr
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo

PolicerExceedAction = Literal[
"drop",
"remark",
]


class PolicerListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)

burst: IntStr = Field(description="bytes", ge=15_000, le=10_000_000)
exceed: PolicerExceedAction = "drop"
rate: IntStr = Field(description="bps", ge=8, le=100_000_000_000)


class PolicerList(PolicyListBase):
type: Literal["policer"] = "policer"
Expand Down
16 changes: 15 additions & 1 deletion catalystwan/models/policy/list/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

from typing import List, Literal

from catalystwan.models.policy.lists_entries import PortListEntry
from pydantic import BaseModel, field_validator

from catalystwan.models.common import IntRangeStr
from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo


class PortListEntry(BaseModel):
port: IntRangeStr

@field_validator("port")
@classmethod
def check_port(cls, port: IntRangeStr):
for i in port:
if i is not None:
assert 0 <= i <= 65_535
return port


class PortList(PolicyListBase):
type: Literal["port"] = "port"
entries: List[PortListEntry] = []
Expand Down
Loading

0 comments on commit 267269b

Please sign in to comment.