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

Commit

Permalink
Merge pull request #685 from cisco-open/extended_community_list_v1_model
Browse files Browse the repository at this point in the history
Extended community list v1 model
  • Loading branch information
jpkrajewski authored May 20, 2024
2 parents a7598cd + d90a341 commit 3a6bfdf
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repos:


- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [
Expand Down
17 changes: 16 additions & 1 deletion catalystwan/api/policy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from catalystwan.endpoints.configuration.policy.list.data_ipv6_prefix import ConfigurationPolicyDataIPv6PrefixList
from catalystwan.endpoints.configuration.policy.list.data_prefix import ConfigurationPolicyDataPrefixList
from catalystwan.endpoints.configuration.policy.list.expanded_community import ConfigurationPolicyExpandedCommunityList
from catalystwan.endpoints.configuration.policy.list.extended_community import ConfigurationPolicyExtendedCommunityList
from catalystwan.endpoints.configuration.policy.list.fqdn import ConfigurationPolicyFQDNList, FQDNListInfo
from catalystwan.endpoints.configuration.policy.list.geo_location import ConfigurationPolicyGeoLocationList
from catalystwan.endpoints.configuration.policy.list.ips_signature import ConfigurationPolicyIPSSignatureList
Expand Down Expand Up @@ -111,6 +112,7 @@
DataIPv6PrefixList,
DataPrefixList,
ExpandedCommunityList,
ExtendedCommunityList,
FQDNList,
GeoLocationList,
IPSSignatureList,
Expand Down Expand Up @@ -173,7 +175,11 @@
from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy, ZoneBasedFWPolicyGetResponse
from catalystwan.models.policy.list.app_probe import AppProbeClassListInfo
from catalystwan.models.policy.list.class_map import ClassMapListInfo
from catalystwan.models.policy.list.communities import CommunityListInfo, ExpandedCommunityListInfo
from catalystwan.models.policy.list.communities import (
CommunityListInfo,
ExpandedCommunityListInfo,
ExtendedCommunityListInfo,
)
from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixListInfo
from catalystwan.models.policy.list.data_prefix import DataPrefixListInfo
from catalystwan.models.policy.list.geo_location import GeoLocationListInfo
Expand Down Expand Up @@ -218,6 +224,7 @@
DataIPv6PrefixList: ConfigurationPolicyDataIPv6PrefixList,
DataPrefixList: ConfigurationPolicyDataPrefixList,
ExpandedCommunityList: ConfigurationPolicyExpandedCommunityList,
ExtendedCommunityList: ConfigurationPolicyExtendedCommunityList,
FQDNList: ConfigurationPolicyFQDNList,
GeoLocationList: ConfigurationPolicyGeoLocationList,
IPSSignatureList: ConfigurationPolicyIPSSignatureList,
Expand Down Expand Up @@ -441,6 +448,10 @@ def get(self, type: Type[DataPrefixList]) -> DataSequence[DataPrefixListInfo]:
def get(self, type: Type[ExpandedCommunityList]) -> DataSequence[ExpandedCommunityListInfo]:
...

@overload
def get(self, type: Type[ExtendedCommunityList]) -> DataSequence[ExtendedCommunityListInfo]:
...

@overload
def get(self, type: Type[FQDNList]) -> DataSequence[FQDNListInfo]:
...
Expand Down Expand Up @@ -571,6 +582,10 @@ def get(self, type: Type[DataPrefixList], id: UUID) -> DataPrefixListInfo:
def get(self, type: Type[ExpandedCommunityList], id: UUID) -> ExpandedCommunityListInfo:
...

@overload
def get(self, type: Type[ExtendedCommunityList], id: UUID) -> ExtendedCommunityListInfo:
...

@overload
def get(self, type: Type[FQDNList], id: UUID) -> FQDNListInfo:
...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2023 Cisco Systems, Inc. and its affiliates

# mypy: disable-error-code="empty-body"
from uuid import UUID

from catalystwan.endpoints import APIEndpoints, delete, get, post, put
from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints
from catalystwan.models.policy.list.communities import (
ExtendedCommunityList,
ExtendedCommunityListEditPayload,
ExtendedCommunityListInfo,
)
from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview
from catalystwan.typed_list import DataSequence


class ConfigurationPolicyExtendedCommunityList(APIEndpoints, PolicyListEndpoints):
@post("/template/policy/list/extcommunity")
def create_policy_list(self, payload: ExtendedCommunityList) -> PolicyListId:
...

@delete("/template/policy/list/extcommunity/{id}")
def delete_policy_list(self, id: UUID) -> None:
...

@delete("/template/policy/list/extcommunity")
def delete_policy_lists_with_info_tag(self, params: InfoTag) -> None:
...

@put("/template/policy/list/extcommunity/{id}")
def edit_policy_list(self, id: UUID, payload: ExtendedCommunityListEditPayload) -> None:
...

@get("/template/policy/list/extcommunity/{id}")
def get_lists_by_id(self, id: UUID) -> ExtendedCommunityListInfo:
...

@get("/template/policy/list/extcommunity", "data")
def get_policy_lists(self) -> DataSequence[ExtendedCommunityListInfo]:
...

@get("/template/policy/list/extcommunity/filtered", "data")
def get_policy_lists_with_info_tag(self, params: InfoTag) -> DataSequence[ExtendedCommunityListInfo]:
...

@post("/template/policy/list/extcommunity/preview")
def preview_policy_list(self, payload: ExtendedCommunityList) -> PolicyListPreview:
...

@get("/template/policy/list/extcommunity/preview/{id}")
def preview_policy_list_by_id(self, id: UUID) -> PolicyListPreview:
...
5 changes: 5 additions & 0 deletions catalystwan/models/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
CommunityListInfo,
ExpandedCommunityList,
ExpandedCommunityListInfo,
ExtendedCommunityList,
ExtendedCommunityListInfo,
)
from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixList, DataIPv6PrefixListInfo
from catalystwan.models.policy.list.data_prefix import DataPrefixList, DataPrefixListInfo
Expand Down Expand Up @@ -123,6 +125,7 @@
DataIPv6PrefixList,
DataPrefixList,
ExpandedCommunityList,
ExtendedCommunityList,
FQDNList,
GeoLocationList,
IPSSignatureList,
Expand Down Expand Up @@ -161,6 +164,7 @@
DataIPv6PrefixListInfo,
DataPrefixListInfo,
ExpandedCommunityListInfo,
ExtendedCommunityListInfo,
FQDNListInfo,
GeoLocationListInfo,
IPSSignatureListInfo,
Expand Down Expand Up @@ -242,6 +246,7 @@
"DnsSecurityPolicy",
"DNSTypeEntryType",
"ExpandedCommunityList",
"ExtendedCommunityList",
"FQDNList",
"GeoLocationList",
"HubAndSpokePolicy",
Expand Down
37 changes: 36 additions & 1 deletion catalystwan/models/policy/list/communities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from typing import List, Literal
from ipaddress import IPv4Address, IPv6Address
from typing import List, Literal, Optional, Union

from pydantic import BaseModel, ConfigDict, Field

Expand All @@ -14,6 +15,11 @@ class CommunityListEntry(BaseModel):
community: str = Field(examples=["1000:10000", "internet", "local-AS"])


class ExtendedCommunityListEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)
community: str = Field(examples=["soo 1.2.3.4:1000", "rt 10:100"])


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

Expand Down Expand Up @@ -46,3 +52,32 @@ class ExpandedCommunityListEditPayload(ExpandedCommunityList, PolicyListId):

class ExpandedCommunityListInfo(ExpandedCommunityList, PolicyListInfo):
pass


class ExtendedCommunityList(PolicyListBase):
entries: List[ExtendedCommunityListEntry] = []
type: Literal["extCommunity"] = "extCommunity"

def add_site_of_origin_community(
self, ip_address: Union[IPv4Address, IPv6Address], port: int, name: Optional[str] = None
):
entry = f"soo {ip_address}:{port}"
self.entries.append(ExtendedCommunityListEntry(community=self._append_name(entry, name)))

def add_route_target_community(self, as_number: int, community_number: int, name: Optional[str] = None):
entry = f"rt {as_number}:{community_number}"
self.entries.append(ExtendedCommunityListEntry(community=self._append_name(entry, name)))

def _append_name(self, entry: str, name: Optional[str] = None) -> str:
if not name:
return entry

return f"{name} {entry}"


class ExtendedCommunityListEditPayload(ExtendedCommunityList, PolicyListId):
pass


class ExtendedCommunityListInfo(ExtendedCommunityList, PolicyListInfo):
pass

0 comments on commit 3a6bfdf

Please sign in to comment.