From 61bf5c0f887c9ea968cccbd1b7749a23c06d4b87 Mon Sep 17 00:00:00 2001 From: sbasan Date: Wed, 13 Mar 2024 23:11:15 +0100 Subject: [PATCH 01/36] phase 1 --- catalystwan/api/policy_api.py | 26 ++++++++-------- .../policy/definition/access_control_list.py | 2 +- .../definition/access_control_list_ipv6.py | 2 +- .../policy/definition/control.py | 2 +- .../policy/definition/device_access.py | 2 +- .../policy/definition/device_access_ipv6.py | 2 +- .../policy/definition/hub_and_spoke.py | 2 +- .../configuration/policy/definition/mesh.py | 2 +- .../policy/definition/qos_map.py | 2 +- .../policy/definition/rewrite.py | 2 +- .../policy/definition/rule_set.py | 2 +- .../policy/definition/security_group.py | 2 +- .../policy/definition/traffic_data.py | 2 +- .../policy/definition/vpn_membership.py | 2 +- .../policy/definition/zone_based_firewall.py | 2 +- catalystwan/models/common.py | 6 ++++ .../models/configuration/config_migration.py | 10 +----- catalystwan/models/policy/__init__.py | 31 +++++++++---------- .../access_control_list.py | 0 .../access_control_list_ipv6.py | 0 .../{definitions => definition}/control.py | 3 +- .../device_access.py | 0 .../device_access_ipv6.py | 0 .../hub_and_spoke.py | 0 .../{definitions => definition}/mesh.py | 0 .../{definitions => definition}/qos_map.py | 0 .../{definitions => definition}/rewrite.py | 0 .../{definitions => definition}/rule_set.py | 0 .../security_group.py | 0 .../traffic_data.py | 3 +- .../vpn_membership.py | 0 .../zone_based_firewall.py | 0 catalystwan/models/policy/list/as_path.py | 0 catalystwan/models/policy/list/class_map.py | 0 catalystwan/models/policy/list/color.py | 0 catalystwan/models/policy/list/community.py | 0 .../models/policy/list/data_ipv6_prefix.py | 0 catalystwan/models/policy/list/data_prefix.py | 0 .../models/policy/list/expanded_community.py | 0 catalystwan/models/policy/list/fqdn.py | 0 .../models/policy/list/geo_location.py | 0 .../models/policy/list/ips_signature.py | 0 catalystwan/models/policy/list/ipv6_prefix.py | 0 catalystwan/models/policy/list/local_app.py | 0 .../models/policy/list/local_domain.py | 0 catalystwan/models/policy/list/mirror.py | 0 catalystwan/models/policy/list/policer.py | 0 catalystwan/models/policy/list/port.py | 0 .../policy/list/preferred_color_group.py | 0 catalystwan/models/policy/list/prefix.py | 0 .../models/policy/list/protocol_name.py | 0 catalystwan/models/policy/list/region.py | 0 catalystwan/models/policy/list/site.py | 0 catalystwan/models/policy/list/sla.py | 0 catalystwan/models/policy/list/tloc.py | 0 .../models/policy/list/url_allow_list.py | 0 .../models/policy/list/url_block_list.py | 0 catalystwan/models/policy/list/vpn.py | 0 catalystwan/models/policy/list/zone.py | 0 catalystwan/models/policy/lists_entries.py | 6 +--- .../models/policy/policy_definition.py | 2 +- 61 files changed, 53 insertions(+), 62 deletions(-) rename catalystwan/models/policy/{definitions => definition}/access_control_list.py (100%) rename catalystwan/models/policy/{definitions => definition}/access_control_list_ipv6.py (100%) rename catalystwan/models/policy/{definitions => definition}/control.py (99%) rename catalystwan/models/policy/{definitions => definition}/device_access.py (100%) rename catalystwan/models/policy/{definitions => definition}/device_access_ipv6.py (100%) rename catalystwan/models/policy/{definitions => definition}/hub_and_spoke.py (100%) rename catalystwan/models/policy/{definitions => definition}/mesh.py (100%) rename catalystwan/models/policy/{definitions => definition}/qos_map.py (100%) rename catalystwan/models/policy/{definitions => definition}/rewrite.py (100%) rename catalystwan/models/policy/{definitions => definition}/rule_set.py (100%) rename catalystwan/models/policy/{definitions => definition}/security_group.py (100%) rename catalystwan/models/policy/{definitions => definition}/traffic_data.py (98%) rename catalystwan/models/policy/{definitions => definition}/vpn_membership.py (100%) rename catalystwan/models/policy/{definitions => definition}/zone_based_firewall.py (100%) create mode 100644 catalystwan/models/policy/list/as_path.py create mode 100644 catalystwan/models/policy/list/class_map.py create mode 100644 catalystwan/models/policy/list/color.py create mode 100644 catalystwan/models/policy/list/community.py create mode 100644 catalystwan/models/policy/list/data_ipv6_prefix.py create mode 100644 catalystwan/models/policy/list/data_prefix.py create mode 100644 catalystwan/models/policy/list/expanded_community.py create mode 100644 catalystwan/models/policy/list/fqdn.py create mode 100644 catalystwan/models/policy/list/geo_location.py create mode 100644 catalystwan/models/policy/list/ips_signature.py create mode 100644 catalystwan/models/policy/list/ipv6_prefix.py create mode 100644 catalystwan/models/policy/list/local_app.py create mode 100644 catalystwan/models/policy/list/local_domain.py create mode 100644 catalystwan/models/policy/list/mirror.py create mode 100644 catalystwan/models/policy/list/policer.py create mode 100644 catalystwan/models/policy/list/port.py create mode 100644 catalystwan/models/policy/list/preferred_color_group.py create mode 100644 catalystwan/models/policy/list/prefix.py create mode 100644 catalystwan/models/policy/list/protocol_name.py create mode 100644 catalystwan/models/policy/list/region.py create mode 100644 catalystwan/models/policy/list/site.py create mode 100644 catalystwan/models/policy/list/sla.py create mode 100644 catalystwan/models/policy/list/tloc.py create mode 100644 catalystwan/models/policy/list/url_allow_list.py create mode 100644 catalystwan/models/policy/list/url_block_list.py create mode 100644 catalystwan/models/policy/list/vpn.py create mode 100644 catalystwan/models/policy/list/zone.py diff --git a/catalystwan/api/policy_api.py b/catalystwan/api/policy_api.py index dd282bcbe..81566c561 100644 --- a/catalystwan/api/policy_api.py +++ b/catalystwan/api/policy_api.py @@ -143,19 +143,19 @@ from catalystwan.models.misc.application_protocols import ApplicationProtocol from catalystwan.models.policy import AnyPolicyDefinition, AnyPolicyList from catalystwan.models.policy.centralized import CentralizedPolicy, CentralizedPolicyEditPayload, CentralizedPolicyInfo -from catalystwan.models.policy.definitions.access_control_list import AclPolicy -from catalystwan.models.policy.definitions.access_control_list_ipv6 import AclIPv6Policy -from catalystwan.models.policy.definitions.control import ControlPolicy -from catalystwan.models.policy.definitions.device_access import DeviceAccessPolicy -from catalystwan.models.policy.definitions.device_access_ipv6 import DeviceAccessIPv6Policy -from catalystwan.models.policy.definitions.hub_and_spoke import HubAndSpokePolicy -from catalystwan.models.policy.definitions.mesh import MeshPolicy -from catalystwan.models.policy.definitions.qos_map import QoSMapPolicy -from catalystwan.models.policy.definitions.rewrite import RewritePolicy -from catalystwan.models.policy.definitions.rule_set import RuleSet -from catalystwan.models.policy.definitions.security_group import SecurityGroup -from catalystwan.models.policy.definitions.vpn_membership import VPNMembershipPolicy -from catalystwan.models.policy.definitions.zone_based_firewall import ZoneBasedFWPolicy +from catalystwan.models.policy.definition.access_control_list import AclPolicy +from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy +from catalystwan.models.policy.definition.control import ControlPolicy +from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy +from catalystwan.models.policy.definition.device_access_ipv6 import DeviceAccessIPv6Policy +from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy +from catalystwan.models.policy.definition.mesh import MeshPolicy +from catalystwan.models.policy.definition.qos_map import QoSMapPolicy +from catalystwan.models.policy.definition.rewrite import RewritePolicy +from catalystwan.models.policy.definition.rule_set import RuleSet +from catalystwan.models.policy.definition.security_group import SecurityGroup +from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy +from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy from catalystwan.models.policy.lists import ( AppList, AppProbeClassList, diff --git a/catalystwan/endpoints/configuration/policy/definition/access_control_list.py b/catalystwan/endpoints/configuration/policy/definition/access_control_list.py index 76da07822..53dda8cca 100644 --- a/catalystwan/endpoints/configuration/policy/definition/access_control_list.py +++ b/catalystwan/endpoints/configuration/policy/definition/access_control_list.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.access_control_list import AclPolicy +from catalystwan.models.policy.definition.access_control_list import AclPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py b/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py index 3e19d8eca..b58147099 100644 --- a/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py +++ b/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.access_control_list_ipv6 import AclIPv6Policy +from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/control.py b/catalystwan/endpoints/configuration/policy/definition/control.py index f502c5ee9..5d5f6dc6a 100644 --- a/catalystwan/endpoints/configuration/policy/definition/control.py +++ b/catalystwan/endpoints/configuration/policy/definition/control.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.control import ControlPolicy +from catalystwan.models.policy.definition.control import ControlPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/device_access.py b/catalystwan/endpoints/configuration/policy/definition/device_access.py index 052286488..e929d812a 100644 --- a/catalystwan/endpoints/configuration/policy/definition/device_access.py +++ b/catalystwan/endpoints/configuration/policy/definition/device_access.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.device_access import DeviceAccessPolicy +from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py b/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py index 82a275cb0..defa7f721 100644 --- a/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py +++ b/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.device_access_ipv6 import DeviceAccessIPv6Policy +from catalystwan.models.policy.definition.device_access_ipv6 import DeviceAccessIPv6Policy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py b/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py index 6d4a8dbce..d15c4ba66 100644 --- a/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py +++ b/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.hub_and_spoke import HubAndSpokePolicy +from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/mesh.py b/catalystwan/endpoints/configuration/policy/definition/mesh.py index 9dba385ce..fb999688f 100644 --- a/catalystwan/endpoints/configuration/policy/definition/mesh.py +++ b/catalystwan/endpoints/configuration/policy/definition/mesh.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.mesh import MeshPolicy +from catalystwan.models.policy.definition.mesh import MeshPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/qos_map.py b/catalystwan/endpoints/configuration/policy/definition/qos_map.py index 620a530d7..49fe7da2f 100644 --- a/catalystwan/endpoints/configuration/policy/definition/qos_map.py +++ b/catalystwan/endpoints/configuration/policy/definition/qos_map.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.qos_map import QoSMapPolicy +from catalystwan.models.policy.definition.qos_map import QoSMapPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/rewrite.py b/catalystwan/endpoints/configuration/policy/definition/rewrite.py index 57dd8b262..79308c135 100644 --- a/catalystwan/endpoints/configuration/policy/definition/rewrite.py +++ b/catalystwan/endpoints/configuration/policy/definition/rewrite.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.rewrite import RewritePolicy +from catalystwan.models.policy.definition.rewrite import RewritePolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/rule_set.py b/catalystwan/endpoints/configuration/policy/definition/rule_set.py index 15edb05bd..1e09afac3 100644 --- a/catalystwan/endpoints/configuration/policy/definition/rule_set.py +++ b/catalystwan/endpoints/configuration/policy/definition/rule_set.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.rule_set import RuleSet +from catalystwan.models.policy.definition.rule_set import RuleSet from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/security_group.py b/catalystwan/endpoints/configuration/policy/definition/security_group.py index 9ca7c9703..b57491649 100644 --- a/catalystwan/endpoints/configuration/policy/definition/security_group.py +++ b/catalystwan/endpoints/configuration/policy/definition/security_group.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.security_group import SecurityGroup +from catalystwan.models.policy.definition.security_group import SecurityGroup from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/traffic_data.py b/catalystwan/endpoints/configuration/policy/definition/traffic_data.py index c3cacf27c..03f5e1039 100644 --- a/catalystwan/endpoints/configuration/policy/definition/traffic_data.py +++ b/catalystwan/endpoints/configuration/policy/definition/traffic_data.py @@ -5,7 +5,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.traffic_data import TrafficDataPolicy +from catalystwan.models.policy.definition.traffic_data import TrafficDataPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py b/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py index a63bf1c46..352ff0ef8 100644 --- a/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py +++ b/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.vpn_membership import VPNMembershipPolicy +from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py b/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py index b805c1fb3..c78a6d1f3 100644 --- a/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py +++ b/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py @@ -4,7 +4,7 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.definitions.zone_based_firewall import ZoneBasedFWPolicy +from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, PolicyDefinitionEndpoints, diff --git a/catalystwan/models/common.py b/catalystwan/models/common.py index d01e90063..9feafaff0 100644 --- a/catalystwan/models/common.py +++ b/catalystwan/models/common.py @@ -101,6 +101,12 @@ def str_as_str_list(val: Union[str, Sequence[str]]) -> Sequence[str]: return val +EncapType = Literal[ + "ipsec", + "gre", +] + + InterfaceType = Literal[ "Ethernet", "FastEthernet", diff --git a/catalystwan/models/configuration/config_migration.py b/catalystwan/models/configuration/config_migration.py index df785c2c9..70273377e 100644 --- a/catalystwan/models/configuration/config_migration.py +++ b/catalystwan/models/configuration/config_migration.py @@ -1,6 +1,6 @@ # Copyright 2024 Cisco Systems, Inc. and its affiliates -from typing import List, Literal, Union +from typing import List, Union from pydantic import BaseModel, ConfigDict, Field from typing_extensions import Annotated @@ -54,14 +54,6 @@ class UX1Templates(BaseModel): ) -class ConfigGroupPreset(BaseModel): - config_group_name: str = Field(serialization_alias="name", validation_alias="name") - solution: Literal["sdwan"] = "sdwan" - profile_parcels: List[AnyParcel] = Field( - default=[], serialization_alias="profileParcels", validation_alias="profileParcels" - ) - - class UX1Config(BaseModel): # All UX1 Configuration items - Mega Model model_config = ConfigDict(populate_by_name=True) diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 0dfa4b3ac..1a107b89b 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -7,20 +7,20 @@ from typing_extensions import Annotated from .centralized import CentralizedPolicy, TrafficDataDirection -from .definitions.access_control_list import AclPolicy -from .definitions.access_control_list_ipv6 import AclIPv6Policy -from .definitions.control import ControlPolicy -from .definitions.device_access import DeviceAccessPolicy -from .definitions.device_access_ipv6 import DeviceAccessIPv6Policy -from .definitions.hub_and_spoke import HubAndSpokePolicy -from .definitions.mesh import MeshPolicy -from .definitions.qos_map import QoSDropType, QoSMapPolicy -from .definitions.rewrite import RewritePolicy -from .definitions.rule_set import RuleSet -from .definitions.security_group import SecurityGroup -from .definitions.traffic_data import TrafficDataPolicy -from .definitions.vpn_membership import VPNMembershipPolicy -from .definitions.zone_based_firewall import ZoneBasedFWPolicy +from .definition.access_control_list import AclPolicy +from .definition.access_control_list_ipv6 import AclIPv6Policy +from .definition.control import ControlPolicy +from .definition.device_access import DeviceAccessPolicy +from .definition.device_access_ipv6 import DeviceAccessIPv6Policy +from .definition.hub_and_spoke import HubAndSpokePolicy +from .definition.mesh import MeshPolicy +from .definition.qos_map import QoSDropType, QoSMapPolicy +from .definition.rewrite import RewritePolicy +from .definition.rule_set import RuleSet +from .definition.security_group import SecurityGroup +from .definition.traffic_data import TrafficDataPolicy +from .definition.vpn_membership import VPNMembershipPolicy +from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( AppList, AppProbeClassList, @@ -52,7 +52,7 @@ VPNList, ZoneList, ) -from .lists_entries import EncapType, PathPreference, PolicerExceedAction +from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( Carrier, @@ -142,7 +142,6 @@ "DeviceAccessIPv6Policy", "DeviceAccessPolicy", "DNSTypeEntryType", - "EncapType", "ExpandedCommunityList", "FQDNList", "GeoLocationList", diff --git a/catalystwan/models/policy/definitions/access_control_list.py b/catalystwan/models/policy/definition/access_control_list.py similarity index 100% rename from catalystwan/models/policy/definitions/access_control_list.py rename to catalystwan/models/policy/definition/access_control_list.py diff --git a/catalystwan/models/policy/definitions/access_control_list_ipv6.py b/catalystwan/models/policy/definition/access_control_list_ipv6.py similarity index 100% rename from catalystwan/models/policy/definitions/access_control_list_ipv6.py rename to catalystwan/models/policy/definition/access_control_list_ipv6.py diff --git a/catalystwan/models/policy/definitions/control.py b/catalystwan/models/policy/definition/control.py similarity index 99% rename from catalystwan/models/policy/definitions/control.py rename to catalystwan/models/policy/definition/control.py index c86e176b7..f132902e1 100644 --- a/catalystwan/models/policy/definitions/control.py +++ b/catalystwan/models/policy/definition/control.py @@ -7,8 +7,7 @@ from pydantic import ConfigDict, Field from typing_extensions import Annotated -from catalystwan.models.common import TLOCColor -from catalystwan.models.policy.lists_entries import EncapType +from catalystwan.models.common import EncapType, TLOCColor from catalystwan.models.policy.policy_definition import ( AffinityEntry, Carrier, diff --git a/catalystwan/models/policy/definitions/device_access.py b/catalystwan/models/policy/definition/device_access.py similarity index 100% rename from catalystwan/models/policy/definitions/device_access.py rename to catalystwan/models/policy/definition/device_access.py diff --git a/catalystwan/models/policy/definitions/device_access_ipv6.py b/catalystwan/models/policy/definition/device_access_ipv6.py similarity index 100% rename from catalystwan/models/policy/definitions/device_access_ipv6.py rename to catalystwan/models/policy/definition/device_access_ipv6.py diff --git a/catalystwan/models/policy/definitions/hub_and_spoke.py b/catalystwan/models/policy/definition/hub_and_spoke.py similarity index 100% rename from catalystwan/models/policy/definitions/hub_and_spoke.py rename to catalystwan/models/policy/definition/hub_and_spoke.py diff --git a/catalystwan/models/policy/definitions/mesh.py b/catalystwan/models/policy/definition/mesh.py similarity index 100% rename from catalystwan/models/policy/definitions/mesh.py rename to catalystwan/models/policy/definition/mesh.py diff --git a/catalystwan/models/policy/definitions/qos_map.py b/catalystwan/models/policy/definition/qos_map.py similarity index 100% rename from catalystwan/models/policy/definitions/qos_map.py rename to catalystwan/models/policy/definition/qos_map.py diff --git a/catalystwan/models/policy/definitions/rewrite.py b/catalystwan/models/policy/definition/rewrite.py similarity index 100% rename from catalystwan/models/policy/definitions/rewrite.py rename to catalystwan/models/policy/definition/rewrite.py diff --git a/catalystwan/models/policy/definitions/rule_set.py b/catalystwan/models/policy/definition/rule_set.py similarity index 100% rename from catalystwan/models/policy/definitions/rule_set.py rename to catalystwan/models/policy/definition/rule_set.py diff --git a/catalystwan/models/policy/definitions/security_group.py b/catalystwan/models/policy/definition/security_group.py similarity index 100% rename from catalystwan/models/policy/definitions/security_group.py rename to catalystwan/models/policy/definition/security_group.py diff --git a/catalystwan/models/policy/definitions/traffic_data.py b/catalystwan/models/policy/definition/traffic_data.py similarity index 98% rename from catalystwan/models/policy/definitions/traffic_data.py rename to catalystwan/models/policy/definition/traffic_data.py index 2d3ffbee5..6215f6329 100644 --- a/catalystwan/models/policy/definitions/traffic_data.py +++ b/catalystwan/models/policy/definition/traffic_data.py @@ -7,8 +7,7 @@ from pydantic import ConfigDict, Field from typing_extensions import Annotated -from catalystwan.models.common import ICMPMessageType, ServiceChainNumber, TLOCColor -from catalystwan.models.policy.lists_entries import EncapType +from catalystwan.models.common import EncapType, ICMPMessageType, ServiceChainNumber, TLOCColor from catalystwan.models.policy.policy_definition import ( AppListEntry, CFlowDAction, diff --git a/catalystwan/models/policy/definitions/vpn_membership.py b/catalystwan/models/policy/definition/vpn_membership.py similarity index 100% rename from catalystwan/models/policy/definitions/vpn_membership.py rename to catalystwan/models/policy/definition/vpn_membership.py diff --git a/catalystwan/models/policy/definitions/zone_based_firewall.py b/catalystwan/models/policy/definition/zone_based_firewall.py similarity index 100% rename from catalystwan/models/policy/definitions/zone_based_firewall.py rename to catalystwan/models/policy/definition/zone_based_firewall.py diff --git a/catalystwan/models/policy/list/as_path.py b/catalystwan/models/policy/list/as_path.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/class_map.py b/catalystwan/models/policy/list/class_map.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/color.py b/catalystwan/models/policy/list/color.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/community.py b/catalystwan/models/policy/list/community.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/data_ipv6_prefix.py b/catalystwan/models/policy/list/data_ipv6_prefix.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/data_prefix.py b/catalystwan/models/policy/list/data_prefix.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/expanded_community.py b/catalystwan/models/policy/list/expanded_community.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/fqdn.py b/catalystwan/models/policy/list/fqdn.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/geo_location.py b/catalystwan/models/policy/list/geo_location.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/ips_signature.py b/catalystwan/models/policy/list/ips_signature.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/ipv6_prefix.py b/catalystwan/models/policy/list/ipv6_prefix.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/local_app.py b/catalystwan/models/policy/list/local_app.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/local_domain.py b/catalystwan/models/policy/list/local_domain.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/mirror.py b/catalystwan/models/policy/list/mirror.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/policer.py b/catalystwan/models/policy/list/policer.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/port.py b/catalystwan/models/policy/list/port.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/preferred_color_group.py b/catalystwan/models/policy/list/preferred_color_group.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/prefix.py b/catalystwan/models/policy/list/prefix.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/protocol_name.py b/catalystwan/models/policy/list/protocol_name.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/region.py b/catalystwan/models/policy/list/region.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/site.py b/catalystwan/models/policy/list/site.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/sla.py b/catalystwan/models/policy/list/sla.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/tloc.py b/catalystwan/models/policy/list/tloc.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/url_allow_list.py b/catalystwan/models/policy/list/url_allow_list.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/url_block_list.py b/catalystwan/models/policy/list/url_block_list.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/vpn.py b/catalystwan/models/policy/list/vpn.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/list/zone.py b/catalystwan/models/policy/list/zone.py new file mode 100644 index 000000000..e69de29bb diff --git a/catalystwan/models/policy/lists_entries.py b/catalystwan/models/policy/lists_entries.py index 7ee837adb..542579c27 100644 --- a/catalystwan/models/policy/lists_entries.py +++ b/catalystwan/models/policy/lists_entries.py @@ -7,6 +7,7 @@ from pydantic import BaseModel, ConfigDict, Field, IPvAnyAddress, field_validator, model_validator from catalystwan.models.common import ( + EncapType, InterfaceType, IntRangeStr, IntStr, @@ -39,11 +40,6 @@ def check_loss_percent(loss_str: Optional[str]) -> Optional[str]: "remark", ] -EncapType = Literal[ - "ipsec", - "gre", -] - PathPreference = Literal[ "direct-path", "multi-hop-path", diff --git a/catalystwan/models/policy/policy_definition.py b/catalystwan/models/policy/policy_definition.py index dcdcd3399..181f20ed3 100644 --- a/catalystwan/models/policy/policy_definition.py +++ b/catalystwan/models/policy/policy_definition.py @@ -10,6 +10,7 @@ from typing_extensions import Annotated, Literal from catalystwan.models.common import ( + EncapType, ICMPMessageType, ServiceChainNumber, TLOCColor, @@ -18,7 +19,6 @@ str_as_uuid_list, ) from catalystwan.models.misc.application_protocols import ApplicationProtocol -from catalystwan.models.policy.lists_entries import EncapType from catalystwan.typed_list import DataSequence From eb5041495fa38ce67c12757712c36ee2994338a0 Mon Sep 17 00:00:00 2001 From: sbasan Date: Wed, 13 Mar 2024 23:45:40 +0100 Subject: [PATCH 02/36] separate endpoint from models, add app_probe list --- catalystwan/api/policy_api.py | 38 +++++++-------- .../configuration/policy/abstractions.py | 48 +++++++++++++++++++ .../policy/definition/access_control_list.py | 2 +- .../definition/access_control_list_ipv6.py | 2 +- .../policy/definition/control.py | 2 +- .../policy/definition/device_access.py | 2 +- .../policy/definition/device_access_ipv6.py | 2 +- .../policy/definition/hub_and_spoke.py | 2 +- .../configuration/policy/definition/mesh.py | 2 +- .../policy/definition/qos_map.py | 2 +- .../policy/definition/rewrite.py | 2 +- .../policy/definition/rule_set.py | 2 +- .../policy/definition/security_group.py | 2 +- .../policy/definition/traffic_data.py | 2 +- .../policy/definition/vpn_membership.py | 2 +- .../policy/definition/zone_based_firewall.py | 2 +- .../configuration/policy/list/app.py | 9 +--- .../configuration/policy/list/app_probe.py | 21 +++----- .../configuration/policy/list/as_path.py | 9 +--- .../configuration/policy/list/class_map.py | 9 +--- .../configuration/policy/list/color.py | 9 +--- .../configuration/policy/list/community.py | 9 +--- .../policy/list/data_ipv6_prefix.py | 9 +--- .../configuration/policy/list/data_prefix.py | 9 +--- .../policy/list/expanded_community.py | 9 +--- .../configuration/policy/list/fqdn.py | 9 +--- .../configuration/policy/list/geo_location.py | 9 +--- .../policy/list/ips_signature.py | 9 +--- .../configuration/policy/list/ipv6_prefix.py | 9 +--- .../configuration/policy/list/local_app.py | 9 +--- .../configuration/policy/list/local_domain.py | 9 +--- .../configuration/policy/list/mirror.py | 9 +--- .../configuration/policy/list/policer.py | 9 +--- .../configuration/policy/list/port.py | 9 +--- .../policy/list/preferred_color_group.py | 9 +--- .../configuration/policy/list/prefix.py | 9 +--- .../policy/list/protocol_name.py | 9 +--- .../configuration/policy/list/site.py | 9 +--- .../configuration/policy/list/sla.py | 9 +--- .../configuration/policy/list/tloc.py | 9 +--- .../policy/list/url_allow_list.py | 9 +--- .../policy/list/url_block_list.py | 9 +--- .../configuration/policy/list/vpn.py | 9 +--- .../configuration/policy/list/zone.py | 9 +--- catalystwan/models/policy/__init__.py | 3 +- catalystwan/models/policy/lists.py | 12 ----- .../models/policy/policy_definition.py | 20 +------- catalystwan/models/policy/policy_list.py | 22 +-------- 48 files changed, 145 insertions(+), 290 deletions(-) create mode 100644 catalystwan/endpoints/configuration/policy/abstractions.py diff --git a/catalystwan/api/policy_api.py b/catalystwan/api/policy_api.py index 81566c561..161d211c1 100644 --- a/catalystwan/api/policy_api.py +++ b/catalystwan/api/policy_api.py @@ -6,6 +6,7 @@ from uuid import UUID from catalystwan.api.task_status_api import Task +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints, PolicyListEndpoints from catalystwan.endpoints.configuration.policy.definition.access_control_list import ( AclPolicyGetResponse, ConfigurationPolicyAclDefinition, @@ -141,22 +142,9 @@ VSmartConnectivityStatus, ) from catalystwan.models.misc.application_protocols import ApplicationProtocol -from catalystwan.models.policy import AnyPolicyDefinition, AnyPolicyList -from catalystwan.models.policy.centralized import CentralizedPolicy, CentralizedPolicyEditPayload, CentralizedPolicyInfo -from catalystwan.models.policy.definition.access_control_list import AclPolicy -from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy -from catalystwan.models.policy.definition.control import ControlPolicy -from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy -from catalystwan.models.policy.definition.device_access_ipv6 import DeviceAccessIPv6Policy -from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy -from catalystwan.models.policy.definition.mesh import MeshPolicy -from catalystwan.models.policy.definition.qos_map import QoSMapPolicy -from catalystwan.models.policy.definition.rewrite import RewritePolicy -from catalystwan.models.policy.definition.rule_set import RuleSet -from catalystwan.models.policy.definition.security_group import SecurityGroup -from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy -from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy -from catalystwan.models.policy.lists import ( +from catalystwan.models.policy import ( + AnyPolicyDefinition, + AnyPolicyList, AppList, AppProbeClassList, ASPathList, @@ -174,7 +162,6 @@ LocalDomainList, MirrorList, PolicerList, - PolicyListBase, PortList, PreferredColorGroupList, PrefixList, @@ -188,6 +175,21 @@ VPNList, ZoneList, ) +from catalystwan.models.policy.centralized import CentralizedPolicy, CentralizedPolicyEditPayload, CentralizedPolicyInfo +from catalystwan.models.policy.definition.access_control_list import AclPolicy +from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy +from catalystwan.models.policy.definition.control import ControlPolicy +from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy +from catalystwan.models.policy.definition.device_access_ipv6 import DeviceAccessIPv6Policy +from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy +from catalystwan.models.policy.definition.mesh import MeshPolicy +from catalystwan.models.policy.definition.qos_map import QoSMapPolicy +from catalystwan.models.policy.definition.rewrite import RewritePolicy +from catalystwan.models.policy.definition.rule_set import RuleSet +from catalystwan.models.policy.definition.security_group import SecurityGroup +from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy +from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy +from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.localized import ( LocalizedPolicy, LocalizedPolicyDeviceInfo, @@ -197,10 +199,8 @@ from catalystwan.models.policy.policy_definition import ( PolicyDefinitionBase, PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionInfo, ) -from catalystwan.models.policy.policy_list import PolicyListEndpoints from catalystwan.models.policy.security import ( AnySecurityPolicy, AnySecurityPolicyInfo, diff --git a/catalystwan/endpoints/configuration/policy/abstractions.py b/catalystwan/endpoints/configuration/policy/abstractions.py new file mode 100644 index 000000000..94e8d2819 --- /dev/null +++ b/catalystwan/endpoints/configuration/policy/abstractions.py @@ -0,0 +1,48 @@ +from typing import Protocol +from uuid import UUID + +from pydantic import BaseModel + +from catalystwan.models.policy import AnyPolicyList +from catalystwan.models.policy.policy_definition import ( + PolicyDefinitionEditResponse, + PolicyDefinitionGetResponse, + PolicyDefinitionId, + PolicyDefinitionInfo, +) +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.typed_list import DataSequence + + +class PolicyListEndpoints(Protocol): + def create_policy_list(self, payload: AnyPolicyList) -> PolicyListId: + ... + + def delete_policy_list(self, id: UUID) -> None: + ... + + def edit_policy_list(self, id: UUID, payload: AnyPolicyList) -> None: + ... + + def get_lists_by_id(self, id: UUID) -> PolicyListInfo: + ... + + def get_policy_lists(self) -> DataSequence[PolicyListInfo]: + ... + + +class PolicyDefinitionEndpoints(Protocol): + def create_policy_definition(self, payload: BaseModel) -> PolicyDefinitionId: + ... + + def delete_policy_definition(self, id: UUID) -> None: + ... + + def edit_policy_definition(self, id: UUID, payload: BaseModel) -> PolicyDefinitionEditResponse: + ... + + def get_definitions(self) -> DataSequence[PolicyDefinitionInfo]: + ... + + def get_policy_definition(self, id: UUID) -> PolicyDefinitionGetResponse: + ... diff --git a/catalystwan/endpoints/configuration/policy/definition/access_control_list.py b/catalystwan/endpoints/configuration/policy/definition/access_control_list.py index 53dda8cca..1edd9be85 100644 --- a/catalystwan/endpoints/configuration/policy/definition/access_control_list.py +++ b/catalystwan/endpoints/configuration/policy/definition/access_control_list.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.access_control_list import AclPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py b/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py index b58147099..980dcc4d1 100644 --- a/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py +++ b/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/control.py b/catalystwan/endpoints/configuration/policy/definition/control.py index 5d5f6dc6a..a788b7630 100644 --- a/catalystwan/endpoints/configuration/policy/definition/control.py +++ b/catalystwan/endpoints/configuration/policy/definition/control.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.control import ControlPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/device_access.py b/catalystwan/endpoints/configuration/policy/definition/device_access.py index e929d812a..b86e26f54 100644 --- a/catalystwan/endpoints/configuration/policy/definition/device_access.py +++ b/catalystwan/endpoints/configuration/policy/definition/device_access.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py b/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py index defa7f721..8cd8006ae 100644 --- a/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py +++ b/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.device_access_ipv6 import DeviceAccessIPv6Policy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py b/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py index d15c4ba66..b124820da 100644 --- a/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py +++ b/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/mesh.py b/catalystwan/endpoints/configuration/policy/definition/mesh.py index fb999688f..ee89c4112 100644 --- a/catalystwan/endpoints/configuration/policy/definition/mesh.py +++ b/catalystwan/endpoints/configuration/policy/definition/mesh.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.mesh import MeshPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/qos_map.py b/catalystwan/endpoints/configuration/policy/definition/qos_map.py index 49fe7da2f..c5f27796d 100644 --- a/catalystwan/endpoints/configuration/policy/definition/qos_map.py +++ b/catalystwan/endpoints/configuration/policy/definition/qos_map.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.qos_map import QoSMapPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/rewrite.py b/catalystwan/endpoints/configuration/policy/definition/rewrite.py index 79308c135..ac1a95e6a 100644 --- a/catalystwan/endpoints/configuration/policy/definition/rewrite.py +++ b/catalystwan/endpoints/configuration/policy/definition/rewrite.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.rewrite import RewritePolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/rule_set.py b/catalystwan/endpoints/configuration/policy/definition/rule_set.py index 1e09afac3..4db698452 100644 --- a/catalystwan/endpoints/configuration/policy/definition/rule_set.py +++ b/catalystwan/endpoints/configuration/policy/definition/rule_set.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.rule_set import RuleSet from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/security_group.py b/catalystwan/endpoints/configuration/policy/definition/security_group.py index b57491649..22b411129 100644 --- a/catalystwan/endpoints/configuration/policy/definition/security_group.py +++ b/catalystwan/endpoints/configuration/policy/definition/security_group.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.security_group import SecurityGroup from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/traffic_data.py b/catalystwan/endpoints/configuration/policy/definition/traffic_data.py index 03f5e1039..ade21a240 100644 --- a/catalystwan/endpoints/configuration/policy/definition/traffic_data.py +++ b/catalystwan/endpoints/configuration/policy/definition/traffic_data.py @@ -5,10 +5,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.traffic_data import TrafficDataPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py b/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py index 352ff0ef8..606da00e6 100644 --- a/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py +++ b/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py b/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py index c78a6d1f3..9ba78575e 100644 --- a/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py +++ b/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py @@ -4,10 +4,10 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put +from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionEndpoints, PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, diff --git a/catalystwan/endpoints/configuration/policy/list/app.py b/catalystwan/endpoints/configuration/policy/list/app.py index eb39f8a83..474ee9e96 100644 --- a/catalystwan/endpoints/configuration/policy/list/app.py +++ b/catalystwan/endpoints/configuration/policy/list/app.py @@ -4,14 +4,9 @@ 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.lists import AppList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/app_probe.py b/catalystwan/endpoints/configuration/policy/list/app_probe.py index b51ce61be..44c378008 100644 --- a/catalystwan/endpoints/configuration/policy/list/app_probe.py +++ b/catalystwan/endpoints/configuration/policy/list/app_probe.py @@ -4,25 +4,16 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.lists import AppProbeClassList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, +from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints +from catalystwan.models.policy.list.app_probe import ( + AppProbeClassList, + AppProbeClassListEditPayload, + AppProbeClassListInfo, ) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class AppProbeClassListEditPayload(AppProbeClassList, PolicyListId): - pass - - -class AppProbeClassListInfo(AppProbeClassList, PolicyListInfo): - pass - - class ConfigurationPolicyAppProbeClassList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/appprobe") def create_policy_list(self, payload: AppProbeClassList) -> PolicyListId: diff --git a/catalystwan/endpoints/configuration/policy/list/as_path.py b/catalystwan/endpoints/configuration/policy/list/as_path.py index 6d28efffa..39c54465b 100644 --- a/catalystwan/endpoints/configuration/policy/list/as_path.py +++ b/catalystwan/endpoints/configuration/policy/list/as_path.py @@ -4,14 +4,9 @@ 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.lists import ASPathList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/class_map.py b/catalystwan/endpoints/configuration/policy/list/class_map.py index 45469301b..7b5ac2faf 100644 --- a/catalystwan/endpoints/configuration/policy/list/class_map.py +++ b/catalystwan/endpoints/configuration/policy/list/class_map.py @@ -4,14 +4,9 @@ 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.lists import ClassMapList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/color.py b/catalystwan/endpoints/configuration/policy/list/color.py index 920b899dc..2d1630f60 100644 --- a/catalystwan/endpoints/configuration/policy/list/color.py +++ b/catalystwan/endpoints/configuration/policy/list/color.py @@ -4,14 +4,9 @@ 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.lists import ColorList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/community.py b/catalystwan/endpoints/configuration/policy/list/community.py index 4fd995a5d..b8cacdc70 100644 --- a/catalystwan/endpoints/configuration/policy/list/community.py +++ b/catalystwan/endpoints/configuration/policy/list/community.py @@ -4,14 +4,9 @@ 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.lists import CommunityList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py b/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py index 767f05dbd..77383a295 100644 --- a/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py @@ -4,14 +4,9 @@ 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.lists import DataIPv6PrefixList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/data_prefix.py b/catalystwan/endpoints/configuration/policy/list/data_prefix.py index 8603730a9..cf062871b 100644 --- a/catalystwan/endpoints/configuration/policy/list/data_prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/data_prefix.py @@ -4,14 +4,9 @@ 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.lists import DataPrefixList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/expanded_community.py b/catalystwan/endpoints/configuration/policy/list/expanded_community.py index 939bbddc3..48836dba4 100644 --- a/catalystwan/endpoints/configuration/policy/list/expanded_community.py +++ b/catalystwan/endpoints/configuration/policy/list/expanded_community.py @@ -4,14 +4,9 @@ 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.lists import ExpandedCommunityList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/fqdn.py b/catalystwan/endpoints/configuration/policy/list/fqdn.py index 7b73d2680..c6bfe79ea 100644 --- a/catalystwan/endpoints/configuration/policy/list/fqdn.py +++ b/catalystwan/endpoints/configuration/policy/list/fqdn.py @@ -4,14 +4,9 @@ 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.lists import FQDNList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/geo_location.py b/catalystwan/endpoints/configuration/policy/list/geo_location.py index a227a5470..98b7bc4ad 100644 --- a/catalystwan/endpoints/configuration/policy/list/geo_location.py +++ b/catalystwan/endpoints/configuration/policy/list/geo_location.py @@ -4,14 +4,9 @@ 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.lists import GeoLocationList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/ips_signature.py b/catalystwan/endpoints/configuration/policy/list/ips_signature.py index c1f60c61f..c0437e0e0 100644 --- a/catalystwan/endpoints/configuration/policy/list/ips_signature.py +++ b/catalystwan/endpoints/configuration/policy/list/ips_signature.py @@ -4,14 +4,9 @@ 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.lists import IPSSignatureList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py b/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py index 9af6b8f90..78e70dde9 100644 --- a/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py @@ -4,14 +4,9 @@ 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.lists import IPv6PrefixList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/local_app.py b/catalystwan/endpoints/configuration/policy/list/local_app.py index 4d4954089..d7cbec87f 100644 --- a/catalystwan/endpoints/configuration/policy/list/local_app.py +++ b/catalystwan/endpoints/configuration/policy/list/local_app.py @@ -4,14 +4,9 @@ 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.lists import LocalAppList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/local_domain.py b/catalystwan/endpoints/configuration/policy/list/local_domain.py index 1359e5cba..eec81b933 100644 --- a/catalystwan/endpoints/configuration/policy/list/local_domain.py +++ b/catalystwan/endpoints/configuration/policy/list/local_domain.py @@ -4,14 +4,9 @@ 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.lists import LocalDomainList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/mirror.py b/catalystwan/endpoints/configuration/policy/list/mirror.py index ab0bb69d5..ab48672bb 100644 --- a/catalystwan/endpoints/configuration/policy/list/mirror.py +++ b/catalystwan/endpoints/configuration/policy/list/mirror.py @@ -4,14 +4,9 @@ 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.lists import MirrorList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/policer.py b/catalystwan/endpoints/configuration/policy/list/policer.py index 9166b20d9..9675d89b0 100644 --- a/catalystwan/endpoints/configuration/policy/list/policer.py +++ b/catalystwan/endpoints/configuration/policy/list/policer.py @@ -4,14 +4,9 @@ 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.lists import PolicerList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/port.py b/catalystwan/endpoints/configuration/policy/list/port.py index 6eb87fdd1..f87c76c44 100644 --- a/catalystwan/endpoints/configuration/policy/list/port.py +++ b/catalystwan/endpoints/configuration/policy/list/port.py @@ -4,14 +4,9 @@ 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.lists import PortList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py b/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py index 3cf8aa3a9..a6c19da22 100644 --- a/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py +++ b/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py @@ -4,14 +4,9 @@ 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.lists import PreferredColorGroupList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/prefix.py b/catalystwan/endpoints/configuration/policy/list/prefix.py index 64f6c584c..cdab743b4 100644 --- a/catalystwan/endpoints/configuration/policy/list/prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/prefix.py @@ -4,14 +4,9 @@ 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.lists import PrefixList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/protocol_name.py b/catalystwan/endpoints/configuration/policy/list/protocol_name.py index e5835f968..e4c288d11 100644 --- a/catalystwan/endpoints/configuration/policy/list/protocol_name.py +++ b/catalystwan/endpoints/configuration/policy/list/protocol_name.py @@ -4,14 +4,9 @@ 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.lists import ProtocolNameList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/site.py b/catalystwan/endpoints/configuration/policy/list/site.py index 004721360..bd7107b22 100644 --- a/catalystwan/endpoints/configuration/policy/list/site.py +++ b/catalystwan/endpoints/configuration/policy/list/site.py @@ -4,14 +4,9 @@ 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.lists import SiteList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/sla.py b/catalystwan/endpoints/configuration/policy/list/sla.py index 5764aa0fd..e3b5183e7 100644 --- a/catalystwan/endpoints/configuration/policy/list/sla.py +++ b/catalystwan/endpoints/configuration/policy/list/sla.py @@ -4,14 +4,9 @@ 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.lists import SLAClassList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/tloc.py b/catalystwan/endpoints/configuration/policy/list/tloc.py index 826197051..42a007fc8 100644 --- a/catalystwan/endpoints/configuration/policy/list/tloc.py +++ b/catalystwan/endpoints/configuration/policy/list/tloc.py @@ -4,14 +4,9 @@ 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.lists import TLOCList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/url_allow_list.py b/catalystwan/endpoints/configuration/policy/list/url_allow_list.py index 32d5c803a..fa252e37d 100644 --- a/catalystwan/endpoints/configuration/policy/list/url_allow_list.py +++ b/catalystwan/endpoints/configuration/policy/list/url_allow_list.py @@ -4,14 +4,9 @@ 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.lists import URLAllowList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/url_block_list.py b/catalystwan/endpoints/configuration/policy/list/url_block_list.py index 96c171539..09cf2bf94 100644 --- a/catalystwan/endpoints/configuration/policy/list/url_block_list.py +++ b/catalystwan/endpoints/configuration/policy/list/url_block_list.py @@ -4,14 +4,9 @@ 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.lists import URLBlockList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/vpn.py b/catalystwan/endpoints/configuration/policy/list/vpn.py index 0b1f50fae..abb23c042 100644 --- a/catalystwan/endpoints/configuration/policy/list/vpn.py +++ b/catalystwan/endpoints/configuration/policy/list/vpn.py @@ -6,14 +6,9 @@ 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.lists import VPNList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/endpoints/configuration/policy/list/zone.py b/catalystwan/endpoints/configuration/policy/list/zone.py index 96464e5c1..1c17fa51f 100644 --- a/catalystwan/endpoints/configuration/policy/list/zone.py +++ b/catalystwan/endpoints/configuration/policy/list/zone.py @@ -4,14 +4,9 @@ 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.lists import ZoneList -from catalystwan.models.policy.policy_list import ( - InfoTag, - PolicyListEndpoints, - PolicyListId, - PolicyListInfo, - PolicyListPreview, -) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview from catalystwan.typed_list import DataSequence diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 1a107b89b..b1d2f9042 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -6,6 +6,8 @@ from pydantic import Field from typing_extensions import Annotated +from catalystwan.models.policy.list.app_probe import AppProbeClassList + from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy from .definition.access_control_list_ipv6 import AclIPv6Policy @@ -23,7 +25,6 @@ from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( AppList, - AppProbeClassList, ASPathList, ClassMapList, ColorList, diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index f35841140..de30065f0 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -9,7 +9,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor, WellKnownBGPCommunities from catalystwan.models.policy.lists_entries import ( AppListEntry, - AppProbeClassListEntry, ASPathListEntry, ClassMapListEntry, ColorGroupPreference, @@ -222,17 +221,6 @@ class MirrorList(PolicyListBase): entries: List[MirrorListEntry] = [] -class AppProbeClassList(PolicyListBase): - type: Literal["appProbe"] = "appProbe" - entries: List[AppProbeClassListEntry] = [] - - def assign_forwarding_class(self, name: str) -> AppProbeClassListEntry: - # App probe class list must have only one entry! - entry = AppProbeClassListEntry(forwarding_class=name) - self._add_entry(entry, single=True) - return entry - - class SLAClassList(PolicyListBase): type: Literal["sla"] = "sla" entries: List[SLAClassListEntry] = [] diff --git a/catalystwan/models/policy/policy_definition.py b/catalystwan/models/policy/policy_definition.py index 181f20ed3..7a0d07151 100644 --- a/catalystwan/models/policy/policy_definition.py +++ b/catalystwan/models/policy/policy_definition.py @@ -3,7 +3,7 @@ import datetime from functools import wraps from ipaddress import IPv4Address, IPv4Network, IPv6Network -from typing import Any, Dict, List, MutableSequence, Optional, Protocol, Sequence, Set, Tuple, Union +from typing import Any, Dict, List, MutableSequence, Optional, Sequence, Set, Tuple, Union from uuid import UUID from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator @@ -19,7 +19,6 @@ str_as_uuid_list, ) from catalystwan.models.misc.application_protocols import ApplicationProtocol -from catalystwan.typed_list import DataSequence def port_set_and_ranges_to_str(ports: Set[int] = set(), port_ranges: List[Tuple[int, int]] = []) -> str: @@ -1146,20 +1145,3 @@ class PolicyDefinitionEditResponse(BaseModel): class PolicyDefinitionPreview(BaseModel): preview: str - - -class PolicyDefinitionEndpoints(Protocol): - def create_policy_definition(self, payload: BaseModel) -> PolicyDefinitionId: - ... - - def delete_policy_definition(self, id: UUID) -> None: - ... - - def edit_policy_definition(self, id: UUID, payload: BaseModel) -> PolicyDefinitionEditResponse: - ... - - def get_definitions(self) -> DataSequence[PolicyDefinitionInfo]: - ... - - def get_policy_definition(self, id: UUID) -> PolicyDefinitionGetResponse: - ... diff --git a/catalystwan/models/policy/policy_list.py b/catalystwan/models/policy/policy_list.py index 2b790a9e5..f829b411a 100644 --- a/catalystwan/models/policy/policy_list.py +++ b/catalystwan/models/policy/policy_list.py @@ -1,14 +1,11 @@ # Copyright 2023 Cisco Systems, Inc. and its affiliates import datetime -from typing import List, Optional, Protocol +from typing import List, Optional from uuid import UUID from pydantic import BaseModel, Field -from catalystwan.models.policy import AnyPolicyList -from catalystwan.typed_list import DataSequence - class InfoTag(BaseModel): info_tag: Optional[str] = Field("", alias="infoTag") @@ -30,20 +27,3 @@ class PolicyListInfo(PolicyListId, InfoTag): class PolicyListPreview(BaseModel): preview: str - - -class PolicyListEndpoints(Protocol): - def create_policy_list(self, payload: AnyPolicyList) -> PolicyListId: - ... - - def delete_policy_list(self, id: UUID) -> None: - ... - - def edit_policy_list(self, id: UUID, payload: AnyPolicyList) -> None: - ... - - def get_lists_by_id(self, id: UUID) -> PolicyListInfo: - ... - - def get_policy_lists(self) -> DataSequence[PolicyListInfo]: - ... From 19d3d9cf1f81b8245543e0f71c83ae51a1722af3 Mon Sep 17 00:00:00 2001 From: sbasan Date: Wed, 13 Mar 2024 23:55:41 +0100 Subject: [PATCH 03/36] separate app-list --- .../configuration/policy/list/app.py | 12 ++-------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/app_probe.py | 24 +++++++++++++++++++ catalystwan/models/policy/lists.py | 12 ---------- 4 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 catalystwan/models/policy/list/app_probe.py diff --git a/catalystwan/endpoints/configuration/policy/list/app.py b/catalystwan/endpoints/configuration/policy/list/app.py index 474ee9e96..878d56b4b 100644 --- a/catalystwan/endpoints/configuration/policy/list/app.py +++ b/catalystwan/endpoints/configuration/policy/list/app.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import AppList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.app import AppList, AppListEditPayload, AppListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class AppListEditPayload(AppList, PolicyListId): - pass - - -class AppListInfo(AppList, PolicyListInfo): - pass - - class ConfigurationPolicyApplicationList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/app") def create_policy_list(self, payload: AppList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index b1d2f9042..87ff380b8 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -6,6 +6,7 @@ from pydantic import Field from typing_extensions import Annotated +from catalystwan.models.policy.list.app import AppList from catalystwan.models.policy.list.app_probe import AppProbeClassList from .centralized import CentralizedPolicy, TrafficDataDirection @@ -24,7 +25,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - AppList, ASPathList, ClassMapList, ColorList, diff --git a/catalystwan/models/policy/list/app_probe.py b/catalystwan/models/policy/list/app_probe.py new file mode 100644 index 000000000..436c44982 --- /dev/null +++ b/catalystwan/models/policy/list/app_probe.py @@ -0,0 +1,24 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import AppProbeClassListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class AppProbeClassList(PolicyListBase): + type: Literal["appProbe"] = "appProbe" + entries: List[AppProbeClassListEntry] = [] + + def assign_forwarding_class(self, name: str) -> AppProbeClassListEntry: + # App probe class list must have only one entry! + entry = AppProbeClassListEntry(forwarding_class=name) + self._add_entry(entry, single=True) + return entry + + +class AppProbeClassListEditPayload(AppProbeClassList, PolicyListId): + pass + + +class AppProbeClassListInfo(AppProbeClassList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index de30065f0..f0ed8c9ee 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -8,7 +8,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor, WellKnownBGPCommunities from catalystwan.models.policy.lists_entries import ( - AppListEntry, ASPathListEntry, ClassMapListEntry, ColorGroupPreference, @@ -126,17 +125,6 @@ class LocalAppList(PolicyListBase): entries: List[LocalAppListEntry] = [] -class AppList(PolicyListBase): - type: Literal["app"] = "app" - entries: List[AppListEntry] = [] - - def add_app(self, app: str) -> None: - self._add_entry(AppListEntry(app=app)) - - def add_app_family(self, app_family: str) -> None: - self._add_entry(AppListEntry(app_family=app_family)) - - class ColorList(PolicyListBase): type: Literal["color"] = "color" entries: List[ColorListEntry] = [] From c0225c01d66b31e6cc2f7828f155db2526a42aad Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:04:40 +0100 Subject: [PATCH 04/36] separate as-path-list --- .../configuration/policy/list/as_path.py | 12 ++---------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/as_path.py | 18 ++++++++++++++++++ catalystwan/models/policy/lists.py | 6 ------ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/as_path.py b/catalystwan/endpoints/configuration/policy/list/as_path.py index 39c54465b..d643a061f 100644 --- a/catalystwan/endpoints/configuration/policy/list/as_path.py +++ b/catalystwan/endpoints/configuration/policy/list/as_path.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import ASPathList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.as_path import ASPathList, ASPathListEditPayload, ASPathListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class ASPathListEditPayload(ASPathList, PolicyListId): - pass - - -class ASPathListInfo(ASPathList, PolicyListInfo): - pass - - class ConfigurationPolicyASPathList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/aspath") def create_policy_list(self, payload: ASPathList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 87ff380b8..a49549090 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -8,6 +8,7 @@ from catalystwan.models.policy.list.app import AppList from catalystwan.models.policy.list.app_probe import AppProbeClassList +from catalystwan.models.policy.list.as_path import ASPathList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -25,7 +26,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - ASPathList, ClassMapList, ColorList, CommunityList, diff --git a/catalystwan/models/policy/list/as_path.py b/catalystwan/models/policy/list/as_path.py index e69de29bb..e8802e674 100644 --- a/catalystwan/models/policy/list/as_path.py +++ b/catalystwan/models/policy/list/as_path.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import ASPathListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class ASPathList(PolicyListBase): + type: Literal["asPath"] = "asPath" + entries: List[ASPathListEntry] = [] + + +class ASPathListEditPayload(ASPathList, PolicyListId): + pass + + +class ASPathListInfo(ASPathList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index f0ed8c9ee..f92107cdf 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -8,7 +8,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor, WellKnownBGPCommunities from catalystwan.models.policy.lists_entries import ( - ASPathListEntry, ClassMapListEntry, ColorGroupPreference, ColorListEntry, @@ -189,11 +188,6 @@ def police(self, burst: int, rate: int, exceed: PolicerExceedAction = "drop") -> self._add_entry(entry, single=True) -class ASPathList(PolicyListBase): - type: Literal["asPath"] = "asPath" - entries: List[ASPathListEntry] = [] - - class ClassMapList(PolicyListBase): type: Literal["class"] = "class" entries: List[ClassMapListEntry] = [] From 9b08773d378bb9591e0fcc8d4ebc85609b86007a Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:10:06 +0100 Subject: [PATCH 05/36] separate class-map-list --- .../configuration/policy/list/class_map.py | 12 ++-------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/class_map.py | 23 +++++++++++++++++++ catalystwan/models/policy/lists.py | 11 --------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/class_map.py b/catalystwan/endpoints/configuration/policy/list/class_map.py index 7b5ac2faf..fa68b803a 100644 --- a/catalystwan/endpoints/configuration/policy/list/class_map.py +++ b/catalystwan/endpoints/configuration/policy/list/class_map.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import ClassMapList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.class_map import ClassMapList, ClassMapListEditPayload, ClassMapListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class ClassMapListEditPayload(ClassMapList, PolicyListId): - pass - - -class ClassMapListInfo(ClassMapList, PolicyListInfo): - pass - - class ConfigurationPolicyForwardingClassList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/class") def create_policy_list(self, payload: ClassMapList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index a49549090..9b51d083f 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -9,6 +9,7 @@ from catalystwan.models.policy.list.app import AppList from catalystwan.models.policy.list.app_probe import AppProbeClassList from catalystwan.models.policy.list.as_path import ASPathList +from catalystwan.models.policy.list.class_map import ClassMapList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -26,7 +27,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - ClassMapList, ColorList, CommunityList, DataIPv6PrefixList, diff --git a/catalystwan/models/policy/list/class_map.py b/catalystwan/models/policy/list/class_map.py index e69de29bb..50ee4ba09 100644 --- a/catalystwan/models/policy/list/class_map.py +++ b/catalystwan/models/policy/list/class_map.py @@ -0,0 +1,23 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import ClassMapListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class ClassMapList(PolicyListBase): + type: Literal["class"] = "class" + entries: List[ClassMapListEntry] = [] + + def assign_queue(self, queue: int) -> None: + # Class map list must have only one entry! + entry = ClassMapListEntry(queue=queue) + self._add_entry(entry, single=True) + + +class ClassMapListEditPayload(ClassMapList, PolicyListId): + pass + + +class ClassMapListInfo(ClassMapList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index f92107cdf..bb569016f 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -8,7 +8,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor, WellKnownBGPCommunities from catalystwan.models.policy.lists_entries import ( - ClassMapListEntry, ColorGroupPreference, ColorListEntry, CommunityListEntry, @@ -188,16 +187,6 @@ def police(self, burst: int, rate: int, exceed: PolicerExceedAction = "drop") -> self._add_entry(entry, single=True) -class ClassMapList(PolicyListBase): - type: Literal["class"] = "class" - entries: List[ClassMapListEntry] = [] - - def assign_queue(self, queue: int) -> None: - # Class map list must have only one entry! - entry = ClassMapListEntry(queue=queue) - self._add_entry(entry, single=True) - - class MirrorList(PolicyListBase): type: Literal["mirror"] = "mirror" entries: List[MirrorListEntry] = [] From 2a303b1a1778041865c0e1d09d679b7d515f1bfa Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:24:29 +0100 Subject: [PATCH 06/36] separate community-list, expanded-community-list --- .../configuration/policy/list/color.py | 12 +----- .../configuration/policy/list/community.py | 12 +----- .../policy/list/expanded_community.py | 16 +++----- catalystwan/models/policy/__init__.py | 5 +-- catalystwan/models/policy/list/color.py | 22 ++++++++++ catalystwan/models/policy/list/communities.py | 40 +++++++++++++++++++ catalystwan/models/policy/list/community.py | 0 catalystwan/models/policy/lists.py | 30 +------------- 8 files changed, 75 insertions(+), 62 deletions(-) create mode 100644 catalystwan/models/policy/list/communities.py delete mode 100644 catalystwan/models/policy/list/community.py diff --git a/catalystwan/endpoints/configuration/policy/list/color.py b/catalystwan/endpoints/configuration/policy/list/color.py index 2d1630f60..135120e50 100644 --- a/catalystwan/endpoints/configuration/policy/list/color.py +++ b/catalystwan/endpoints/configuration/policy/list/color.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import ColorList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.color import ColorList, ColorListEditPayload, ColorListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class ColorListEditPayload(ColorList, PolicyListId): - pass - - -class ColorListInfo(ColorList, PolicyListInfo): - pass - - class ConfigurationPolicyColorList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/color") def create_policy_list(self, payload: ColorList) -> PolicyListId: diff --git a/catalystwan/endpoints/configuration/policy/list/community.py b/catalystwan/endpoints/configuration/policy/list/community.py index b8cacdc70..14fa31150 100644 --- a/catalystwan/endpoints/configuration/policy/list/community.py +++ b/catalystwan/endpoints/configuration/policy/list/community.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import CommunityList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.communities import CommunityList, CommunityListEditPayload, CommunityListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class CommunityListEditPayload(CommunityList, PolicyListId): - pass - - -class CommunityListInfo(CommunityList, PolicyListInfo): - pass - - class ConfigurationPolicyCommunityList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/community") def create_policy_list(self, payload: CommunityList) -> PolicyListId: diff --git a/catalystwan/endpoints/configuration/policy/list/expanded_community.py b/catalystwan/endpoints/configuration/policy/list/expanded_community.py index 48836dba4..0c1d81a34 100644 --- a/catalystwan/endpoints/configuration/policy/list/expanded_community.py +++ b/catalystwan/endpoints/configuration/policy/list/expanded_community.py @@ -5,19 +5,15 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import ExpandedCommunityList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.communities import ( + ExpandedCommunityList, + ExpandedCommunityListEditPayload, + ExpandedCommunityListInfo, +) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class ExpandedCommunityListEditPayload(ExpandedCommunityList, PolicyListId): - pass - - -class ExpandedCommunityListInfo(ExpandedCommunityList, PolicyListInfo): - pass - - class ConfigurationPolicyExpandedCommunityList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/expandedcommunity") def create_policy_list(self, payload: ExpandedCommunityList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 9b51d083f..531840bb5 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -10,6 +10,8 @@ from catalystwan.models.policy.list.app_probe import AppProbeClassList from catalystwan.models.policy.list.as_path import ASPathList from catalystwan.models.policy.list.class_map import ClassMapList +from catalystwan.models.policy.list.color import ColorList +from catalystwan.models.policy.list.communities import CommunityList, ExpandedCommunityList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -27,11 +29,8 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - ColorList, - CommunityList, DataIPv6PrefixList, DataPrefixList, - ExpandedCommunityList, FQDNList, GeoLocationList, IPSSignatureList, diff --git a/catalystwan/models/policy/list/color.py b/catalystwan/models/policy/list/color.py index e69de29bb..99cdd6937 100644 --- a/catalystwan/models/policy/list/color.py +++ b/catalystwan/models/policy/list/color.py @@ -0,0 +1,22 @@ +from typing import List, Literal + +from catalystwan.models.common import TLOCColor +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import ColorListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class ColorList(PolicyListBase): + type: Literal["color"] = "color" + entries: List[ColorListEntry] = [] + + def add_color(self, color: TLOCColor) -> None: + self._add_entry(ColorListEntry(color=color)) + + +class ColorListEditPayload(ColorList, PolicyListId): + pass + + +class ColorListInfo(ColorList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/list/communities.py b/catalystwan/models/policy/list/communities.py new file mode 100644 index 000000000..211bda895 --- /dev/null +++ b/catalystwan/models/policy/list/communities.py @@ -0,0 +1,40 @@ +from typing import List, Literal + +from catalystwan.models.common import WellKnownBGPCommunities +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import CommunityListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class _CommunityListBase(PolicyListBase): + entries: List[CommunityListEntry] = [] + + def add_well_known_community(self, community: WellKnownBGPCommunities) -> None: + self._add_entry(CommunityListEntry(community=community)) + + def add_community(self, as_number: int, community_number: int) -> None: + self._add_entry(CommunityListEntry(community=f"{as_number}:{community_number}")) + + +class CommunityList(_CommunityListBase): + type: Literal["community"] = "community" + + +class CommunityListEditPayload(CommunityList, PolicyListId): + pass + + +class CommunityListInfo(CommunityList, PolicyListInfo): + pass + + +class ExpandedCommunityList(_CommunityListBase): + type: Literal["expandedCommunity"] = "expandedCommunity" + + +class ExpandedCommunityListEditPayload(ExpandedCommunityList, PolicyListId): + pass + + +class ExpandedCommunityListInfo(ExpandedCommunityList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/list/community.py b/catalystwan/models/policy/list/community.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index bb569016f..1fe20dfd1 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -6,11 +6,9 @@ from pydantic import BaseModel, Field -from catalystwan.models.common import InterfaceType, TLOCColor, WellKnownBGPCommunities +from catalystwan.models.common import InterfaceType, TLOCColor from catalystwan.models.policy.lists_entries import ( ColorGroupPreference, - ColorListEntry, - CommunityListEntry, DataIPv6PrefixListEntry, DataPrefixListEntry, EncapType, @@ -123,14 +121,6 @@ class LocalAppList(PolicyListBase): entries: List[LocalAppListEntry] = [] -class ColorList(PolicyListBase): - type: Literal["color"] = "color" - entries: List[ColorListEntry] = [] - - def add_color(self, color: TLOCColor) -> None: - self._add_entry(ColorListEntry(color=color)) - - class DataIPv6PrefixList(PolicyListBase): type: Literal["dataIpv6Prefix"] = "dataIpv6Prefix" entries: List[DataIPv6PrefixListEntry] = [] @@ -159,24 +149,6 @@ class URLBlockList(PolicyListBase): entries: List[URLListEntry] = [] -class _CommunityListBase(PolicyListBase): - entries: List[CommunityListEntry] = [] - - def add_well_known_community(self, community: WellKnownBGPCommunities) -> None: - self._add_entry(CommunityListEntry(community=community)) - - def add_community(self, as_number: int, community_number: int) -> None: - self._add_entry(CommunityListEntry(community=f"{as_number}:{community_number}")) - - -class CommunityList(_CommunityListBase): - type: Literal["community"] = "community" - - -class ExpandedCommunityList(_CommunityListBase): - type: Literal["expandedCommunity"] = "expandedCommunity" - - class PolicerList(PolicyListBase): type: Literal["policer"] = "policer" entries: List[PolicerListEntry] = [] From 79ab87c36c4c68755339e04c2c5e2b9abd685fbb Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:33:32 +0100 Subject: [PATCH 07/36] separate data-ipv6-prefix-list --- .../policy/list/data_ipv6_prefix.py | 16 +++++--------- catalystwan/models/policy/__init__.py | 2 +- .../models/policy/list/data_ipv6_prefix.py | 22 +++++++++++++++++++ catalystwan/models/policy/lists.py | 9 -------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py b/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py index 77383a295..ec7a7cadb 100644 --- a/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/data_ipv6_prefix.py @@ -5,19 +5,15 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import DataIPv6PrefixList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.data_ipv6_prefix import ( + DataIPv6PrefixList, + DataIPv6PrefixListEditPayload, + DataIPv6PrefixListInfo, +) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class DataIPv6PrefixListEditPayload(DataIPv6PrefixList, PolicyListId): - pass - - -class DataIPv6PrefixListInfo(DataIPv6PrefixList, PolicyListInfo): - pass - - class ConfigurationPolicyDataIPv6PrefixList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/dataipv6prefix") def create_policy_list(self, payload: DataIPv6PrefixList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 531840bb5..eab86488e 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -12,6 +12,7 @@ from catalystwan.models.policy.list.class_map import ClassMapList from catalystwan.models.policy.list.color import ColorList from catalystwan.models.policy.list.communities import CommunityList, ExpandedCommunityList +from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -29,7 +30,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - DataIPv6PrefixList, DataPrefixList, FQDNList, GeoLocationList, diff --git a/catalystwan/models/policy/list/data_ipv6_prefix.py b/catalystwan/models/policy/list/data_ipv6_prefix.py index e69de29bb..92e936e3b 100644 --- a/catalystwan/models/policy/list/data_ipv6_prefix.py +++ b/catalystwan/models/policy/list/data_ipv6_prefix.py @@ -0,0 +1,22 @@ +from ipaddress import IPv6Interface +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import DataIPv6PrefixListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class DataIPv6PrefixList(PolicyListBase): + type: Literal["dataIpv6Prefix"] = "dataIpv6Prefix" + entries: List[DataIPv6PrefixListEntry] = [] + + def add_prefix(self, ipv6_prefix: IPv6Interface) -> None: + self._add_entry(DataIPv6PrefixListEntry(ipv6_prefix=ipv6_prefix)) + + +class DataIPv6PrefixListEditPayload(DataIPv6PrefixList, PolicyListId): + pass + + +class DataIPv6PrefixListInfo(DataIPv6PrefixList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 1fe20dfd1..af2f747de 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -9,7 +9,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor from catalystwan.models.policy.lists_entries import ( ColorGroupPreference, - DataIPv6PrefixListEntry, DataPrefixListEntry, EncapType, FQDNListEntry, @@ -121,14 +120,6 @@ class LocalAppList(PolicyListBase): entries: List[LocalAppListEntry] = [] -class DataIPv6PrefixList(PolicyListBase): - type: Literal["dataIpv6Prefix"] = "dataIpv6Prefix" - entries: List[DataIPv6PrefixListEntry] = [] - - def add_prefix(self, ipv6_prefix: IPv6Interface) -> None: - self._add_entry(DataIPv6PrefixListEntry(ipv6_prefix=ipv6_prefix)) - - class LocalDomainList(PolicyListBase): type: Literal["localDomain"] = "localDomain" entries: List[LocalDomainListEntry] = [] From f8d1a98a3f61e5add6fe8f240c38fce9b4973714 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:38:39 +0100 Subject: [PATCH 08/36] separate data-prefix-list --- .../configuration/policy/list/data_prefix.py | 12 ++-------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/data_prefix.py | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/data_prefix.py b/catalystwan/endpoints/configuration/policy/list/data_prefix.py index cf062871b..458246662 100644 --- a/catalystwan/endpoints/configuration/policy/list/data_prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/data_prefix.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import DataPrefixList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.data_prefix import DataPrefixList, DataPrefixListEditPayload, DataPrefixListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class DataPrefixListEditPayload(DataPrefixList, PolicyListId): - pass - - -class DataPrefixListInfo(DataPrefixList, PolicyListInfo): - pass - - class ConfigurationPolicyDataPrefixList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/dataprefix") def create_policy_list(self, payload: DataPrefixList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index eab86488e..efa50b554 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -13,6 +13,7 @@ from catalystwan.models.policy.list.color import ColorList from catalystwan.models.policy.list.communities import CommunityList, ExpandedCommunityList from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixList +from catalystwan.models.policy.list.data_prefix import DataPrefixList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -30,7 +31,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - DataPrefixList, FQDNList, GeoLocationList, IPSSignatureList, diff --git a/catalystwan/models/policy/list/data_prefix.py b/catalystwan/models/policy/list/data_prefix.py index e69de29bb..52f91606d 100644 --- a/catalystwan/models/policy/list/data_prefix.py +++ b/catalystwan/models/policy/list/data_prefix.py @@ -0,0 +1,22 @@ +from ipaddress import IPv4Network +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import DataPrefixListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class DataPrefixList(PolicyListBase): + type: Literal["dataPrefix"] = "dataPrefix" + entries: List[DataPrefixListEntry] = [] + + def add_prefix(self, ip_prefix: IPv4Network) -> None: + self._add_entry(DataPrefixListEntry(ip_prefix=ip_prefix)) + + +class DataPrefixListEditPayload(DataPrefixList, PolicyListId): + pass + + +class DataPrefixListInfo(DataPrefixList, PolicyListInfo): + pass From 9c913e7db76dbafe3154c9dd9b410e0778491046 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:43:44 +0100 Subject: [PATCH 09/36] separate fqdn-list --- .../configuration/policy/list/fqdn.py | 12 ++---------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/fqdn.py | 18 ++++++++++++++++++ catalystwan/models/policy/lists.py | 15 --------------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/fqdn.py b/catalystwan/endpoints/configuration/policy/list/fqdn.py index c6bfe79ea..f796c611b 100644 --- a/catalystwan/endpoints/configuration/policy/list/fqdn.py +++ b/catalystwan/endpoints/configuration/policy/list/fqdn.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import FQDNList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.fqdn import FQDNList, FQDNListEditPayload, FQDNListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class FQDNListEditPayload(FQDNList, PolicyListId): - pass - - -class FQDNListInfo(FQDNList, PolicyListInfo): - pass - - class ConfigurationPolicyFQDNList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/fqdn") def create_policy_list(self, payload: FQDNList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index efa50b554..1cecddb11 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -14,6 +14,7 @@ from catalystwan.models.policy.list.communities import CommunityList, ExpandedCommunityList from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixList from catalystwan.models.policy.list.data_prefix import DataPrefixList +from catalystwan.models.policy.list.fqdn import FQDNList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -31,7 +32,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - FQDNList, GeoLocationList, IPSSignatureList, IPv6PrefixList, diff --git a/catalystwan/models/policy/list/fqdn.py b/catalystwan/models/policy/list/fqdn.py index e69de29bb..100f193d7 100644 --- a/catalystwan/models/policy/list/fqdn.py +++ b/catalystwan/models/policy/list/fqdn.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import FQDNListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class FQDNList(PolicyListBase): + type: Literal["fqdn"] = "fqdn" + entries: List[FQDNListEntry] = [] + + +class FQDNListEditPayload(FQDNList, PolicyListId): + pass + + +class FQDNListInfo(FQDNList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index af2f747de..313988271 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -9,9 +9,7 @@ from catalystwan.models.common import InterfaceType, TLOCColor from catalystwan.models.policy.lists_entries import ( ColorGroupPreference, - DataPrefixListEntry, EncapType, - FQDNListEntry, GeoLocationListEntry, IPSSignatureListEntry, IPv6PrefixListEntry, @@ -51,14 +49,6 @@ def _add_entry(self, entry: Any, single: bool = False) -> None: self.entries.append(entry) -class DataPrefixList(PolicyListBase): - type: Literal["dataPrefix"] = "dataPrefix" - entries: List[DataPrefixListEntry] = [] - - def add_prefix(self, ip_prefix: IPv4Network) -> None: - self._add_entry(DataPrefixListEntry(ip_prefix=ip_prefix)) - - class SiteList(PolicyListBase): type: Literal["site"] = "site" entries: List[SiteListEntry] = [] @@ -95,11 +85,6 @@ def assign_interfaces(self, ifs: Set[InterfaceType]) -> None: self.entries = [ZoneListEntry(interface=interface) for interface in ifs] -class FQDNList(PolicyListBase): - type: Literal["fqdn"] = "fqdn" - entries: List[FQDNListEntry] = [] - - class GeoLocationList(PolicyListBase): type: Literal["geoLocation"] = "geoLocation" entries: List[GeoLocationListEntry] = [] From 2198dbd92f88c469d4d65ba042ae7f6b5e7366dd Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:47:45 +0100 Subject: [PATCH 10/36] separate geo-location-list --- .../configuration/policy/list/geo_location.py | 12 ++---------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/geo_location.py | 18 ++++++++++++++++++ catalystwan/models/policy/lists.py | 6 ------ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/geo_location.py b/catalystwan/endpoints/configuration/policy/list/geo_location.py index 98b7bc4ad..2c7d4748b 100644 --- a/catalystwan/endpoints/configuration/policy/list/geo_location.py +++ b/catalystwan/endpoints/configuration/policy/list/geo_location.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import GeoLocationList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.geo_location import GeoLocationList, GeoLocationListEditPayload, GeoLocationListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class GeoLocationListEditPayload(GeoLocationList, PolicyListId): - pass - - -class GeoLocationListInfo(GeoLocationList, PolicyListInfo): - pass - - class ConfigurationPolicyGeoLocationList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/geolocation") def create_policy_list(self, payload: GeoLocationList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 1cecddb11..1c1ab3b38 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -15,6 +15,7 @@ from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixList from catalystwan.models.policy.list.data_prefix import DataPrefixList from catalystwan.models.policy.list.fqdn import FQDNList +from catalystwan.models.policy.list.geo_location import GeoLocationList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -32,7 +33,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - GeoLocationList, IPSSignatureList, IPv6PrefixList, LocalAppList, diff --git a/catalystwan/models/policy/list/geo_location.py b/catalystwan/models/policy/list/geo_location.py index e69de29bb..de97a31f3 100644 --- a/catalystwan/models/policy/list/geo_location.py +++ b/catalystwan/models/policy/list/geo_location.py @@ -0,0 +1,18 @@ +from typing import Literal, List + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import GeoLocationListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class GeoLocationList(PolicyListBase): + type: Literal["geoLocation"] = "geoLocation" + entries: List[GeoLocationListEntry] = [] + + +class GeoLocationListEditPayload(GeoLocationList, PolicyListId): + pass + + +class GeoLocationListInfo(GeoLocationList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 313988271..e93ebad98 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -10,7 +10,6 @@ from catalystwan.models.policy.lists_entries import ( ColorGroupPreference, EncapType, - GeoLocationListEntry, IPSSignatureListEntry, IPv6PrefixListEntry, LocalAppListEntry, @@ -85,11 +84,6 @@ def assign_interfaces(self, ifs: Set[InterfaceType]) -> None: self.entries = [ZoneListEntry(interface=interface) for interface in ifs] -class GeoLocationList(PolicyListBase): - type: Literal["geoLocation"] = "geoLocation" - entries: List[GeoLocationListEntry] = [] - - class PortList(PolicyListBase): type: Literal["port"] = "port" entries: List[PortListEntry] = [] From 22e9bc0edb62b14f54a6e00b35e4395344719b58 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 00:52:54 +0100 Subject: [PATCH 11/36] separate ips-signature-list --- .../configuration/policy/list/ips_signature.py | 16 ++++++---------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/geo_location.py | 2 +- .../models/policy/list/ips_signature.py | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/ips_signature.py b/catalystwan/endpoints/configuration/policy/list/ips_signature.py index c0437e0e0..040f2f400 100644 --- a/catalystwan/endpoints/configuration/policy/list/ips_signature.py +++ b/catalystwan/endpoints/configuration/policy/list/ips_signature.py @@ -5,19 +5,15 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import IPSSignatureList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.ips_signature import ( + IPSSignatureList, + IPSSignatureListEditPayload, + IPSSignatureListInfo, +) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class IPSSignatureListEditPayload(IPSSignatureList, PolicyListId): - pass - - -class IPSSignatureListInfo(IPSSignatureList, PolicyListInfo): - pass - - class ConfigurationPolicyIPSSignatureList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/ipssignature") def create_policy_list(self, payload: IPSSignatureList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 1c1ab3b38..30a349b17 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -16,6 +16,7 @@ from catalystwan.models.policy.list.data_prefix import DataPrefixList from catalystwan.models.policy.list.fqdn import FQDNList from catalystwan.models.policy.list.geo_location import GeoLocationList +from catalystwan.models.policy.list.ips_signature import IPSSignatureList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -33,7 +34,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - IPSSignatureList, IPv6PrefixList, LocalAppList, LocalDomainList, diff --git a/catalystwan/models/policy/list/geo_location.py b/catalystwan/models/policy/list/geo_location.py index de97a31f3..f5589f915 100644 --- a/catalystwan/models/policy/list/geo_location.py +++ b/catalystwan/models/policy/list/geo_location.py @@ -1,4 +1,4 @@ -from typing import Literal, List +from typing import List, Literal from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import GeoLocationListEntry diff --git a/catalystwan/models/policy/list/ips_signature.py b/catalystwan/models/policy/list/ips_signature.py index e69de29bb..31ae71dde 100644 --- a/catalystwan/models/policy/list/ips_signature.py +++ b/catalystwan/models/policy/list/ips_signature.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import IPSSignatureListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class IPSSignatureList(PolicyListBase): + type: Literal["ipsSignature"] = "ipsSignature" + entries: List[IPSSignatureListEntry] = [] + + +class IPSSignatureListEditPayload(IPSSignatureList, PolicyListId): + pass + + +class IPSSignatureListInfo(IPSSignatureList, PolicyListInfo): + pass From 404a299d9eff7a054057ef1d2e0f099e71f1aba4 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:02:10 +0100 Subject: [PATCH 12/36] separate ipv6-prefix-list --- .../configuration/policy/list/ipv6_prefix.py | 12 ++-------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/communities.py | 6 ++--- catalystwan/models/policy/list/ipv6_prefix.py | 22 +++++++++++++++++++ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py b/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py index 78e70dde9..8f9030be4 100644 --- a/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/ipv6_prefix.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import IPv6PrefixList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixList, IPv6PrefixListEditPayload, IPv6PrefixListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class IPv6PrefixListEditPayload(IPv6PrefixList, PolicyListId): - pass - - -class IPv6PrefixListInfo(IPv6PrefixList, PolicyListInfo): - pass - - class ConfigurationPolicyIPv6PrefixList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/ipv6prefix") def create_policy_list(self, payload: IPv6PrefixList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 30a349b17..f909a6393 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -17,6 +17,7 @@ from catalystwan.models.policy.list.fqdn import FQDNList from catalystwan.models.policy.list.geo_location import GeoLocationList from catalystwan.models.policy.list.ips_signature import IPSSignatureList +from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -34,7 +35,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - IPv6PrefixList, LocalAppList, LocalDomainList, MirrorList, diff --git a/catalystwan/models/policy/list/communities.py b/catalystwan/models/policy/list/communities.py index 211bda895..5b174cb0d 100644 --- a/catalystwan/models/policy/list/communities.py +++ b/catalystwan/models/policy/list/communities.py @@ -6,7 +6,7 @@ from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo -class _CommunityListBase(PolicyListBase): +class CommunityListBase(PolicyListBase): entries: List[CommunityListEntry] = [] def add_well_known_community(self, community: WellKnownBGPCommunities) -> None: @@ -16,7 +16,7 @@ def add_community(self, as_number: int, community_number: int) -> None: self._add_entry(CommunityListEntry(community=f"{as_number}:{community_number}")) -class CommunityList(_CommunityListBase): +class CommunityList(CommunityListBase): type: Literal["community"] = "community" @@ -28,7 +28,7 @@ class CommunityListInfo(CommunityList, PolicyListInfo): pass -class ExpandedCommunityList(_CommunityListBase): +class ExpandedCommunityList(CommunityListBase): type: Literal["expandedCommunity"] = "expandedCommunity" diff --git a/catalystwan/models/policy/list/ipv6_prefix.py b/catalystwan/models/policy/list/ipv6_prefix.py index e69de29bb..7f9601927 100644 --- a/catalystwan/models/policy/list/ipv6_prefix.py +++ b/catalystwan/models/policy/list/ipv6_prefix.py @@ -0,0 +1,22 @@ +from ipaddress import IPv6Interface +from typing import List, Literal, Optional + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import IPv6PrefixListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class IPv6PrefixList(PolicyListBase): + type: Literal["ipv6prefix"] = "ipv6prefix" + entries: List[IPv6PrefixListEntry] = [] + + def add_prefix(self, prefix: IPv6Interface, ge: Optional[int] = None, le: Optional[int] = None) -> None: + self._add_entry(IPv6PrefixListEntry(ipv6_prefix=prefix, ge=ge, le=le)) + + +class IPv6PrefixListEditPayload(IPv6PrefixList, PolicyListId): + pass + + +class IPv6PrefixListInfo(IPv6PrefixList, PolicyListInfo): + pass From 3b410a70e6c73d5e8635832405532d37c608ec28 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:05:34 +0100 Subject: [PATCH 13/36] separate local-app-list --- .../configuration/policy/list/local_app.py | 12 ++-------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/local_app.py | 18 +++++++++++++++ catalystwan/models/policy/lists.py | 23 +------------------ 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/local_app.py b/catalystwan/endpoints/configuration/policy/list/local_app.py index d7cbec87f..1c00b5647 100644 --- a/catalystwan/endpoints/configuration/policy/list/local_app.py +++ b/catalystwan/endpoints/configuration/policy/list/local_app.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import LocalAppList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.local_app import LocalAppList, LocalAppListEditPayload, LocalAppListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class LocalAppListEditPayload(LocalAppList, PolicyListId): - pass - - -class LocalAppListInfo(LocalAppList, PolicyListInfo): - pass - - class ConfigurationPolicyLocalAppList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/localapp") def create_policy_list(self, payload: LocalAppList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index f909a6393..81656f083 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -18,6 +18,7 @@ from catalystwan.models.policy.list.geo_location import GeoLocationList from catalystwan.models.policy.list.ips_signature import IPSSignatureList from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixList +from catalystwan.models.policy.list.local_app import LocalAppList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -35,7 +36,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - LocalAppList, LocalDomainList, MirrorList, PolicerList, diff --git a/catalystwan/models/policy/list/local_app.py b/catalystwan/models/policy/list/local_app.py index e69de29bb..b3e43a872 100644 --- a/catalystwan/models/policy/list/local_app.py +++ b/catalystwan/models/policy/list/local_app.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import LocalAppListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class LocalAppList(PolicyListBase): + type: Literal["localApp"] = "localApp" + entries: List[LocalAppListEntry] = [] + + +class LocalAppListEditPayload(LocalAppList, PolicyListId): + pass + + +class LocalAppListInfo(LocalAppList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index e93ebad98..f2d26f844 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -1,6 +1,6 @@ # Copyright 2023 Cisco Systems, Inc. and its affiliates -from ipaddress import IPv4Address, IPv4Network, IPv6Interface +from ipaddress import IPv4Address, IPv4Network from typing import Any, List, Literal, Optional, Set, Tuple from uuid import UUID @@ -10,9 +10,6 @@ from catalystwan.models.policy.lists_entries import ( ColorGroupPreference, EncapType, - IPSSignatureListEntry, - IPv6PrefixListEntry, - LocalAppListEntry, LocalDomainListEntry, MirrorListEntry, PathPreference, @@ -94,21 +91,11 @@ class ProtocolNameList(PolicyListBase): entries: List[ProtocolNameListEntry] = [] -class LocalAppList(PolicyListBase): - type: Literal["localApp"] = "localApp" - entries: List[LocalAppListEntry] = [] - - class LocalDomainList(PolicyListBase): type: Literal["localDomain"] = "localDomain" entries: List[LocalDomainListEntry] = [] -class IPSSignatureList(PolicyListBase): - type: Literal["ipsSignature"] = "ipsSignature" - entries: List[IPSSignatureListEntry] = [] - - class URLAllowList(PolicyListBase): type: Literal["urlWhiteList"] = "urlWhiteList" entries: List[URLListEntry] = [] @@ -210,14 +197,6 @@ def add_prefix(self, prefix: IPv4Network, ge: Optional[int] = None, le: Optional self._add_entry(PrefixListEntry(ip_prefix=prefix, ge=ge, le=le)) -class IPv6PrefixList(PolicyListBase): - type: Literal["ipv6prefix"] = "ipv6prefix" - entries: List[IPv6PrefixListEntry] = [] - - def add_prefix(self, prefix: IPv6Interface, ge: Optional[int] = None, le: Optional[int] = None) -> None: - self._add_entry(IPv6PrefixListEntry(ipv6_prefix=prefix, ge=ge, le=le)) - - class RegionList(PolicyListBase): type: Literal["region"] = "region" entries: List[RegionListEntry] = [] From 19182ad3243704b44d9b75a86e2ab3ace032caa0 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:08:41 +0100 Subject: [PATCH 14/36] separate local-domain-list --- .../configuration/policy/list/local_domain.py | 12 ++---------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/local_domain.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/local_domain.py b/catalystwan/endpoints/configuration/policy/list/local_domain.py index eec81b933..4b2de258b 100644 --- a/catalystwan/endpoints/configuration/policy/list/local_domain.py +++ b/catalystwan/endpoints/configuration/policy/list/local_domain.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import LocalDomainList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.local_domain import LocalDomainList, LocalDomainListEditPayload, LocalDomainListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class LocalDomainListEditPayload(LocalDomainList, PolicyListId): - pass - - -class LocalDomainListInfo(LocalDomainList, PolicyListInfo): - pass - - class ConfigurationPolicyLocalDomainList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/localdomain") def create_policy_list(self, payload: LocalDomainList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 81656f083..9882cf2d6 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -19,6 +19,7 @@ from catalystwan.models.policy.list.ips_signature import IPSSignatureList from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixList from catalystwan.models.policy.list.local_app import LocalAppList +from catalystwan.models.policy.list.local_domain import LocalDomainList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -36,7 +37,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - LocalDomainList, MirrorList, PolicerList, PortList, diff --git a/catalystwan/models/policy/list/local_domain.py b/catalystwan/models/policy/list/local_domain.py index e69de29bb..4a4210596 100644 --- a/catalystwan/models/policy/list/local_domain.py +++ b/catalystwan/models/policy/list/local_domain.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import LocalDomainListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class LocalDomainList(PolicyListBase): + type: Literal["localDomain"] = "localDomain" + entries: List[LocalDomainListEntry] = [] + + +class LocalDomainListEditPayload(LocalDomainList, PolicyListId): + pass + + +class LocalDomainListInfo(LocalDomainList, PolicyListInfo): + pass From 6454e72903badfd6bde4a1265b25e12c333a6406 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:11:22 +0100 Subject: [PATCH 15/36] separate mirror-list --- .../configuration/policy/list/mirror.py | 12 ++---------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/mirror.py | 18 ++++++++++++++++++ catalystwan/models/policy/lists.py | 12 ------------ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/mirror.py b/catalystwan/endpoints/configuration/policy/list/mirror.py index ab48672bb..8e4b1bd76 100644 --- a/catalystwan/endpoints/configuration/policy/list/mirror.py +++ b/catalystwan/endpoints/configuration/policy/list/mirror.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import MirrorList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.mirror import MirrorList, MirrorListEditPayload, MirrorListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class MirrorListEditPayload(MirrorList, PolicyListId): - pass - - -class MirrorListInfo(MirrorList, PolicyListInfo): - pass - - class ConfigurationPolicyMirrorList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/mirror") def create_policy_list(self, payload: MirrorList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 9882cf2d6..98da64dd4 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -20,6 +20,7 @@ from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixList from catalystwan.models.policy.list.local_app import LocalAppList from catalystwan.models.policy.list.local_domain import LocalDomainList +from catalystwan.models.policy.list.mirror import MirrorList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -37,7 +38,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - MirrorList, PolicerList, PortList, PreferredColorGroupList, diff --git a/catalystwan/models/policy/list/mirror.py b/catalystwan/models/policy/list/mirror.py index e69de29bb..b4c041304 100644 --- a/catalystwan/models/policy/list/mirror.py +++ b/catalystwan/models/policy/list/mirror.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import MirrorListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class MirrorList(PolicyListBase): + type: Literal["mirror"] = "mirror" + entries: List[MirrorListEntry] = [] + + +class MirrorListEditPayload(MirrorList, PolicyListId): + pass + + +class MirrorListInfo(MirrorList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index f2d26f844..b60885fac 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -10,8 +10,6 @@ from catalystwan.models.policy.lists_entries import ( ColorGroupPreference, EncapType, - LocalDomainListEntry, - MirrorListEntry, PathPreference, PolicerExceedAction, PolicerListEntry, @@ -91,11 +89,6 @@ class ProtocolNameList(PolicyListBase): entries: List[ProtocolNameListEntry] = [] -class LocalDomainList(PolicyListBase): - type: Literal["localDomain"] = "localDomain" - entries: List[LocalDomainListEntry] = [] - - class URLAllowList(PolicyListBase): type: Literal["urlWhiteList"] = "urlWhiteList" entries: List[URLListEntry] = [] @@ -116,11 +109,6 @@ def police(self, burst: int, rate: int, exceed: PolicerExceedAction = "drop") -> self._add_entry(entry, single=True) -class MirrorList(PolicyListBase): - type: Literal["mirror"] = "mirror" - entries: List[MirrorListEntry] = [] - - class SLAClassList(PolicyListBase): type: Literal["sla"] = "sla" entries: List[SLAClassListEntry] = [] From 9cb7eb784d94f981ac1d6a0c79897b878c89ca66 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:13:29 +0100 Subject: [PATCH 16/36] separate policer-list --- .../configuration/policy/list/policer.py | 12 ++-------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/policer.py | 23 +++++++++++++++++++ catalystwan/models/policy/lists.py | 12 ---------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/policer.py b/catalystwan/endpoints/configuration/policy/list/policer.py index 9675d89b0..1b578ec70 100644 --- a/catalystwan/endpoints/configuration/policy/list/policer.py +++ b/catalystwan/endpoints/configuration/policy/list/policer.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import PolicerList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.policer import PolicerList, PolicerListEditPayload, PolicerListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class PolicerListEditPayload(PolicerList, PolicyListId): - pass - - -class PolicerListInfo(PolicerList, PolicyListInfo): - pass - - class ConfigurationPolicyPolicerClassList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/policer") def create_policy_list(self, payload: PolicerList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 98da64dd4..173d6f696 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -21,6 +21,7 @@ from catalystwan.models.policy.list.local_app import LocalAppList from catalystwan.models.policy.list.local_domain import LocalDomainList from catalystwan.models.policy.list.mirror import MirrorList +from catalystwan.models.policy.list.policer import PolicerList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -38,7 +39,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - PolicerList, PortList, PreferredColorGroupList, PrefixList, diff --git a/catalystwan/models/policy/list/policer.py b/catalystwan/models/policy/list/policer.py index e69de29bb..9986d9675 100644 --- a/catalystwan/models/policy/list/policer.py +++ b/catalystwan/models/policy/list/policer.py @@ -0,0 +1,23 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import PolicerExceedAction, PolicerListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class PolicerList(PolicyListBase): + type: Literal["policer"] = "policer" + entries: List[PolicerListEntry] = [] + + def police(self, burst: int, rate: int, exceed: PolicerExceedAction = "drop") -> None: + # Policer list must have only single entry! + entry = PolicerListEntry(burst=burst, exceed=exceed, rate=rate) + self._add_entry(entry, single=True) + + +class PolicerListEditPayload(PolicerList, PolicyListId): + pass + + +class PolicerListInfo(PolicerList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index b60885fac..eeb373cf1 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -11,8 +11,6 @@ ColorGroupPreference, EncapType, PathPreference, - PolicerExceedAction, - PolicerListEntry, PortListEntry, PreferredColorGroupListEntry, PrefixListEntry, @@ -99,16 +97,6 @@ class URLBlockList(PolicyListBase): entries: List[URLListEntry] = [] -class PolicerList(PolicyListBase): - type: Literal["policer"] = "policer" - entries: List[PolicerListEntry] = [] - - def police(self, burst: int, rate: int, exceed: PolicerExceedAction = "drop") -> None: - # Policer list must have only single entry! - entry = PolicerListEntry(burst=burst, exceed=exceed, rate=rate) - self._add_entry(entry, single=True) - - class SLAClassList(PolicyListBase): type: Literal["sla"] = "sla" entries: List[SLAClassListEntry] = [] From 9c55b0072e89fcebb1a5903ef664d014e02445cd Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:16:18 +0100 Subject: [PATCH 17/36] separate port-list --- .../configuration/policy/list/port.py | 12 ++---------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/port.py | 18 ++++++++++++++++++ catalystwan/models/policy/lists.py | 6 ------ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/port.py b/catalystwan/endpoints/configuration/policy/list/port.py index f87c76c44..344835b8c 100644 --- a/catalystwan/endpoints/configuration/policy/list/port.py +++ b/catalystwan/endpoints/configuration/policy/list/port.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import PortList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.port import PortList, PortListEditPayload, PortListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class PortListEditPayload(PortList, PolicyListId): - pass - - -class PortListInfo(PortList, PolicyListInfo): - pass - - class ConfigurationPolicyPortList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/port") def create_policy_list(self, payload: PortList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 173d6f696..8099fccad 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -22,6 +22,7 @@ from catalystwan.models.policy.list.local_domain import LocalDomainList from catalystwan.models.policy.list.mirror import MirrorList from catalystwan.models.policy.list.policer import PolicerList +from catalystwan.models.policy.list.port import PortList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -39,7 +40,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - PortList, PreferredColorGroupList, PrefixList, ProtocolNameList, diff --git a/catalystwan/models/policy/list/port.py b/catalystwan/models/policy/list/port.py index e69de29bb..3e5db4c57 100644 --- a/catalystwan/models/policy/list/port.py +++ b/catalystwan/models/policy/list/port.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import PortListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class PortList(PolicyListBase): + type: Literal["port"] = "port" + entries: List[PortListEntry] = [] + + +class PortListEditPayload(PortList, PolicyListId): + pass + + +class PortListInfo(PortList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index eeb373cf1..2ef9b6ff6 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -11,7 +11,6 @@ ColorGroupPreference, EncapType, PathPreference, - PortListEntry, PreferredColorGroupListEntry, PrefixListEntry, ProtocolNameListEntry, @@ -77,11 +76,6 @@ def assign_interfaces(self, ifs: Set[InterfaceType]) -> None: self.entries = [ZoneListEntry(interface=interface) for interface in ifs] -class PortList(PolicyListBase): - type: Literal["port"] = "port" - entries: List[PortListEntry] = [] - - class ProtocolNameList(PolicyListBase): type: Literal["protocolName"] = "protocolName" entries: List[ProtocolNameListEntry] = [] From cd96609ba723488667d53c75c899eddad89a11d8 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:21:16 +0100 Subject: [PATCH 18/36] separate preferred-color-group-list --- .../policy/list/preferred_color_group.py | 16 +++----- catalystwan/models/policy/__init__.py | 2 +- .../policy/list/preferred_color_group.py | 38 +++++++++++++++++++ catalystwan/models/policy/lists.py | 30 --------------- 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py b/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py index a6c19da22..8902bf4d9 100644 --- a/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py +++ b/catalystwan/endpoints/configuration/policy/list/preferred_color_group.py @@ -5,19 +5,15 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import PreferredColorGroupList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.preferred_color_group import ( + PreferredColorGroupList, + PreferredColorGroupListEditPayload, + PreferredColorGroupListInfo, +) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class PreferredColorGroupListEditPayload(PreferredColorGroupList, PolicyListId): - pass - - -class PreferredColorGroupListInfo(PreferredColorGroupList, PolicyListInfo): - pass - - class ConfigurationPreferredColorGroupList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/preferredcolorgroup") def create_policy_list(self, payload: PreferredColorGroupList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 8099fccad..ca3aba30e 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -23,6 +23,7 @@ from catalystwan.models.policy.list.mirror import MirrorList from catalystwan.models.policy.list.policer import PolicerList from catalystwan.models.policy.list.port import PortList +from catalystwan.models.policy.list.preferred_color_group import PreferredColorGroupList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -40,7 +41,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - PreferredColorGroupList, PrefixList, ProtocolNameList, RegionList, diff --git a/catalystwan/models/policy/list/preferred_color_group.py b/catalystwan/models/policy/list/preferred_color_group.py index e69de29bb..2685ddaea 100644 --- a/catalystwan/models/policy/list/preferred_color_group.py +++ b/catalystwan/models/policy/list/preferred_color_group.py @@ -0,0 +1,38 @@ +from typing import List, Literal, Optional, Set, Tuple + +from catalystwan.models.common import TLOCColor +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import ColorGroupPreference, PathPreference, PreferredColorGroupListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class PreferredColorGroupList(PolicyListBase): + type: Literal["preferredColorGroup"] = "preferredColorGroup" + entries: List[PreferredColorGroupListEntry] = [] + + def assign_color_groups( + self, + primary: Tuple[Set[TLOCColor], PathPreference], + secondary: Optional[Tuple[Set[TLOCColor], PathPreference]] = None, + tertiary: Optional[Tuple[Set[TLOCColor], PathPreference]] = None, + ) -> PreferredColorGroupListEntry: + primary_preference = ColorGroupPreference.from_color_set_and_path(*primary) + secondary_preference = ( + ColorGroupPreference.from_color_set_and_path(*secondary) if secondary is not None else None + ) + tertiary_preference = ColorGroupPreference.from_color_set_and_path(*tertiary) if tertiary is not None else None + entry = PreferredColorGroupListEntry( + primary_preference=primary_preference, + secondary_preference=secondary_preference, + tertiary_preference=tertiary_preference, + ) + self._add_entry(entry=entry, single=True) + return entry + + +class PreferredColorGroupListEditPayload(PreferredColorGroupList, PolicyListId): + pass + + +class PreferredColorGroupListInfo(PreferredColorGroupList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 2ef9b6ff6..074c5c62e 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -8,10 +8,7 @@ from catalystwan.models.common import InterfaceType, TLOCColor from catalystwan.models.policy.lists_entries import ( - ColorGroupPreference, EncapType, - PathPreference, - PreferredColorGroupListEntry, PrefixListEntry, ProtocolNameListEntry, RegionListEntry, @@ -132,33 +129,6 @@ def add_tloc(self, tloc: IPv4Address, color: TLOCColor, encap: EncapType, prefer self.entries.append(TLOCListEntry(tloc=tloc, color=color, encap=encap, preference=_preference)) -class PreferredColorGroupList(PolicyListBase): - type: Literal["preferredColorGroup"] = "preferredColorGroup" - entries: List[PreferredColorGroupListEntry] = [] - - def assign_color_groups( - self, - primary: Tuple[Set[TLOCColor], PathPreference], - secondary: Optional[Tuple[Set[TLOCColor], PathPreference]] = None, - tertiary: Optional[Tuple[Set[TLOCColor], PathPreference]] = None, - ) -> PreferredColorGroupListEntry: - primary_preference = ColorGroupPreference.from_color_set_and_path(*primary) - secondary_preference = ( - ColorGroupPreference.from_color_set_and_path(*secondary) if secondary is not None else None - ) - tertiary_preference = ColorGroupPreference.from_color_set_and_path(*tertiary) if tertiary is not None else None - entry = PreferredColorGroupListEntry( - primary_preference=primary_preference, - secondary_preference=secondary_preference, - tertiary_preference=tertiary_preference, - ) - if self.entries: - self.entries[0] = entry - else: - self.entries.append(entry) - return entry - - class PrefixList(PolicyListBase): type: Literal["prefix"] = "prefix" entries: List[PrefixListEntry] = [] From f8cde35ea197aaffa9b6c4e57911c3cffed632ad Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:23:57 +0100 Subject: [PATCH 19/36] separate prefix-list --- .../configuration/policy/list/prefix.py | 13 +++-------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/prefix.py | 22 +++++++++++++++++++ catalystwan/models/policy/lists.py | 11 +--------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/prefix.py b/catalystwan/endpoints/configuration/policy/list/prefix.py index cdab743b4..f31ea5418 100644 --- a/catalystwan/endpoints/configuration/policy/list/prefix.py +++ b/catalystwan/endpoints/configuration/policy/list/prefix.py @@ -3,21 +3,14 @@ # mypy: disable-error-code="empty-body" from uuid import UUID +from catalystwan.api.templates.models.cisco_vpn_model import PrefixList from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import PrefixList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.prefix import PrefixListEditPayload, PrefixListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class PrefixListEditPayload(PrefixList, PolicyListId): - pass - - -class PrefixListInfo(PrefixList, PolicyListInfo): - pass - - class ConfigurationPolicyPrefixList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/prefix") def create_policy_list(self, payload: PrefixList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index ca3aba30e..3d8c774f5 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -24,6 +24,7 @@ from catalystwan.models.policy.list.policer import PolicerList from catalystwan.models.policy.list.port import PortList from catalystwan.models.policy.list.preferred_color_group import PreferredColorGroupList +from catalystwan.models.policy.list.prefix import PrefixList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -41,7 +42,6 @@ from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy from .lists import ( - PrefixList, ProtocolNameList, RegionList, SiteList, diff --git a/catalystwan/models/policy/list/prefix.py b/catalystwan/models/policy/list/prefix.py index e69de29bb..cdeb31d42 100644 --- a/catalystwan/models/policy/list/prefix.py +++ b/catalystwan/models/policy/list/prefix.py @@ -0,0 +1,22 @@ +from ipaddress import IPv4Network +from typing import List, Literal, Optional + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import PrefixListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class PrefixList(PolicyListBase): + type: Literal["prefix"] = "prefix" + entries: List[PrefixListEntry] = [] + + def add_prefix(self, prefix: IPv4Network, ge: Optional[int] = None, le: Optional[int] = None) -> None: + self._add_entry(PrefixListEntry(ip_prefix=prefix, ge=ge, le=le)) + + +class PrefixListEditPayload(PrefixList, PolicyListId): + pass + + +class PrefixListInfo(PrefixList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 074c5c62e..c2f843ff2 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -1,6 +1,6 @@ # Copyright 2023 Cisco Systems, Inc. and its affiliates -from ipaddress import IPv4Address, IPv4Network +from ipaddress import IPv4Address from typing import Any, List, Literal, Optional, Set, Tuple from uuid import UUID @@ -9,7 +9,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor from catalystwan.models.policy.lists_entries import ( EncapType, - PrefixListEntry, ProtocolNameListEntry, RegionListEntry, SiteListEntry, @@ -129,14 +128,6 @@ def add_tloc(self, tloc: IPv4Address, color: TLOCColor, encap: EncapType, prefer self.entries.append(TLOCListEntry(tloc=tloc, color=color, encap=encap, preference=_preference)) -class PrefixList(PolicyListBase): - type: Literal["prefix"] = "prefix" - entries: List[PrefixListEntry] = [] - - def add_prefix(self, prefix: IPv4Network, ge: Optional[int] = None, le: Optional[int] = None) -> None: - self._add_entry(PrefixListEntry(ip_prefix=prefix, ge=ge, le=le)) - - class RegionList(PolicyListBase): type: Literal["region"] = "region" entries: List[RegionListEntry] = [] From 0c33c40c000d0df56e7d877e2fff696fdbc3943e Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:26:45 +0100 Subject: [PATCH 20/36] separate protocol-name-list --- .../configuration/policy/list/protocol_name.py | 16 ++++++---------- catalystwan/models/policy/__init__.py | 13 ++----------- .../models/policy/list/protocol_name.py | 18 ++++++++++++++++++ catalystwan/models/policy/lists.py | 6 ------ 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/protocol_name.py b/catalystwan/endpoints/configuration/policy/list/protocol_name.py index e4c288d11..76e7a837e 100644 --- a/catalystwan/endpoints/configuration/policy/list/protocol_name.py +++ b/catalystwan/endpoints/configuration/policy/list/protocol_name.py @@ -5,19 +5,15 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import ProtocolNameList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.protocol_name import ( + ProtocolNameList, + ProtocolNameListEditPayload, + ProtocolNameListInfo, +) +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class ProtocolNameListEditPayload(ProtocolNameList, PolicyListId): - pass - - -class ProtocolNameListInfo(ProtocolNameList, PolicyListInfo): - pass - - class ConfigurationPolicyProtocolNameList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/protocolname") def create_policy_list(self, payload: ProtocolNameList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 3d8c774f5..1d546f8f5 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -25,6 +25,7 @@ from catalystwan.models.policy.list.port import PortList from catalystwan.models.policy.list.preferred_color_group import PreferredColorGroupList from catalystwan.models.policy.list.prefix import PrefixList +from catalystwan.models.policy.list.protocol_name import ProtocolNameList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -41,17 +42,7 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import ( - ProtocolNameList, - RegionList, - SiteList, - SLAClassList, - TLOCList, - URLAllowList, - URLBlockList, - VPNList, - ZoneList, -) +from .lists import RegionList, SiteList, SLAClassList, TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/protocol_name.py b/catalystwan/models/policy/list/protocol_name.py index e69de29bb..0414bee68 100644 --- a/catalystwan/models/policy/list/protocol_name.py +++ b/catalystwan/models/policy/list/protocol_name.py @@ -0,0 +1,18 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import ProtocolNameListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class ProtocolNameList(PolicyListBase): + type: Literal["protocolName"] = "protocolName" + entries: List[ProtocolNameListEntry] = [] + + +class ProtocolNameListEditPayload(ProtocolNameList, PolicyListId): + pass + + +class ProtocolNameListInfo(ProtocolNameList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index c2f843ff2..2f6e19ddd 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -9,7 +9,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor from catalystwan.models.policy.lists_entries import ( EncapType, - ProtocolNameListEntry, RegionListEntry, SiteListEntry, SLAClassListEntry, @@ -72,11 +71,6 @@ def assign_interfaces(self, ifs: Set[InterfaceType]) -> None: self.entries = [ZoneListEntry(interface=interface) for interface in ifs] -class ProtocolNameList(PolicyListBase): - type: Literal["protocolName"] = "protocolName" - entries: List[ProtocolNameListEntry] = [] - - class URLAllowList(PolicyListBase): type: Literal["urlWhiteList"] = "urlWhiteList" entries: List[URLListEntry] = [] From 2e7b8ebc3283ae6df3ed2218766f66ca57abadd2 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:30:23 +0100 Subject: [PATCH 21/36] separate region-list --- .../configuration/policy/list/region.py | 12 ++------- catalystwan/models/policy/__init__.py | 3 ++- catalystwan/models/policy/list/region.py | 26 +++++++++++++++++++ catalystwan/models/policy/lists.py | 14 ---------- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/region.py b/catalystwan/endpoints/configuration/policy/list/region.py index e55cbddd1..a711446bb 100644 --- a/catalystwan/endpoints/configuration/policy/list/region.py +++ b/catalystwan/endpoints/configuration/policy/list/region.py @@ -4,19 +4,11 @@ from uuid import UUID from catalystwan.endpoints import APIEndpoints, delete, get, post, put -from catalystwan.models.policy.lists import RegionList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.region import RegionList, RegionListEditPayload, RegionListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class RegionListEditPayload(RegionList, PolicyListId): - pass - - -class RegionListInfo(RegionList, PolicyListInfo): - pass - - class ConfigurationPolicyRegionList(APIEndpoints): @post("/template/policy/list/region") def create_policy_list(self, payload: RegionList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 1d546f8f5..ca21b6180 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -26,6 +26,7 @@ from catalystwan.models.policy.list.preferred_color_group import PreferredColorGroupList from catalystwan.models.policy.list.prefix import PrefixList from catalystwan.models.policy.list.protocol_name import ProtocolNameList +from catalystwan.models.policy.list.region import RegionList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -42,7 +43,7 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import RegionList, SiteList, SLAClassList, TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList +from .lists import SiteList, SLAClassList, TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/region.py b/catalystwan/models/policy/list/region.py index e69de29bb..6e89d61b9 100644 --- a/catalystwan/models/policy/list/region.py +++ b/catalystwan/models/policy/list/region.py @@ -0,0 +1,26 @@ +from typing import List, Literal, Set, Tuple + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import RegionListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class RegionList(PolicyListBase): + type: Literal["region"] = "region" + entries: List[RegionListEntry] = [] + + def add_regions(self, regions: Set[int]): + for region in regions: + self._add_entry(RegionListEntry(region_id=str(region))) + + def add_region_range(self, region_range: Tuple[int, int]): + entry = RegionListEntry(region_id=f"{region_range[0]}-{region_range[1]}") + self._add_entry(entry) + + +class RegionListEditPayload(RegionList, PolicyListId): + pass + + +class RegionListInfo(RegionList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 2f6e19ddd..1add7b184 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -9,7 +9,6 @@ from catalystwan.models.common import InterfaceType, TLOCColor from catalystwan.models.policy.lists_entries import ( EncapType, - RegionListEntry, SiteListEntry, SLAClassListEntry, TLOCListEntry, @@ -120,16 +119,3 @@ class TLOCList(PolicyListBase): def add_tloc(self, tloc: IPv4Address, color: TLOCColor, encap: EncapType, preference: Optional[int] = None) -> None: _preference = str(preference) if preference is not None else None self.entries.append(TLOCListEntry(tloc=tloc, color=color, encap=encap, preference=_preference)) - - -class RegionList(PolicyListBase): - type: Literal["region"] = "region" - entries: List[RegionListEntry] = [] - - def add_regions(self, regions: Set[int]): - for region in regions: - self._add_entry(RegionListEntry(region_id=str(region))) - - def add_region_range(self, region_range: Tuple[int, int]): - entry = RegionListEntry(region_id=f"{region_range[0]}-{region_range[1]}") - self._add_entry(entry) From 02d7bfea21b5eb28e838caf38d3f5d7e342b3b1f Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:33:16 +0100 Subject: [PATCH 22/36] separate site-list --- .../configuration/policy/list/site.py | 12 ++------- catalystwan/models/policy/__init__.py | 3 ++- catalystwan/models/policy/list/site.py | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/site.py b/catalystwan/endpoints/configuration/policy/list/site.py index bd7107b22..8dd1b458b 100644 --- a/catalystwan/endpoints/configuration/policy/list/site.py +++ b/catalystwan/endpoints/configuration/policy/list/site.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import SiteList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.site import SiteList, SiteListEditPayload, SiteListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class SiteListEditPayload(SiteList, PolicyListId): - pass - - -class SiteListInfo(SiteList, PolicyListInfo): - pass - - class ConfigurationPolicySiteList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/site/defaultsite") def create_default_site_list(self, payload: SiteList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index ca21b6180..a6d0bb2fc 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -27,6 +27,7 @@ from catalystwan.models.policy.list.prefix import PrefixList from catalystwan.models.policy.list.protocol_name import ProtocolNameList from catalystwan.models.policy.list.region import RegionList +from catalystwan.models.policy.list.site import SiteList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -43,7 +44,7 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import SiteList, SLAClassList, TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList +from .lists import SLAClassList, TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/site.py b/catalystwan/models/policy/list/site.py index e69de29bb..b79314975 100644 --- a/catalystwan/models/policy/list/site.py +++ b/catalystwan/models/policy/list/site.py @@ -0,0 +1,26 @@ +from typing import List, Literal, Set, Tuple + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import SiteListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class SiteList(PolicyListBase): + type: Literal["site"] = "site" + entries: List[SiteListEntry] = [] + + def add_sites(self, sites: Set[int]): + for site in sites: + self._add_entry(SiteListEntry(site_id=str(site))) + + def add_site_range(self, site_range: Tuple[int, int]): + entry = SiteListEntry(site_id=f"{site_range[0]}-{site_range[1]}") + self._add_entry(entry) + + +class SiteListEditPayload(SiteList, PolicyListId): + pass + + +class SiteListInfo(SiteList, PolicyListInfo): + pass From 6645d8e8bef182334851779417e86333f604aa2b Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:40:38 +0100 Subject: [PATCH 23/36] separate sla-class-list --- .../configuration/policy/list/sla.py | 12 +--- catalystwan/models/policy/__init__.py | 3 +- catalystwan/models/policy/list/sla.py | 46 +++++++++++++++ catalystwan/models/policy/lists.py | 56 +------------------ 4 files changed, 51 insertions(+), 66 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/sla.py b/catalystwan/endpoints/configuration/policy/list/sla.py index e3b5183e7..6dd6833f8 100644 --- a/catalystwan/endpoints/configuration/policy/list/sla.py +++ b/catalystwan/endpoints/configuration/policy/list/sla.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import SLAClassList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.sla import SLAClassList, SLAClassListEditPayload, SLAClassListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class SLAClassListEditPayload(SLAClassList, PolicyListId): - pass - - -class SLAClassListInfo(SLAClassList, PolicyListInfo): - pass - - class ConfigurationPolicySLAClassList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/sla") def create_policy_list(self, payload: SLAClassList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index a6d0bb2fc..cedb9eb23 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -28,6 +28,7 @@ from catalystwan.models.policy.list.protocol_name import ProtocolNameList from catalystwan.models.policy.list.region import RegionList from catalystwan.models.policy.list.site import SiteList +from catalystwan.models.policy.list.sla import SLAClassList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -44,7 +45,7 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import SLAClassList, TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList +from .lists import TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/sla.py b/catalystwan/models/policy/list/sla.py index e69de29bb..a62e050e3 100644 --- a/catalystwan/models/policy/list/sla.py +++ b/catalystwan/models/policy/list/sla.py @@ -0,0 +1,46 @@ +from typing import List, Literal, Optional +from uuid import UUID + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import SLAClassListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class SLAClassList(PolicyListBase): + type: Literal["sla"] = "sla" + entries: List[SLAClassListEntry] = [] + + def assign_app_probe_class( + self, + app_probe_class_id: UUID, + latency: Optional[int] = None, + loss: Optional[int] = None, + jitter: Optional[int] = None, + ) -> SLAClassListEntry: + # SLA class list must have only one entry! + _latency = str(latency) if latency is not None else None + _loss = str(loss) if loss is not None else None + _jitter = str(jitter) if jitter is not None else None + entry = SLAClassListEntry(latency=_latency, loss=_loss, jitter=_jitter, app_probe_class=app_probe_class_id) + self._add_entry(entry, single=True) + return entry + + def add_fallback_jitter_criteria(self, jitter_variance: int) -> None: + assert self.entries, "Assign app probe class before configuring best fallback tunnel" + self.entries[0].add_fallback_jitter_criteria(jitter_variance) + + def add_fallback_latency_criteria(self, latency_variance: int) -> None: + assert self.entries, "Assign app probe class before configuring best fallback tunnel" + self.entries[0].add_fallback_latency_criteria(latency_variance) + + def add_fallback_loss_criteria(self, loss_variance: int) -> None: + assert self.entries, "Assign app probe class before configuring best fallback tunnel" + self.entries[0].add_fallback_loss_criteria(loss_variance) + + +class SLAClassListEditPayload(SLAClassList, PolicyListId): + pass + + +class SLAClassListInfo(SLAClassList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 1add7b184..59f083620 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -2,20 +2,11 @@ from ipaddress import IPv4Address from typing import Any, List, Literal, Optional, Set, Tuple -from uuid import UUID from pydantic import BaseModel, Field from catalystwan.models.common import InterfaceType, TLOCColor -from catalystwan.models.policy.lists_entries import ( - EncapType, - SiteListEntry, - SLAClassListEntry, - TLOCListEntry, - URLListEntry, - VPNListEntry, - ZoneListEntry, -) +from catalystwan.models.policy.lists_entries import EncapType, TLOCListEntry, URLListEntry, VPNListEntry, ZoneListEntry class PolicyListBase(BaseModel): @@ -34,19 +25,6 @@ def _add_entry(self, entry: Any, single: bool = False) -> None: self.entries.append(entry) -class SiteList(PolicyListBase): - type: Literal["site"] = "site" - entries: List[SiteListEntry] = [] - - def add_sites(self, sites: Set[int]): - for site in sites: - self._add_entry(SiteListEntry(site_id=str(site))) - - def add_site_range(self, site_range: Tuple[int, int]): - entry = SiteListEntry(site_id=f"{site_range[0]}-{site_range[1]}") - self._add_entry(entry) - - class VPNList(PolicyListBase): type: Literal["vpn"] = "vpn" entries: List[VPNListEntry] = [] @@ -80,38 +58,6 @@ class URLBlockList(PolicyListBase): entries: List[URLListEntry] = [] -class SLAClassList(PolicyListBase): - type: Literal["sla"] = "sla" - entries: List[SLAClassListEntry] = [] - - def assign_app_probe_class( - self, - app_probe_class_id: UUID, - latency: Optional[int] = None, - loss: Optional[int] = None, - jitter: Optional[int] = None, - ) -> SLAClassListEntry: - # SLA class list must have only one entry! - _latency = str(latency) if latency is not None else None - _loss = str(loss) if loss is not None else None - _jitter = str(jitter) if jitter is not None else None - entry = SLAClassListEntry(latency=_latency, loss=_loss, jitter=_jitter, app_probe_class=app_probe_class_id) - self._add_entry(entry, single=True) - return entry - - def add_fallback_jitter_criteria(self, jitter_variance: int) -> None: - assert self.entries, "Assign app probe class before configuring best fallback tunnel" - self.entries[0].add_fallback_jitter_criteria(jitter_variance) - - def add_fallback_latency_criteria(self, latency_variance: int) -> None: - assert self.entries, "Assign app probe class before configuring best fallback tunnel" - self.entries[0].add_fallback_latency_criteria(latency_variance) - - def add_fallback_loss_criteria(self, loss_variance: int) -> None: - assert self.entries, "Assign app probe class before configuring best fallback tunnel" - self.entries[0].add_fallback_loss_criteria(loss_variance) - - class TLOCList(PolicyListBase): type: Literal["tloc"] = "tloc" entries: List[TLOCListEntry] = [] From 4902258dfaf886b9f4944488383acbee0ed5bb8f Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:45:46 +0100 Subject: [PATCH 24/36] separate tloc-list --- .../configuration/policy/list/tloc.py | 12 ++-------- catalystwan/models/policy/__init__.py | 3 ++- catalystwan/models/policy/list/tloc.py | 23 +++++++++++++++++++ catalystwan/models/policy/lists.py | 14 ++--------- catalystwan/models/policy/lists_entries.py | 9 +------- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/tloc.py b/catalystwan/endpoints/configuration/policy/list/tloc.py index 42a007fc8..ad9b47d1a 100644 --- a/catalystwan/endpoints/configuration/policy/list/tloc.py +++ b/catalystwan/endpoints/configuration/policy/list/tloc.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import TLOCList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.tloc import TLOCList, TLOCListEditPayload, TLOCListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class TLOCListEditPayload(TLOCList, PolicyListId): - pass - - -class TLOCListInfo(TLOCList, PolicyListInfo): - pass - - class ConfigurationPolicyTLOCList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/tloc") def create_policy_list(self, payload: TLOCList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index cedb9eb23..93b8ed1cc 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -29,6 +29,7 @@ from catalystwan.models.policy.list.region import RegionList from catalystwan.models.policy.list.site import SiteList from catalystwan.models.policy.list.sla import SLAClassList +from catalystwan.models.policy.list.tloc import TLOCList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -45,7 +46,7 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import TLOCList, URLAllowList, URLBlockList, VPNList, ZoneList +from .lists import URLAllowList, URLBlockList, VPNList, ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/tloc.py b/catalystwan/models/policy/list/tloc.py index e69de29bb..53e96c606 100644 --- a/catalystwan/models/policy/list/tloc.py +++ b/catalystwan/models/policy/list/tloc.py @@ -0,0 +1,23 @@ +from ipaddress import IPv4Address +from typing import List, Literal, Optional + +from catalystwan.models.common import EncapType, TLOCColor +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import TLOCListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class TLOCList(PolicyListBase): + type: Literal["tloc"] = "tloc" + entries: List[TLOCListEntry] = [] + + def add_tloc(self, tloc: IPv4Address, color: TLOCColor, encap: EncapType, preference: Optional[int] = None) -> None: + self.entries.append(TLOCListEntry(tloc=tloc, color=color, encap=encap, preference=preference)) + + +class TLOCListEditPayload(TLOCList, PolicyListId): + pass + + +class TLOCListInfo(TLOCList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 59f083620..809c8f599 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -1,12 +1,11 @@ # Copyright 2023 Cisco Systems, Inc. and its affiliates -from ipaddress import IPv4Address from typing import Any, List, Literal, Optional, Set, Tuple from pydantic import BaseModel, Field -from catalystwan.models.common import InterfaceType, TLOCColor -from catalystwan.models.policy.lists_entries import EncapType, TLOCListEntry, URLListEntry, VPNListEntry, ZoneListEntry +from catalystwan.models.common import InterfaceType +from catalystwan.models.policy.lists_entries import URLListEntry, VPNListEntry, ZoneListEntry class PolicyListBase(BaseModel): @@ -56,12 +55,3 @@ class URLAllowList(PolicyListBase): class URLBlockList(PolicyListBase): type: Literal["urlBlackList"] = "urlBlackList" entries: List[URLListEntry] = [] - - -class TLOCList(PolicyListBase): - type: Literal["tloc"] = "tloc" - entries: List[TLOCListEntry] = [] - - def add_tloc(self, tloc: IPv4Address, color: TLOCColor, encap: EncapType, preference: Optional[int] = None) -> None: - _preference = str(preference) if preference is not None else None - self.entries.append(TLOCListEntry(tloc=tloc, color=color, encap=encap, preference=_preference)) diff --git a/catalystwan/models/policy/lists_entries.py b/catalystwan/models/policy/lists_entries.py index 542579c27..0b7295272 100644 --- a/catalystwan/models/policy/lists_entries.py +++ b/catalystwan/models/policy/lists_entries.py @@ -359,14 +359,7 @@ class TLOCListEntry(BaseModel): tloc: IPv4Address color: TLOCColor encap: EncapType - preference: Optional[str] = None - - @field_validator("preference") - @classmethod - def check_preference(cls, preference_str: str): - if preference_str is not None: - assert 0 <= int(preference_str) <= 2**32 - 1 - return preference_str + preference: Optional[IntStr] = Field(default=None, ge=0, le=2**32 - 1) class PreferredColorGroupListEntry(BaseModel): From d427dff0a054a38130643896c0ffe95461278a89 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:52:00 +0100 Subject: [PATCH 25/36] separate url-lists --- .../policy/list/url_allow_list.py | 12 ++----- .../policy/list/url_block_list.py | 12 ++----- catalystwan/models/policy/__init__.py | 3 +- catalystwan/models/policy/list/url.py | 31 +++++++++++++++++++ .../models/policy/list/url_allow_list.py | 0 .../models/policy/list/url_block_list.py | 0 catalystwan/models/policy/lists.py | 12 +------ 7 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 catalystwan/models/policy/list/url.py delete mode 100644 catalystwan/models/policy/list/url_allow_list.py delete mode 100644 catalystwan/models/policy/list/url_block_list.py diff --git a/catalystwan/endpoints/configuration/policy/list/url_allow_list.py b/catalystwan/endpoints/configuration/policy/list/url_allow_list.py index fa252e37d..1e235908f 100644 --- a/catalystwan/endpoints/configuration/policy/list/url_allow_list.py +++ b/catalystwan/endpoints/configuration/policy/list/url_allow_list.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import URLAllowList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.url import URLAllowList, URLAllowListEditPayload, URLAllowListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class URLAllowListEditPayload(URLAllowList, PolicyListId): - pass - - -class URLAllowListInfo(URLAllowList, PolicyListInfo): - pass - - class ConfigurationPolicyURLAllowList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/urlwhitelist") def create_policy_list(self, payload: URLAllowList) -> PolicyListId: diff --git a/catalystwan/endpoints/configuration/policy/list/url_block_list.py b/catalystwan/endpoints/configuration/policy/list/url_block_list.py index 09cf2bf94..41258d272 100644 --- a/catalystwan/endpoints/configuration/policy/list/url_block_list.py +++ b/catalystwan/endpoints/configuration/policy/list/url_block_list.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import URLBlockList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.url import URLBlockList, URLBlockListEditPayload, URLBlockListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class URLBlockListEditPayload(URLBlockList, PolicyListId): - pass - - -class URLBlockListInfo(URLBlockList, PolicyListInfo): - pass - - class ConfigurationPolicyURLBlockList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/urlblacklist") def create_policy_list(self, payload: URLBlockList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 93b8ed1cc..79d4d9050 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -30,6 +30,7 @@ from catalystwan.models.policy.list.site import SiteList from catalystwan.models.policy.list.sla import SLAClassList from catalystwan.models.policy.list.tloc import TLOCList +from catalystwan.models.policy.list.url import URLAllowList, URLBlockList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -46,7 +47,7 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import URLAllowList, URLBlockList, VPNList, ZoneList +from .lists import VPNList, ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/url.py b/catalystwan/models/policy/list/url.py new file mode 100644 index 000000000..e9e71c602 --- /dev/null +++ b/catalystwan/models/policy/list/url.py @@ -0,0 +1,31 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import URLListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class URLAllowList(PolicyListBase): + type: Literal["urlWhiteList"] = "urlWhiteList" + entries: List[URLListEntry] = [] + + +class URLAllowListEditPayload(URLAllowList, PolicyListId): + pass + + +class URLAllowListInfo(URLAllowList, PolicyListInfo): + pass + + +class URLBlockList(PolicyListBase): + type: Literal["urlBlackList"] = "urlBlackList" + entries: List[URLListEntry] = [] + + +class URLBlockListEditPayload(URLBlockList, PolicyListId): + pass + + +class URLBlockListInfo(URLBlockList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/list/url_allow_list.py b/catalystwan/models/policy/list/url_allow_list.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/catalystwan/models/policy/list/url_block_list.py b/catalystwan/models/policy/list/url_block_list.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 809c8f599..4f1e97da9 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -5,7 +5,7 @@ from pydantic import BaseModel, Field from catalystwan.models.common import InterfaceType -from catalystwan.models.policy.lists_entries import URLListEntry, VPNListEntry, ZoneListEntry +from catalystwan.models.policy.lists_entries import VPNListEntry, ZoneListEntry class PolicyListBase(BaseModel): @@ -45,13 +45,3 @@ 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] - - -class URLAllowList(PolicyListBase): - type: Literal["urlWhiteList"] = "urlWhiteList" - entries: List[URLListEntry] = [] - - -class URLBlockList(PolicyListBase): - type: Literal["urlBlackList"] = "urlBlackList" - entries: List[URLListEntry] = [] From 0579c355038b8dd13730750298c97d8e04dbebce Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:55:06 +0100 Subject: [PATCH 26/36] separate vpn-list --- .../configuration/policy/list/vpn.py | 12 ++------- catalystwan/models/policy/__init__.py | 3 ++- catalystwan/models/policy/list/vpn.py | 25 +++++++++++++++++++ catalystwan/models/policy/lists.py | 16 ++---------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/vpn.py b/catalystwan/endpoints/configuration/policy/list/vpn.py index abb23c042..e945b8e13 100644 --- a/catalystwan/endpoints/configuration/policy/list/vpn.py +++ b/catalystwan/endpoints/configuration/policy/list/vpn.py @@ -7,19 +7,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import VPNList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.vpn import VPNList, VPNListEditPayload, VPNListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class VPNListEditPayload(VPNList, PolicyListId): - pass - - -class VPNListInfo(VPNList, PolicyListInfo): - pass - - class ConfigurationPolicyVPNList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/vpn") def create_policy_list(self, payload: VPNList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 79d4d9050..24d695fc3 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -31,6 +31,7 @@ from catalystwan.models.policy.list.sla import SLAClassList from catalystwan.models.policy.list.tloc import TLOCList from catalystwan.models.policy.list.url import URLAllowList, URLBlockList +from catalystwan.models.policy.list.vpn import VPNList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -47,7 +48,7 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import VPNList, ZoneList +from .lists import ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/vpn.py b/catalystwan/models/policy/list/vpn.py index e69de29bb..6a8a7b3ae 100644 --- a/catalystwan/models/policy/list/vpn.py +++ b/catalystwan/models/policy/list/vpn.py @@ -0,0 +1,25 @@ +from typing import List, Literal, Set, Tuple + +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import VPNListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class VPNList(PolicyListBase): + type: Literal["vpn"] = "vpn" + entries: List[VPNListEntry] = [] + + def add_vpns(self, vpns: Set[int]): + for vpn in vpns: + self._add_entry(VPNListEntry(vpn=(vpn, None))) + + def add_vpn_range(self, vpn_range: Tuple[int, int]): + self._add_entry(VPNListEntry(vpn=vpn_range)) + + +class VPNListEditPayload(VPNList, PolicyListId): + pass + + +class VPNListInfo(VPNList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index 4f1e97da9..c81a84f9f 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -1,11 +1,11 @@ # Copyright 2023 Cisco Systems, Inc. and its affiliates -from typing import Any, List, Literal, Optional, Set, Tuple +from typing import Any, List, Literal, Optional, Set from pydantic import BaseModel, Field from catalystwan.models.common import InterfaceType -from catalystwan.models.policy.lists_entries import VPNListEntry, ZoneListEntry +from catalystwan.models.policy.lists_entries import ZoneListEntry class PolicyListBase(BaseModel): @@ -24,18 +24,6 @@ def _add_entry(self, entry: Any, single: bool = False) -> None: self.entries.append(entry) -class VPNList(PolicyListBase): - type: Literal["vpn"] = "vpn" - entries: List[VPNListEntry] = [] - - def add_vpns(self, vpns: Set[int]): - for vpn in vpns: - self._add_entry(VPNListEntry(vpn=(vpn, None))) - - def add_vpn_range(self, vpn_range: Tuple[int, int]): - self._add_entry(VPNListEntry(vpn=vpn_range)) - - class ZoneList(PolicyListBase): type: Literal["zone"] = "zone" entries: List[ZoneListEntry] = [] From 0db6ed9a5123152c796faae004334d0e98c3e2a8 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 01:59:01 +0100 Subject: [PATCH 27/36] separate zone-list --- .../configuration/policy/list/zone.py | 12 ++------- catalystwan/models/policy/__init__.py | 2 +- catalystwan/models/policy/list/zone.py | 25 +++++++++++++++++++ catalystwan/models/policy/lists.py | 16 +----------- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/catalystwan/endpoints/configuration/policy/list/zone.py b/catalystwan/endpoints/configuration/policy/list/zone.py index 1c17fa51f..995643e6d 100644 --- a/catalystwan/endpoints/configuration/policy/list/zone.py +++ b/catalystwan/endpoints/configuration/policy/list/zone.py @@ -5,19 +5,11 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints -from catalystwan.models.policy.lists import ZoneList -from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListInfo, PolicyListPreview +from catalystwan.models.policy.list.zone import ZoneList, ZoneListEditPayload, ZoneListInfo +from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview from catalystwan.typed_list import DataSequence -class ZoneListEditPayload(ZoneList, PolicyListId): - pass - - -class ZoneListInfo(ZoneList, PolicyListInfo): - pass - - class ConfigurationPolicyZoneList(APIEndpoints, PolicyListEndpoints): @post("/template/policy/list/zone") def create_policy_list(self, payload: ZoneList) -> PolicyListId: diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 24d695fc3..7c209cbba 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -32,6 +32,7 @@ from catalystwan.models.policy.list.tloc import TLOCList from catalystwan.models.policy.list.url import URLAllowList, URLBlockList from catalystwan.models.policy.list.vpn import VPNList +from catalystwan.models.policy.list.zone import ZoneList from .centralized import CentralizedPolicy, TrafficDataDirection from .definition.access_control_list import AclPolicy @@ -48,7 +49,6 @@ from .definition.traffic_data import TrafficDataPolicy from .definition.vpn_membership import VPNMembershipPolicy from .definition.zone_based_firewall import ZoneBasedFWPolicy -from .lists import ZoneList from .lists_entries import PathPreference, PolicerExceedAction from .localized import LocalizedPolicy from .policy_definition import ( diff --git a/catalystwan/models/policy/list/zone.py b/catalystwan/models/policy/list/zone.py index e69de29bb..502457218 100644 --- a/catalystwan/models/policy/list/zone.py +++ b/catalystwan/models/policy/list/zone.py @@ -0,0 +1,25 @@ +from typing import List, Literal, Set + +from catalystwan.models.common import InterfaceType +from catalystwan.models.policy.lists import PolicyListBase +from catalystwan.models.policy.lists_entries import ZoneListEntry +from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo + + +class ZoneList(PolicyListBase): + type: Literal["zone"] = "zone" + entries: List[ZoneListEntry] = [] + + def assign_vpns(self, vpns: Set[int]) -> None: + self.entries = [ZoneListEntry(vpn=(vpn, None)) for vpn in vpns] + + def assign_interfaces(self, ifs: Set[InterfaceType]) -> None: + self.entries = [ZoneListEntry(interface=interface) for interface in ifs] + + +class ZoneListEditPayload(ZoneList, PolicyListId): + pass + + +class ZoneListInfo(ZoneList, PolicyListInfo): + pass diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py index c81a84f9f..d46a9aca2 100644 --- a/catalystwan/models/policy/lists.py +++ b/catalystwan/models/policy/lists.py @@ -1,12 +1,9 @@ # Copyright 2023 Cisco Systems, Inc. and its affiliates -from typing import Any, List, Literal, Optional, Set +from typing import Any, List, Optional from pydantic import BaseModel, Field -from catalystwan.models.common import InterfaceType -from catalystwan.models.policy.lists_entries import ZoneListEntry - class PolicyListBase(BaseModel): name: str = Field( @@ -22,14 +19,3 @@ def _add_entry(self, entry: Any, single: bool = False) -> None: del self.entries[1:] else: self.entries.append(entry) - - -class ZoneList(PolicyListBase): - type: Literal["zone"] = "zone" - entries: List[ZoneListEntry] = [] - - def assign_vpns(self, vpns: Set[int]) -> None: - self.entries = [ZoneListEntry(vpn=(vpn, None)) for vpn in vpns] - - def assign_interfaces(self, ifs: Set[InterfaceType]) -> None: - self.entries = [ZoneListEntry(interface=interface) for interface in ifs] From f4846ea74ae9e31bde0551f48102e82133b88990 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 02:03:41 +0100 Subject: [PATCH 28/36] move PolicyListBase --- catalystwan/api/policy_api.py | 2 +- catalystwan/models/policy/list/app_probe.py | 3 +-- catalystwan/models/policy/list/as_path.py | 3 +-- catalystwan/models/policy/list/class_map.py | 3 +-- catalystwan/models/policy/list/color.py | 3 +-- catalystwan/models/policy/list/communities.py | 3 +-- .../models/policy/list/data_ipv6_prefix.py | 3 +-- catalystwan/models/policy/list/data_prefix.py | 3 +-- catalystwan/models/policy/list/fqdn.py | 3 +-- .../models/policy/list/geo_location.py | 3 +-- .../models/policy/list/ips_signature.py | 3 +-- catalystwan/models/policy/list/ipv6_prefix.py | 3 +-- catalystwan/models/policy/list/local_app.py | 3 +-- .../models/policy/list/local_domain.py | 3 +-- catalystwan/models/policy/list/mirror.py | 3 +-- catalystwan/models/policy/list/policer.py | 3 +-- catalystwan/models/policy/list/port.py | 3 +-- .../policy/list/preferred_color_group.py | 3 +-- catalystwan/models/policy/list/prefix.py | 3 +-- .../models/policy/list/protocol_name.py | 3 +-- catalystwan/models/policy/list/region.py | 3 +-- catalystwan/models/policy/list/site.py | 3 +-- catalystwan/models/policy/list/sla.py | 3 +-- catalystwan/models/policy/list/tloc.py | 3 +-- catalystwan/models/policy/list/url.py | 3 +-- catalystwan/models/policy/list/vpn.py | 3 +-- catalystwan/models/policy/list/zone.py | 3 +-- catalystwan/models/policy/lists.py | 21 ------------------- catalystwan/models/policy/policy_list.py | 18 +++++++++++++++- 29 files changed, 44 insertions(+), 75 deletions(-) delete mode 100644 catalystwan/models/policy/lists.py diff --git a/catalystwan/api/policy_api.py b/catalystwan/api/policy_api.py index 161d211c1..37e2570d4 100644 --- a/catalystwan/api/policy_api.py +++ b/catalystwan/api/policy_api.py @@ -189,7 +189,6 @@ from catalystwan.models.policy.definition.security_group import SecurityGroup from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.localized import ( LocalizedPolicy, LocalizedPolicyDeviceInfo, @@ -201,6 +200,7 @@ PolicyDefinitionEditResponse, PolicyDefinitionInfo, ) +from catalystwan.models.policy.policy_list import PolicyListBase from catalystwan.models.policy.security import ( AnySecurityPolicy, AnySecurityPolicyInfo, diff --git a/catalystwan/models/policy/list/app_probe.py b/catalystwan/models/policy/list/app_probe.py index 436c44982..0f0c44473 100644 --- a/catalystwan/models/policy/list/app_probe.py +++ b/catalystwan/models/policy/list/app_probe.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import AppProbeClassListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class AppProbeClassList(PolicyListBase): diff --git a/catalystwan/models/policy/list/as_path.py b/catalystwan/models/policy/list/as_path.py index e8802e674..2fd3e9e7a 100644 --- a/catalystwan/models/policy/list/as_path.py +++ b/catalystwan/models/policy/list/as_path.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import ASPathListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class ASPathList(PolicyListBase): diff --git a/catalystwan/models/policy/list/class_map.py b/catalystwan/models/policy/list/class_map.py index 50ee4ba09..bffaf8dde 100644 --- a/catalystwan/models/policy/list/class_map.py +++ b/catalystwan/models/policy/list/class_map.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import ClassMapListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class ClassMapList(PolicyListBase): diff --git a/catalystwan/models/policy/list/color.py b/catalystwan/models/policy/list/color.py index 99cdd6937..dba504e6f 100644 --- a/catalystwan/models/policy/list/color.py +++ b/catalystwan/models/policy/list/color.py @@ -1,9 +1,8 @@ from typing import List, Literal from catalystwan.models.common import TLOCColor -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import ColorListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class ColorList(PolicyListBase): diff --git a/catalystwan/models/policy/list/communities.py b/catalystwan/models/policy/list/communities.py index 5b174cb0d..0f8f6889d 100644 --- a/catalystwan/models/policy/list/communities.py +++ b/catalystwan/models/policy/list/communities.py @@ -1,9 +1,8 @@ from typing import List, Literal from catalystwan.models.common import WellKnownBGPCommunities -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import CommunityListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class CommunityListBase(PolicyListBase): diff --git a/catalystwan/models/policy/list/data_ipv6_prefix.py b/catalystwan/models/policy/list/data_ipv6_prefix.py index 92e936e3b..8da456f29 100644 --- a/catalystwan/models/policy/list/data_ipv6_prefix.py +++ b/catalystwan/models/policy/list/data_ipv6_prefix.py @@ -1,9 +1,8 @@ from ipaddress import IPv6Interface from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import DataIPv6PrefixListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class DataIPv6PrefixList(PolicyListBase): diff --git a/catalystwan/models/policy/list/data_prefix.py b/catalystwan/models/policy/list/data_prefix.py index 52f91606d..0968cfaf0 100644 --- a/catalystwan/models/policy/list/data_prefix.py +++ b/catalystwan/models/policy/list/data_prefix.py @@ -1,9 +1,8 @@ from ipaddress import IPv4Network from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import DataPrefixListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class DataPrefixList(PolicyListBase): diff --git a/catalystwan/models/policy/list/fqdn.py b/catalystwan/models/policy/list/fqdn.py index 100f193d7..be8a8e89e 100644 --- a/catalystwan/models/policy/list/fqdn.py +++ b/catalystwan/models/policy/list/fqdn.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import FQDNListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class FQDNList(PolicyListBase): diff --git a/catalystwan/models/policy/list/geo_location.py b/catalystwan/models/policy/list/geo_location.py index f5589f915..96c1e84a5 100644 --- a/catalystwan/models/policy/list/geo_location.py +++ b/catalystwan/models/policy/list/geo_location.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import GeoLocationListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class GeoLocationList(PolicyListBase): diff --git a/catalystwan/models/policy/list/ips_signature.py b/catalystwan/models/policy/list/ips_signature.py index 31ae71dde..cbd9e47a9 100644 --- a/catalystwan/models/policy/list/ips_signature.py +++ b/catalystwan/models/policy/list/ips_signature.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import IPSSignatureListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class IPSSignatureList(PolicyListBase): diff --git a/catalystwan/models/policy/list/ipv6_prefix.py b/catalystwan/models/policy/list/ipv6_prefix.py index 7f9601927..c6682c2b1 100644 --- a/catalystwan/models/policy/list/ipv6_prefix.py +++ b/catalystwan/models/policy/list/ipv6_prefix.py @@ -1,9 +1,8 @@ from ipaddress import IPv6Interface from typing import List, Literal, Optional -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import IPv6PrefixListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class IPv6PrefixList(PolicyListBase): diff --git a/catalystwan/models/policy/list/local_app.py b/catalystwan/models/policy/list/local_app.py index b3e43a872..8f1195d0e 100644 --- a/catalystwan/models/policy/list/local_app.py +++ b/catalystwan/models/policy/list/local_app.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import LocalAppListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class LocalAppList(PolicyListBase): diff --git a/catalystwan/models/policy/list/local_domain.py b/catalystwan/models/policy/list/local_domain.py index 4a4210596..46283d397 100644 --- a/catalystwan/models/policy/list/local_domain.py +++ b/catalystwan/models/policy/list/local_domain.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import LocalDomainListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class LocalDomainList(PolicyListBase): diff --git a/catalystwan/models/policy/list/mirror.py b/catalystwan/models/policy/list/mirror.py index b4c041304..15579e9d4 100644 --- a/catalystwan/models/policy/list/mirror.py +++ b/catalystwan/models/policy/list/mirror.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import MirrorListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class MirrorList(PolicyListBase): diff --git a/catalystwan/models/policy/list/policer.py b/catalystwan/models/policy/list/policer.py index 9986d9675..f8c2814a3 100644 --- a/catalystwan/models/policy/list/policer.py +++ b/catalystwan/models/policy/list/policer.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import PolicerExceedAction, PolicerListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class PolicerList(PolicyListBase): diff --git a/catalystwan/models/policy/list/port.py b/catalystwan/models/policy/list/port.py index 3e5db4c57..56df2d9b8 100644 --- a/catalystwan/models/policy/list/port.py +++ b/catalystwan/models/policy/list/port.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import PortListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class PortList(PolicyListBase): diff --git a/catalystwan/models/policy/list/preferred_color_group.py b/catalystwan/models/policy/list/preferred_color_group.py index 2685ddaea..ba8eb4869 100644 --- a/catalystwan/models/policy/list/preferred_color_group.py +++ b/catalystwan/models/policy/list/preferred_color_group.py @@ -1,9 +1,8 @@ from typing import List, Literal, Optional, Set, Tuple from catalystwan.models.common import TLOCColor -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import ColorGroupPreference, PathPreference, PreferredColorGroupListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class PreferredColorGroupList(PolicyListBase): diff --git a/catalystwan/models/policy/list/prefix.py b/catalystwan/models/policy/list/prefix.py index cdeb31d42..1e311268f 100644 --- a/catalystwan/models/policy/list/prefix.py +++ b/catalystwan/models/policy/list/prefix.py @@ -1,9 +1,8 @@ from ipaddress import IPv4Network from typing import List, Literal, Optional -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import PrefixListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class PrefixList(PolicyListBase): diff --git a/catalystwan/models/policy/list/protocol_name.py b/catalystwan/models/policy/list/protocol_name.py index 0414bee68..0a3f57fb1 100644 --- a/catalystwan/models/policy/list/protocol_name.py +++ b/catalystwan/models/policy/list/protocol_name.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import ProtocolNameListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class ProtocolNameList(PolicyListBase): diff --git a/catalystwan/models/policy/list/region.py b/catalystwan/models/policy/list/region.py index 6e89d61b9..19c439133 100644 --- a/catalystwan/models/policy/list/region.py +++ b/catalystwan/models/policy/list/region.py @@ -1,8 +1,7 @@ from typing import List, Literal, Set, Tuple -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import RegionListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class RegionList(PolicyListBase): diff --git a/catalystwan/models/policy/list/site.py b/catalystwan/models/policy/list/site.py index b79314975..2957c4320 100644 --- a/catalystwan/models/policy/list/site.py +++ b/catalystwan/models/policy/list/site.py @@ -1,8 +1,7 @@ from typing import List, Literal, Set, Tuple -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import SiteListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class SiteList(PolicyListBase): diff --git a/catalystwan/models/policy/list/sla.py b/catalystwan/models/policy/list/sla.py index a62e050e3..59b633ec4 100644 --- a/catalystwan/models/policy/list/sla.py +++ b/catalystwan/models/policy/list/sla.py @@ -1,9 +1,8 @@ from typing import List, Literal, Optional from uuid import UUID -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import SLAClassListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class SLAClassList(PolicyListBase): diff --git a/catalystwan/models/policy/list/tloc.py b/catalystwan/models/policy/list/tloc.py index 53e96c606..bc5d723f4 100644 --- a/catalystwan/models/policy/list/tloc.py +++ b/catalystwan/models/policy/list/tloc.py @@ -2,9 +2,8 @@ from typing import List, Literal, Optional from catalystwan.models.common import EncapType, TLOCColor -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import TLOCListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class TLOCList(PolicyListBase): diff --git a/catalystwan/models/policy/list/url.py b/catalystwan/models/policy/list/url.py index e9e71c602..eff955f70 100644 --- a/catalystwan/models/policy/list/url.py +++ b/catalystwan/models/policy/list/url.py @@ -1,8 +1,7 @@ from typing import List, Literal -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import URLListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class URLAllowList(PolicyListBase): diff --git a/catalystwan/models/policy/list/vpn.py b/catalystwan/models/policy/list/vpn.py index 6a8a7b3ae..13747b168 100644 --- a/catalystwan/models/policy/list/vpn.py +++ b/catalystwan/models/policy/list/vpn.py @@ -1,8 +1,7 @@ from typing import List, Literal, Set, Tuple -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import VPNListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class VPNList(PolicyListBase): diff --git a/catalystwan/models/policy/list/zone.py b/catalystwan/models/policy/list/zone.py index 502457218..2d44fde25 100644 --- a/catalystwan/models/policy/list/zone.py +++ b/catalystwan/models/policy/list/zone.py @@ -1,9 +1,8 @@ from typing import List, Literal, Set from catalystwan.models.common import InterfaceType -from catalystwan.models.policy.lists import PolicyListBase from catalystwan.models.policy.lists_entries import ZoneListEntry -from catalystwan.models.policy.policy_list import PolicyListId, PolicyListInfo +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo class ZoneList(PolicyListBase): diff --git a/catalystwan/models/policy/lists.py b/catalystwan/models/policy/lists.py deleted file mode 100644 index d46a9aca2..000000000 --- a/catalystwan/models/policy/lists.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2023 Cisco Systems, Inc. and its affiliates - -from typing import Any, List, Optional - -from pydantic import BaseModel, Field - - -class PolicyListBase(BaseModel): - name: str = Field( - pattern="^[a-zA-Z0-9_-]{1,32}$", - description="Can include only alpha-numeric characters, hyphen '-' or underscore '_'; maximum 32 characters", - ) - description: Optional[str] = "Desc Not Required" - entries: List[Any] - - def _add_entry(self, entry: Any, single: bool = False) -> None: - if self.entries and single: - self.entries[0] = entry - del self.entries[1:] - else: - self.entries.append(entry) diff --git a/catalystwan/models/policy/policy_list.py b/catalystwan/models/policy/policy_list.py index f829b411a..c68c3d16b 100644 --- a/catalystwan/models/policy/policy_list.py +++ b/catalystwan/models/policy/policy_list.py @@ -1,12 +1,28 @@ # Copyright 2023 Cisco Systems, Inc. and its affiliates import datetime -from typing import List, Optional +from typing import Any, List, Optional from uuid import UUID from pydantic import BaseModel, Field +class PolicyListBase(BaseModel): + name: str = Field( + pattern="^[a-zA-Z0-9_-]{1,32}$", + description="Can include only alpha-numeric characters, hyphen '-' or underscore '_'; maximum 32 characters", + ) + description: Optional[str] = "Desc Not Required" + entries: List[Any] + + def _add_entry(self, entry: Any, single: bool = False) -> None: + if self.entries and single: + self.entries[0] = entry + del self.entries[1:] + else: + self.entries.append(entry) + + class InfoTag(BaseModel): info_tag: Optional[str] = Field("", alias="infoTag") From 476f4c582d121348d2f5fe2b920126404bc26218 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 02:08:01 +0100 Subject: [PATCH 29/36] add copyright --- catalystwan/models/policy/list/app_probe.py | 2 ++ catalystwan/models/policy/list/as_path.py | 2 ++ catalystwan/models/policy/list/class_map.py | 2 ++ catalystwan/models/policy/list/color.py | 2 ++ catalystwan/models/policy/list/communities.py | 2 ++ catalystwan/models/policy/list/data_ipv6_prefix.py | 2 ++ catalystwan/models/policy/list/data_prefix.py | 2 ++ .../models/policy/list/expanded_community.py | 1 + catalystwan/models/policy/list/fqdn.py | 2 ++ catalystwan/models/policy/list/geo_location.py | 2 ++ catalystwan/models/policy/list/ips_signature.py | 2 ++ catalystwan/models/policy/list/ipv6_prefix.py | 2 ++ catalystwan/models/policy/list/local_app.py | 2 ++ catalystwan/models/policy/list/local_domain.py | 2 ++ catalystwan/models/policy/list/mirror.py | 2 ++ catalystwan/models/policy/list/policer.py | 2 ++ catalystwan/models/policy/list/port.py | 2 ++ .../models/policy/list/preferred_color_group.py | 2 ++ catalystwan/models/policy/list/prefix.py | 2 ++ catalystwan/models/policy/list/protocol_name.py | 2 ++ catalystwan/models/policy/list/region.py | 2 ++ catalystwan/models/policy/list/site.py | 2 ++ catalystwan/models/policy/list/sla.py | 2 ++ catalystwan/models/policy/list/tloc.py | 2 ++ catalystwan/models/policy/list/url.py | 2 ++ catalystwan/models/policy/list/vpn.py | 2 ++ catalystwan/models/policy/list/zone.py | 2 ++ catalystwan/models/policy/policy_list.py | 14 ++++++++------ 28 files changed, 61 insertions(+), 6 deletions(-) diff --git a/catalystwan/models/policy/list/app_probe.py b/catalystwan/models/policy/list/app_probe.py index 0f0c44473..e40c8f54f 100644 --- a/catalystwan/models/policy/list/app_probe.py +++ b/catalystwan/models/policy/list/app_probe.py @@ -1,3 +1,5 @@ +# Copyright 2024 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import AppProbeClassListEntry diff --git a/catalystwan/models/policy/list/as_path.py b/catalystwan/models/policy/list/as_path.py index 2fd3e9e7a..4aa8c0033 100644 --- a/catalystwan/models/policy/list/as_path.py +++ b/catalystwan/models/policy/list/as_path.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import ASPathListEntry diff --git a/catalystwan/models/policy/list/class_map.py b/catalystwan/models/policy/list/class_map.py index bffaf8dde..4a82dfff4 100644 --- a/catalystwan/models/policy/list/class_map.py +++ b/catalystwan/models/policy/list/class_map.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import ClassMapListEntry diff --git a/catalystwan/models/policy/list/color.py b/catalystwan/models/policy/list/color.py index dba504e6f..28415f716 100644 --- a/catalystwan/models/policy/list/color.py +++ b/catalystwan/models/policy/list/color.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.common import TLOCColor diff --git a/catalystwan/models/policy/list/communities.py b/catalystwan/models/policy/list/communities.py index 0f8f6889d..aac5f36da 100644 --- a/catalystwan/models/policy/list/communities.py +++ b/catalystwan/models/policy/list/communities.py @@ -1,3 +1,5 @@ +# Copyright 2024 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.common import WellKnownBGPCommunities diff --git a/catalystwan/models/policy/list/data_ipv6_prefix.py b/catalystwan/models/policy/list/data_ipv6_prefix.py index 8da456f29..128c3b183 100644 --- a/catalystwan/models/policy/list/data_ipv6_prefix.py +++ b/catalystwan/models/policy/list/data_ipv6_prefix.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from ipaddress import IPv6Interface from typing import List, Literal diff --git a/catalystwan/models/policy/list/data_prefix.py b/catalystwan/models/policy/list/data_prefix.py index 0968cfaf0..ce12c0ea1 100644 --- a/catalystwan/models/policy/list/data_prefix.py +++ b/catalystwan/models/policy/list/data_prefix.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from ipaddress import IPv4Network from typing import List, Literal diff --git a/catalystwan/models/policy/list/expanded_community.py b/catalystwan/models/policy/list/expanded_community.py index e69de29bb..2cb417b59 100644 --- a/catalystwan/models/policy/list/expanded_community.py +++ b/catalystwan/models/policy/list/expanded_community.py @@ -0,0 +1 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates diff --git a/catalystwan/models/policy/list/fqdn.py b/catalystwan/models/policy/list/fqdn.py index be8a8e89e..8162ba6e3 100644 --- a/catalystwan/models/policy/list/fqdn.py +++ b/catalystwan/models/policy/list/fqdn.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import FQDNListEntry diff --git a/catalystwan/models/policy/list/geo_location.py b/catalystwan/models/policy/list/geo_location.py index 96c1e84a5..938845b56 100644 --- a/catalystwan/models/policy/list/geo_location.py +++ b/catalystwan/models/policy/list/geo_location.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import GeoLocationListEntry diff --git a/catalystwan/models/policy/list/ips_signature.py b/catalystwan/models/policy/list/ips_signature.py index cbd9e47a9..7d25d21ee 100644 --- a/catalystwan/models/policy/list/ips_signature.py +++ b/catalystwan/models/policy/list/ips_signature.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import IPSSignatureListEntry diff --git a/catalystwan/models/policy/list/ipv6_prefix.py b/catalystwan/models/policy/list/ipv6_prefix.py index c6682c2b1..5842e4375 100644 --- a/catalystwan/models/policy/list/ipv6_prefix.py +++ b/catalystwan/models/policy/list/ipv6_prefix.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from ipaddress import IPv6Interface from typing import List, Literal, Optional diff --git a/catalystwan/models/policy/list/local_app.py b/catalystwan/models/policy/list/local_app.py index 8f1195d0e..10f13502b 100644 --- a/catalystwan/models/policy/list/local_app.py +++ b/catalystwan/models/policy/list/local_app.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import LocalAppListEntry diff --git a/catalystwan/models/policy/list/local_domain.py b/catalystwan/models/policy/list/local_domain.py index 46283d397..5c35a4d51 100644 --- a/catalystwan/models/policy/list/local_domain.py +++ b/catalystwan/models/policy/list/local_domain.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import LocalDomainListEntry diff --git a/catalystwan/models/policy/list/mirror.py b/catalystwan/models/policy/list/mirror.py index 15579e9d4..d8a2e8587 100644 --- a/catalystwan/models/policy/list/mirror.py +++ b/catalystwan/models/policy/list/mirror.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import MirrorListEntry diff --git a/catalystwan/models/policy/list/policer.py b/catalystwan/models/policy/list/policer.py index f8c2814a3..e505fd098 100644 --- a/catalystwan/models/policy/list/policer.py +++ b/catalystwan/models/policy/list/policer.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import PolicerExceedAction, PolicerListEntry diff --git a/catalystwan/models/policy/list/port.py b/catalystwan/models/policy/list/port.py index 56df2d9b8..5a99c1905 100644 --- a/catalystwan/models/policy/list/port.py +++ b/catalystwan/models/policy/list/port.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import PortListEntry diff --git a/catalystwan/models/policy/list/preferred_color_group.py b/catalystwan/models/policy/list/preferred_color_group.py index ba8eb4869..83581c707 100644 --- a/catalystwan/models/policy/list/preferred_color_group.py +++ b/catalystwan/models/policy/list/preferred_color_group.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal, Optional, Set, Tuple from catalystwan.models.common import TLOCColor diff --git a/catalystwan/models/policy/list/prefix.py b/catalystwan/models/policy/list/prefix.py index 1e311268f..663f11466 100644 --- a/catalystwan/models/policy/list/prefix.py +++ b/catalystwan/models/policy/list/prefix.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from ipaddress import IPv4Network from typing import List, Literal, Optional diff --git a/catalystwan/models/policy/list/protocol_name.py b/catalystwan/models/policy/list/protocol_name.py index 0a3f57fb1..046ac1519 100644 --- a/catalystwan/models/policy/list/protocol_name.py +++ b/catalystwan/models/policy/list/protocol_name.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import ProtocolNameListEntry diff --git a/catalystwan/models/policy/list/region.py b/catalystwan/models/policy/list/region.py index 19c439133..03848a361 100644 --- a/catalystwan/models/policy/list/region.py +++ b/catalystwan/models/policy/list/region.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal, Set, Tuple from catalystwan.models.policy.lists_entries import RegionListEntry diff --git a/catalystwan/models/policy/list/site.py b/catalystwan/models/policy/list/site.py index 2957c4320..6cf434c53 100644 --- a/catalystwan/models/policy/list/site.py +++ b/catalystwan/models/policy/list/site.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal, Set, Tuple from catalystwan.models.policy.lists_entries import SiteListEntry diff --git a/catalystwan/models/policy/list/sla.py b/catalystwan/models/policy/list/sla.py index 59b633ec4..e698cb600 100644 --- a/catalystwan/models/policy/list/sla.py +++ b/catalystwan/models/policy/list/sla.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal, Optional from uuid import UUID diff --git a/catalystwan/models/policy/list/tloc.py b/catalystwan/models/policy/list/tloc.py index bc5d723f4..fd63b001c 100644 --- a/catalystwan/models/policy/list/tloc.py +++ b/catalystwan/models/policy/list/tloc.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from ipaddress import IPv4Address from typing import List, Literal, Optional diff --git a/catalystwan/models/policy/list/url.py b/catalystwan/models/policy/list/url.py index eff955f70..add5f0a9d 100644 --- a/catalystwan/models/policy/list/url.py +++ b/catalystwan/models/policy/list/url.py @@ -1,3 +1,5 @@ +# Copyright 2024 Cisco Systems, Inc. and its affiliates + from typing import List, Literal from catalystwan.models.policy.lists_entries import URLListEntry diff --git a/catalystwan/models/policy/list/vpn.py b/catalystwan/models/policy/list/vpn.py index 13747b168..6baaffcd0 100644 --- a/catalystwan/models/policy/list/vpn.py +++ b/catalystwan/models/policy/list/vpn.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal, Set, Tuple from catalystwan.models.policy.lists_entries import VPNListEntry diff --git a/catalystwan/models/policy/list/zone.py b/catalystwan/models/policy/list/zone.py index 2d44fde25..5b8a6f867 100644 --- a/catalystwan/models/policy/list/zone.py +++ b/catalystwan/models/policy/list/zone.py @@ -1,3 +1,5 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + from typing import List, Literal, Set from catalystwan.models.common import InterfaceType diff --git a/catalystwan/models/policy/policy_list.py b/catalystwan/models/policy/policy_list.py index c68c3d16b..0397c5d10 100644 --- a/catalystwan/models/policy/policy_list.py +++ b/catalystwan/models/policy/policy_list.py @@ -24,21 +24,23 @@ def _add_entry(self, entry: Any, single: bool = False) -> None: class InfoTag(BaseModel): - info_tag: Optional[str] = Field("", alias="infoTag") + info_tag: Optional[str] = Field("", serialization_alias="infoTag", validation_alias="infoTag") class PolicyListId(BaseModel): - list_id: UUID = Field(alias="listId") + list_id: UUID = Field(serialization_alias="listId", validation_alias="listId") class PolicyListInfo(PolicyListId, InfoTag): - last_updated: datetime.datetime = Field(alias="lastUpdated") + last_updated: datetime.datetime = Field(serialization_alias="lastUpdated", validation_alias="lastUpdated") owner: str - read_only: bool = Field(alias="readOnly") + read_only: bool = Field(serialization_alias="readOnly", validation_alias="readOnly") version: str - reference_count: int = Field(alias="referenceCount") + reference_count: int = Field(serialization_alias="referenceCount", validation_alias="referenceCount") references: List - is_activated_by_vsmart: Optional[bool] = Field(None, alias="isActivatedByVsmart") + is_activated_by_vsmart: Optional[bool] = Field( + None, serialization_alias="isActivatedByVsmart", validation_alias="isActivatedByVsmart" + ) class PolicyListPreview(BaseModel): From 1f5db574f5876bfc775cfb39852a02c61edd5bb2 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 02:50:53 +0100 Subject: [PATCH 30/36] separate policy definition models from endpoints --- catalystwan/api/policy_api.py | 136 ++++++----------- .../policy/definition/access_control_list.py | 15 +- .../definition/access_control_list_ipv6.py | 15 +- .../policy/definition/control.py | 15 +- .../policy/definition/device_access.py | 15 +- .../policy/definition/device_access_ipv6.py | 15 +- .../policy/definition/hub_and_spoke.py | 15 +- .../configuration/policy/definition/mesh.py | 11 +- .../policy/definition/qos_map.py | 11 +- .../policy/definition/rewrite.py | 15 +- .../policy/definition/rule_set.py | 11 +- .../policy/definition/security_group.py | 15 +- .../policy/definition/traffic_data.py | 15 +- .../policy/definition/vpn_membership.py | 15 +- .../policy/definition/zone_based_firewall.py | 15 +- .../models/configuration/config_migration.py | 4 +- catalystwan/models/policy/__init__.py | 144 +++++++++++++----- .../policy/definition/access_control_list.py | 10 ++ .../definition/access_control_list_ipv6.py | 10 ++ .../models/policy/definition/control.py | 10 ++ .../models/policy/definition/device_access.py | 10 ++ .../policy/definition/device_access_ipv6.py | 10 ++ .../models/policy/definition/hub_and_spoke.py | 14 +- catalystwan/models/policy/definition/mesh.py | 14 +- .../models/policy/definition/qos_map.py | 14 +- .../models/policy/definition/rewrite.py | 10 ++ .../models/policy/definition/rule_set.py | 16 +- .../policy/definition/security_group.py | 16 +- .../models/policy/definition/traffic_data.py | 10 ++ .../policy/definition/vpn_membership.py | 14 +- .../policy/definition/zone_based_firewall.py | 10 ++ 31 files changed, 368 insertions(+), 282 deletions(-) diff --git a/catalystwan/api/policy_api.py b/catalystwan/api/policy_api.py index 37e2570d4..6221fd3d7 100644 --- a/catalystwan/api/policy_api.py +++ b/catalystwan/api/policy_api.py @@ -7,108 +7,47 @@ from catalystwan.api.task_status_api import Task from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints, PolicyListEndpoints -from catalystwan.endpoints.configuration.policy.definition.access_control_list import ( - AclPolicyGetResponse, - ConfigurationPolicyAclDefinition, -) +from catalystwan.endpoints.configuration.policy.definition.access_control_list import ConfigurationPolicyAclDefinition from catalystwan.endpoints.configuration.policy.definition.access_control_list_ipv6 import ( - AclIPv6PolicyGetResponse, ConfigurationPolicyAclIPv6Definition, ) -from catalystwan.endpoints.configuration.policy.definition.control import ( - ConfigurationPolicyControlDefinition, - ControlPolicyGetResponse, -) +from catalystwan.endpoints.configuration.policy.definition.control import ConfigurationPolicyControlDefinition from catalystwan.endpoints.configuration.policy.definition.device_access import ( ConfigurationPolicyDeviceAccessDefinition, - DeviceAccessPolicyGetResponse, ) from catalystwan.endpoints.configuration.policy.definition.device_access_ipv6 import ( ConfigurationPolicyDeviceAccessIPv6Definition, - DeviceAccessIPv6PolicyGetResponse, -) -from catalystwan.endpoints.configuration.policy.definition.hub_and_spoke import ( - ConfigurationPolicyHubAndSpokeDefinition, - HubAndSpokePolicyGetResponse, -) -from catalystwan.endpoints.configuration.policy.definition.mesh import ( - ConfigurationPolicyMeshDefinition, - MeshPolicyGetResponse, -) -from catalystwan.endpoints.configuration.policy.definition.qos_map import ( - ConfigurationPolicyQoSMapDefinition, - QoSMapPolicyGetResponse, -) -from catalystwan.endpoints.configuration.policy.definition.rewrite import ( - ConfigurationPolicyRewriteRuleDefinition, - RewritePolicyGetResponse, -) -from catalystwan.endpoints.configuration.policy.definition.rule_set import ( - ConfigurationPolicyRuleSetDefinition, - RuleSetGetResponse, ) +from catalystwan.endpoints.configuration.policy.definition.hub_and_spoke import ConfigurationPolicyHubAndSpokeDefinition +from catalystwan.endpoints.configuration.policy.definition.mesh import ConfigurationPolicyMeshDefinition +from catalystwan.endpoints.configuration.policy.definition.qos_map import ConfigurationPolicyQoSMapDefinition +from catalystwan.endpoints.configuration.policy.definition.rewrite import ConfigurationPolicyRewriteRuleDefinition +from catalystwan.endpoints.configuration.policy.definition.rule_set import ConfigurationPolicyRuleSetDefinition from catalystwan.endpoints.configuration.policy.definition.security_group import ( ConfigurationPolicySecurityGroupDefinition, - SecurityGroupGetResponse, -) -from catalystwan.endpoints.configuration.policy.definition.traffic_data import ( - ConfigurationPolicyDataDefinition, - TrafficDataPolicy, - TrafficDataPolicyGetResponse, ) +from catalystwan.endpoints.configuration.policy.definition.traffic_data import ConfigurationPolicyDataDefinition from catalystwan.endpoints.configuration.policy.definition.vpn_membership import ( ConfigurationPolicyVPNMembershipGroupDefinition, - VPNMembershipPolicyGetResponse, ) from catalystwan.endpoints.configuration.policy.definition.zone_based_firewall import ( ConfigurationPolicyZoneBasedFirewallDefinition, - ZoneBasedFWPolicyGetResponse, ) from catalystwan.endpoints.configuration.policy.list.app import AppListInfo, ConfigurationPolicyApplicationList -from catalystwan.endpoints.configuration.policy.list.app_probe import ( - AppProbeClassListInfo, - ConfigurationPolicyAppProbeClassList, -) +from catalystwan.endpoints.configuration.policy.list.app_probe import ConfigurationPolicyAppProbeClassList from catalystwan.endpoints.configuration.policy.list.as_path import ASPathListInfo, ConfigurationPolicyASPathList -from catalystwan.endpoints.configuration.policy.list.class_map import ( - ClassMapListInfo, - ConfigurationPolicyForwardingClassList, -) +from catalystwan.endpoints.configuration.policy.list.class_map import ConfigurationPolicyForwardingClassList from catalystwan.endpoints.configuration.policy.list.color import ColorListInfo, ConfigurationPolicyColorList -from catalystwan.endpoints.configuration.policy.list.community import ( - CommunityListInfo, - ConfigurationPolicyCommunityList, -) -from catalystwan.endpoints.configuration.policy.list.data_ipv6_prefix import ( - ConfigurationPolicyDataIPv6PrefixList, - DataIPv6PrefixListInfo, -) -from catalystwan.endpoints.configuration.policy.list.data_prefix import ( - ConfigurationPolicyDataPrefixList, - DataPrefixListInfo, -) -from catalystwan.endpoints.configuration.policy.list.expanded_community import ( - ConfigurationPolicyExpandedCommunityList, - ExpandedCommunityListInfo, -) +from catalystwan.endpoints.configuration.policy.list.community import ConfigurationPolicyCommunityList +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.fqdn import ConfigurationPolicyFQDNList, FQDNListInfo -from catalystwan.endpoints.configuration.policy.list.geo_location import ( - ConfigurationPolicyGeoLocationList, - GeoLocationListInfo, -) -from catalystwan.endpoints.configuration.policy.list.ips_signature import ( - ConfigurationPolicyIPSSignatureList, - IPSSignatureListInfo, -) -from catalystwan.endpoints.configuration.policy.list.ipv6_prefix import ( - ConfigurationPolicyIPv6PrefixList, - IPv6PrefixListInfo, -) +from catalystwan.endpoints.configuration.policy.list.geo_location import ConfigurationPolicyGeoLocationList +from catalystwan.endpoints.configuration.policy.list.ips_signature import ConfigurationPolicyIPSSignatureList +from catalystwan.endpoints.configuration.policy.list.ipv6_prefix import ConfigurationPolicyIPv6PrefixList from catalystwan.endpoints.configuration.policy.list.local_app import ConfigurationPolicyLocalAppList, LocalAppListInfo -from catalystwan.endpoints.configuration.policy.list.local_domain import ( - ConfigurationPolicyLocalDomainList, - LocalDomainListInfo, -) +from catalystwan.endpoints.configuration.policy.list.local_domain import ConfigurationPolicyLocalDomainList from catalystwan.endpoints.configuration.policy.list.mirror import ConfigurationPolicyMirrorList, MirrorListInfo from catalystwan.endpoints.configuration.policy.list.policer import ConfigurationPolicyPolicerClassList, PolicerListInfo from catalystwan.endpoints.configuration.policy.list.port import ConfigurationPolicyPortList, PortListInfo @@ -176,19 +115,32 @@ ZoneList, ) from catalystwan.models.policy.centralized import CentralizedPolicy, CentralizedPolicyEditPayload, CentralizedPolicyInfo -from catalystwan.models.policy.definition.access_control_list import AclPolicy -from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy -from catalystwan.models.policy.definition.control import ControlPolicy -from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy -from catalystwan.models.policy.definition.device_access_ipv6 import DeviceAccessIPv6Policy -from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy -from catalystwan.models.policy.definition.mesh import MeshPolicy -from catalystwan.models.policy.definition.qos_map import QoSMapPolicy -from catalystwan.models.policy.definition.rewrite import RewritePolicy -from catalystwan.models.policy.definition.rule_set import RuleSet -from catalystwan.models.policy.definition.security_group import SecurityGroup -from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy -from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy +from catalystwan.models.policy.definition.access_control_list import AclPolicy, AclPolicyGetResponse +from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy, AclIPv6PolicyGetResponse +from catalystwan.models.policy.definition.control import ControlPolicy, ControlPolicyGetResponse +from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy, DeviceAccessPolicyGetResponse +from catalystwan.models.policy.definition.device_access_ipv6 import ( + DeviceAccessIPv6Policy, + DeviceAccessIPv6PolicyGetResponse, +) +from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy, HubAndSpokePolicyGetResponse +from catalystwan.models.policy.definition.mesh import MeshPolicy, MeshPolicyGetResponse +from catalystwan.models.policy.definition.qos_map import QoSMapPolicy, QoSMapPolicyGetResponse +from catalystwan.models.policy.definition.rewrite import RewritePolicy, RewritePolicyGetResponse +from catalystwan.models.policy.definition.rule_set import RuleSet, RuleSetGetResponse +from catalystwan.models.policy.definition.security_group import SecurityGroup, SecurityGroupGetResponse +from catalystwan.models.policy.definition.traffic_data import TrafficDataPolicy, TrafficDataPolicyGetResponse +from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy, VPNMembershipPolicyGetResponse +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.data_ipv6_prefix import DataIPv6PrefixListInfo +from catalystwan.models.policy.list.data_prefix import DataPrefixListInfo +from catalystwan.models.policy.list.geo_location import GeoLocationListInfo +from catalystwan.models.policy.list.ips_signature import IPSSignatureListInfo +from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixListInfo +from catalystwan.models.policy.list.local_domain import LocalDomainListInfo from catalystwan.models.policy.localized import ( LocalizedPolicy, LocalizedPolicyDeviceInfo, diff --git a/catalystwan/endpoints/configuration/policy/definition/access_control_list.py b/catalystwan/endpoints/configuration/policy/definition/access_control_list.py index 1edd9be85..4ee7cadc3 100644 --- a/catalystwan/endpoints/configuration/policy/definition/access_control_list.py +++ b/catalystwan/endpoints/configuration/policy/definition/access_control_list.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.access_control_list import AclPolicy +from catalystwan.models.policy.definition.access_control_list import ( + AclPolicy, + AclPolicyEditPayload, + AclPolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class AclPolicyEditPayload(AclPolicy, PolicyDefinitionId): - pass - - -class AclPolicyGetResponse(AclPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyAclDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/acl") def create_policy_definition(self, payload: AclPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py b/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py index 980dcc4d1..8c4ef74a1 100644 --- a/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py +++ b/catalystwan/endpoints/configuration/policy/definition/access_control_list_ipv6.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy +from catalystwan.models.policy.definition.access_control_list_ipv6 import ( + AclIPv6Policy, + AclIPv6PolicyEditPayload, + AclIPv6PolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class AclIPv6PolicyEditPayload(AclIPv6Policy, PolicyDefinitionId): - pass - - -class AclIPv6PolicyGetResponse(AclIPv6Policy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyAclIPv6Definition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/aclv6") def create_policy_definition(self, payload: AclIPv6Policy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/control.py b/catalystwan/endpoints/configuration/policy/definition/control.py index a788b7630..b5f94c8f0 100644 --- a/catalystwan/endpoints/configuration/policy/definition/control.py +++ b/catalystwan/endpoints/configuration/policy/definition/control.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.control import ControlPolicy +from catalystwan.models.policy.definition.control import ( + ControlPolicy, + ControlPolicyEditPayload, + ControlPolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class ControlPolicyEditPayload(ControlPolicy, PolicyDefinitionId): - pass - - -class ControlPolicyGetResponse(ControlPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyControlDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/control") def create_policy_definition(self, payload: ControlPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/device_access.py b/catalystwan/endpoints/configuration/policy/definition/device_access.py index b86e26f54..c12ec51a4 100644 --- a/catalystwan/endpoints/configuration/policy/definition/device_access.py +++ b/catalystwan/endpoints/configuration/policy/definition/device_access.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.device_access import DeviceAccessPolicy +from catalystwan.models.policy.definition.device_access import ( + DeviceAccessPolicy, + DeviceAccessPolicyEditPayload, + DeviceAccessPolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class DeviceAccessPolicyEditPayload(DeviceAccessPolicy, PolicyDefinitionId): - pass - - -class DeviceAccessPolicyGetResponse(DeviceAccessPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyDeviceAccessDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/deviceaccesspolicy") def create_policy_definition(self, payload: DeviceAccessPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py b/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py index 8cd8006ae..525c685c4 100644 --- a/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py +++ b/catalystwan/endpoints/configuration/policy/definition/device_access_ipv6.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.device_access_ipv6 import DeviceAccessIPv6Policy +from catalystwan.models.policy.definition.device_access_ipv6 import ( + DeviceAccessIPv6Policy, + DeviceAccessIPv6PolicyEditPayload, + DeviceAccessIPv6PolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class DeviceAccessIPv6PolicyEditPayload(DeviceAccessIPv6Policy, PolicyDefinitionId): - pass - - -class DeviceAccessIPv6PolicyGetResponse(DeviceAccessIPv6Policy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyDeviceAccessIPv6Definition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/deviceaccesspolicyv6") def create_policy_definition(self, payload: DeviceAccessIPv6Policy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py b/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py index b124820da..2c783f8d0 100644 --- a/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py +++ b/catalystwan/endpoints/configuration/policy/definition/hub_and_spoke.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.hub_and_spoke import HubAndSpokePolicy +from catalystwan.models.policy.definition.hub_and_spoke import ( + HubAndSpokePolicy, + HubAndSpokePolicyEditPayload, + HubAndSpokePolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class HubAndSpokePolicyEditPayload(HubAndSpokePolicy, PolicyDefinitionId): - pass - - -class HubAndSpokePolicyGetResponse(HubAndSpokePolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyHubAndSpokeDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/hubandspoke") def create_policy_definition(self, payload: HubAndSpokePolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/mesh.py b/catalystwan/endpoints/configuration/policy/definition/mesh.py index ee89c4112..6a2e6b413 100644 --- a/catalystwan/endpoints/configuration/policy/definition/mesh.py +++ b/catalystwan/endpoints/configuration/policy/definition/mesh.py @@ -5,10 +5,9 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.mesh import MeshPolicy +from catalystwan.models.policy.definition.mesh import MeshPolicy, MeshPolicyEditPayload, MeshPolicyGetResponse from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +15,6 @@ from catalystwan.typed_list import DataSequence -class MeshPolicyEditPayload(MeshPolicy, PolicyDefinitionId): - pass - - -class MeshPolicyGetResponse(MeshPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyMeshDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/mesh") def create_policy_definition(self, payload: MeshPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/qos_map.py b/catalystwan/endpoints/configuration/policy/definition/qos_map.py index c5f27796d..c07ea297b 100644 --- a/catalystwan/endpoints/configuration/policy/definition/qos_map.py +++ b/catalystwan/endpoints/configuration/policy/definition/qos_map.py @@ -5,10 +5,9 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.qos_map import QoSMapPolicy +from catalystwan.models.policy.definition.qos_map import QoSMapPolicy, QoSMapPolicyEditPayload, QoSMapPolicyGetResponse from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +15,6 @@ from catalystwan.typed_list import DataSequence -class QoSMapPolicyEditPayload(QoSMapPolicy, PolicyDefinitionId): - pass - - -class QoSMapPolicyGetResponse(QoSMapPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyQoSMapDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/qosmap") def create_policy_definition(self, payload: QoSMapPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/rewrite.py b/catalystwan/endpoints/configuration/policy/definition/rewrite.py index ac1a95e6a..7d9d656ab 100644 --- a/catalystwan/endpoints/configuration/policy/definition/rewrite.py +++ b/catalystwan/endpoints/configuration/policy/definition/rewrite.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.rewrite import RewritePolicy +from catalystwan.models.policy.definition.rewrite import ( + RewritePolicy, + RewritePolicyEditPayload, + RewritePolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class RewritePolicyEditPayload(RewritePolicy, PolicyDefinitionId): - pass - - -class RewritePolicyGetResponse(RewritePolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyRewriteRuleDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/rewriterule") def create_policy_definition(self, payload: RewritePolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/rule_set.py b/catalystwan/endpoints/configuration/policy/definition/rule_set.py index 4db698452..92119e2d4 100644 --- a/catalystwan/endpoints/configuration/policy/definition/rule_set.py +++ b/catalystwan/endpoints/configuration/policy/definition/rule_set.py @@ -5,10 +5,9 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.rule_set import RuleSet +from catalystwan.models.policy.definition.rule_set import RuleSet, RuleSetEditPayload, RuleSetGetResponse from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +15,6 @@ from catalystwan.typed_list import DataSequence -class RuleSetEditPayload(RuleSet, PolicyDefinitionId): - pass - - -class RuleSetGetResponse(RuleSet, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyRuleSetDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/ruleset") def create_policy_definition(self, payload: RuleSet) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/security_group.py b/catalystwan/endpoints/configuration/policy/definition/security_group.py index 22b411129..a210f2eae 100644 --- a/catalystwan/endpoints/configuration/policy/definition/security_group.py +++ b/catalystwan/endpoints/configuration/policy/definition/security_group.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.security_group import SecurityGroup +from catalystwan.models.policy.definition.security_group import ( + SecurityGroup, + SecurityGroupEditPayload, + SecurityGroupGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class SecurityGroupEditPayload(SecurityGroup, PolicyDefinitionId): - pass - - -class SecurityGroupGetResponse(SecurityGroup, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicySecurityGroupDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/securitygroup") def create_policy_definition(self, payload: SecurityGroup) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/traffic_data.py b/catalystwan/endpoints/configuration/policy/definition/traffic_data.py index ade21a240..4a5e6a774 100644 --- a/catalystwan/endpoints/configuration/policy/definition/traffic_data.py +++ b/catalystwan/endpoints/configuration/policy/definition/traffic_data.py @@ -6,10 +6,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.traffic_data import TrafficDataPolicy +from catalystwan.models.policy.definition.traffic_data import ( + TrafficDataPolicy, + TrafficDataPolicyEditPayload, + TrafficDataPolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -17,14 +20,6 @@ from catalystwan.typed_list import DataSequence -class TrafficDataPolicyEditPayload(TrafficDataPolicy, PolicyDefinitionId): - pass - - -class TrafficDataPolicyGetResponse(TrafficDataPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyDataDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/data") def create_policy_definition(self, payload: TrafficDataPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py b/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py index 606da00e6..22862eeb1 100644 --- a/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py +++ b/catalystwan/endpoints/configuration/policy/definition/vpn_membership.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.vpn_membership import VPNMembershipPolicy +from catalystwan.models.policy.definition.vpn_membership import ( + VPNMembershipPolicy, + VPNMembershipPolicyEditPayload, + VPNMembershipPolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class VPNMembershipPolicyEditPayload(VPNMembershipPolicy, PolicyDefinitionId): - pass - - -class VPNMembershipPolicyGetResponse(VPNMembershipPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyVPNMembershipGroupDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/vpnmembershipgroup") def create_policy_definition(self, payload: VPNMembershipPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py b/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py index 9ba78575e..1808f98f6 100644 --- a/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py +++ b/catalystwan/endpoints/configuration/policy/definition/zone_based_firewall.py @@ -5,10 +5,13 @@ from catalystwan.endpoints import APIEndpoints, delete, get, post, put from catalystwan.endpoints.configuration.policy.abstractions import PolicyDefinitionEndpoints -from catalystwan.models.policy.definition.zone_based_firewall import ZoneBasedFWPolicy +from catalystwan.models.policy.definition.zone_based_firewall import ( + ZoneBasedFWPolicy, + ZoneBasedFWPolicyEditPayload, + ZoneBasedFWPolicyGetResponse, +) from catalystwan.models.policy.policy_definition import ( PolicyDefinitionEditResponse, - PolicyDefinitionGetResponse, PolicyDefinitionId, PolicyDefinitionInfo, PolicyDefinitionPreview, @@ -16,14 +19,6 @@ from catalystwan.typed_list import DataSequence -class ZoneBasedFWPolicyEditPayload(ZoneBasedFWPolicy, PolicyDefinitionId): - pass - - -class ZoneBasedFWPolicyGetResponse(ZoneBasedFWPolicy, PolicyDefinitionGetResponse): - pass - - class ConfigurationPolicyZoneBasedFirewallDefinition(APIEndpoints, PolicyDefinitionEndpoints): @post("/template/policy/definition/zonebasedfw") def create_policy_definition(self, payload: ZoneBasedFWPolicy) -> PolicyDefinitionId: diff --git a/catalystwan/models/configuration/config_migration.py b/catalystwan/models/configuration/config_migration.py index 70273377e..3e8b3e8b9 100644 --- a/catalystwan/models/configuration/config_migration.py +++ b/catalystwan/models/configuration/config_migration.py @@ -12,7 +12,7 @@ from catalystwan.models.configuration.feature_profile.sdwan.policy_object import AnyPolicyObjectParcel from catalystwan.models.configuration.feature_profile.sdwan.system import AnySystemParcel from catalystwan.models.configuration.topology_group import TopologyGroup -from catalystwan.models.policy import AnyPolicyDefinition, AnyPolicyList +from catalystwan.models.policy import AnyPolicyDefinition, AnyPolicyListInfo from catalystwan.models.policy.centralized import CentralizedPolicyInfo from catalystwan.models.policy.localized import LocalizedPolicyInfo from catalystwan.models.policy.security import AnySecurityPolicyInfo @@ -40,7 +40,7 @@ class UX1Policies(BaseModel): policy_definitions: List[AnyPolicyDefinition] = Field( default=[], serialization_alias="policyDefinitions", validation_alias="policyDefinitions" ) - policy_lists: List[AnyPolicyList] = Field( + policy_lists: List[AnyPolicyListInfo] = Field( default=[], serialization_alias="policyLists", validation_alias="policyLists" ) diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 7c209cbba..8630c493a 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -6,49 +6,54 @@ from pydantic import Field from typing_extensions import Annotated -from catalystwan.models.policy.list.app import AppList -from catalystwan.models.policy.list.app_probe import AppProbeClassList -from catalystwan.models.policy.list.as_path import ASPathList -from catalystwan.models.policy.list.class_map import ClassMapList -from catalystwan.models.policy.list.color import ColorList -from catalystwan.models.policy.list.communities import CommunityList, ExpandedCommunityList -from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixList -from catalystwan.models.policy.list.data_prefix import DataPrefixList -from catalystwan.models.policy.list.fqdn import FQDNList -from catalystwan.models.policy.list.geo_location import GeoLocationList -from catalystwan.models.policy.list.ips_signature import IPSSignatureList -from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixList -from catalystwan.models.policy.list.local_app import LocalAppList -from catalystwan.models.policy.list.local_domain import LocalDomainList -from catalystwan.models.policy.list.mirror import MirrorList -from catalystwan.models.policy.list.policer import PolicerList -from catalystwan.models.policy.list.port import PortList -from catalystwan.models.policy.list.preferred_color_group import PreferredColorGroupList -from catalystwan.models.policy.list.prefix import PrefixList -from catalystwan.models.policy.list.protocol_name import ProtocolNameList -from catalystwan.models.policy.list.region import RegionList -from catalystwan.models.policy.list.site import SiteList -from catalystwan.models.policy.list.sla import SLAClassList -from catalystwan.models.policy.list.tloc import TLOCList -from catalystwan.models.policy.list.url import URLAllowList, URLBlockList -from catalystwan.models.policy.list.vpn import VPNList -from catalystwan.models.policy.list.zone import ZoneList +from catalystwan.models.policy.list.app import AppList, AppListInfo +from catalystwan.models.policy.list.app_probe import AppProbeClassList, AppProbeClassListInfo +from catalystwan.models.policy.list.as_path import ASPathList, ASPathListInfo +from catalystwan.models.policy.list.class_map import ClassMapList, ClassMapListInfo +from catalystwan.models.policy.list.color import ColorList, ColorListInfo +from catalystwan.models.policy.list.communities import ( + CommunityList, + CommunityListInfo, + ExpandedCommunityList, + ExpandedCommunityListInfo, +) +from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixList, DataIPv6PrefixListInfo +from catalystwan.models.policy.list.data_prefix import DataPrefixList, DataPrefixListInfo +from catalystwan.models.policy.list.fqdn import FQDNList, FQDNListInfo +from catalystwan.models.policy.list.geo_location import GeoLocationList, GeoLocationListInfo +from catalystwan.models.policy.list.ips_signature import IPSSignatureList, IPSSignatureListInfo +from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixList, IPv6PrefixListInfo +from catalystwan.models.policy.list.local_app import LocalAppList, LocalAppListInfo +from catalystwan.models.policy.list.local_domain import LocalDomainList, LocalDomainListInfo +from catalystwan.models.policy.list.mirror import MirrorList, MirrorListInfo +from catalystwan.models.policy.list.policer import PolicerList, PolicerListInfo +from catalystwan.models.policy.list.port import PortList, PortListInfo +from catalystwan.models.policy.list.preferred_color_group import PreferredColorGroupList, PreferredColorGroupListInfo +from catalystwan.models.policy.list.prefix import PrefixList, PrefixListInfo +from catalystwan.models.policy.list.protocol_name import ProtocolNameList, ProtocolNameListInfo +from catalystwan.models.policy.list.region import RegionList, RegionListInfo +from catalystwan.models.policy.list.site import SiteList, SiteListInfo +from catalystwan.models.policy.list.sla import SLAClassList, SLAClassListInfo +from catalystwan.models.policy.list.tloc import TLOCList, TLOCListInfo +from catalystwan.models.policy.list.url import URLAllowList, URLAllowListInfo, URLBlockList, URLBlockListInfo +from catalystwan.models.policy.list.vpn import VPNList, VPNListInfo +from catalystwan.models.policy.list.zone import ZoneList, ZoneListInfo from .centralized import CentralizedPolicy, TrafficDataDirection -from .definition.access_control_list import AclPolicy -from .definition.access_control_list_ipv6 import AclIPv6Policy -from .definition.control import ControlPolicy -from .definition.device_access import DeviceAccessPolicy -from .definition.device_access_ipv6 import DeviceAccessIPv6Policy -from .definition.hub_and_spoke import HubAndSpokePolicy -from .definition.mesh import MeshPolicy -from .definition.qos_map import QoSDropType, QoSMapPolicy -from .definition.rewrite import RewritePolicy -from .definition.rule_set import RuleSet -from .definition.security_group import SecurityGroup -from .definition.traffic_data import TrafficDataPolicy -from .definition.vpn_membership import VPNMembershipPolicy -from .definition.zone_based_firewall import ZoneBasedFWPolicy +from .definition.access_control_list import AclPolicy, AclPolicyGetResponse +from .definition.access_control_list_ipv6 import AclIPv6Policy, AclIPv6PolicyGetResponse +from .definition.control import ControlPolicy, ControlPolicyGetResponse +from .definition.device_access import DeviceAccessPolicy, DeviceAccessPolicyGetResponse +from .definition.device_access_ipv6 import DeviceAccessIPv6Policy, DeviceAccessIPv6PolicyGetResponse +from .definition.hub_and_spoke import HubAndSpokePolicy, HubAndSpokePolicyGetResponse +from .definition.mesh import MeshPolicy, MeshPolicyGetResponse +from .definition.qos_map import QoSDropType, QoSMapPolicy, QoSMapPolicyGetResponse +from .definition.rewrite import RewritePolicy, RewritePolicyGetResponse +from .definition.rule_set import RuleSet, RuleSetGetResponse +from .definition.security_group import SecurityGroup, SecurityGroupGetResponse +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 ( @@ -119,12 +124,67 @@ Field(discriminator="type"), ] +AnyPolicyListInfo = Annotated[ + Union[ + AppListInfo, + AppProbeClassListInfo, + ASPathListInfo, + ClassMapListInfo, + ColorListInfo, + CommunityListInfo, + DataIPv6PrefixListInfo, + DataPrefixListInfo, + ExpandedCommunityListInfo, + FQDNListInfo, + GeoLocationListInfo, + IPSSignatureListInfo, + IPv6PrefixListInfo, + LocalAppListInfo, + LocalDomainListInfo, + MirrorListInfo, + PolicerListInfo, + PortListInfo, + PreferredColorGroupListInfo, + PrefixListInfo, + ProtocolNameListInfo, + RegionListInfo, + SiteListInfo, + SLAClassListInfo, + TLOCListInfo, + URLBlockListInfo, + URLAllowListInfo, + VPNListInfo, + ZoneListInfo, + ], + Field(discriminator="type"), +] + +AnyPolicyDefinitionInfo = Annotated[ + Union[ + TrafficDataPolicyGetResponse, + RuleSetGetResponse, + SecurityGroupGetResponse, + ZoneBasedFWPolicyGetResponse, + QoSMapPolicyGetResponse, + RewritePolicyGetResponse, + ControlPolicyGetResponse, + VPNMembershipPolicyGetResponse, + HubAndSpokePolicyGetResponse, + MeshPolicyGetResponse, + AclPolicyGetResponse, + AclIPv6PolicyGetResponse, + DeviceAccessPolicyGetResponse, + DeviceAccessIPv6PolicyGetResponse, + ], + Field(discriminator="type"), +] + __all__ = ( "AclIPv6Policy", "AclPolicy", "AnyPolicyList", - "AnyPolicyList", + "AnyPolicyDefinitionInfo", "AppList", "AppProbeClassList", "ASPathList", diff --git a/catalystwan/models/policy/definition/access_control_list.py b/catalystwan/models/policy/definition/access_control_list.py index 1fab42806..121bf6aaf 100644 --- a/catalystwan/models/policy/definition/access_control_list.py +++ b/catalystwan/models/policy/definition/access_control_list.py @@ -26,6 +26,8 @@ PolicerAction, PolicyActionType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, PolicyDefinitionSequenceBase, ProtocolEntry, Reference, @@ -161,3 +163,11 @@ def add_acl_sequence( ) self.add(seq) return seq + + +class AclPolicyEditPayload(AclPolicy, PolicyDefinitionId): + pass + + +class AclPolicyGetResponse(AclPolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/access_control_list_ipv6.py b/catalystwan/models/policy/definition/access_control_list_ipv6.py index 66fcbf47d..29e14f1dc 100644 --- a/catalystwan/models/policy/definition/access_control_list_ipv6.py +++ b/catalystwan/models/policy/definition/access_control_list_ipv6.py @@ -26,6 +26,8 @@ PolicerAction, PolicyActionType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, PolicyDefinitionSequenceBase, Reference, SourceDataIPv6PrefixListEntry, @@ -161,3 +163,11 @@ def add_acl_sequence( ) self.add(seq) return seq + + +class AclIPv6PolicyEditPayload(AclIPv6Policy, PolicyDefinitionId): + pass + + +class AclIPv6PolicyGetResponse(AclIPv6Policy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/control.py b/catalystwan/models/policy/definition/control.py index f132902e1..b2800bb78 100644 --- a/catalystwan/models/policy/definition/control.py +++ b/catalystwan/models/policy/definition/control.py @@ -32,6 +32,8 @@ PathTypeEntry, PolicyActionType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, PolicyDefinitionSequenceBase, PreferenceEntry, PrefixListEntry, @@ -340,3 +342,11 @@ def add_tloc_sequence( ) self.add(seq) return seq + + +class ControlPolicyEditPayload(ControlPolicy, PolicyDefinitionId): + pass + + +class ControlPolicyGetResponse(ControlPolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/device_access.py b/catalystwan/models/policy/definition/device_access.py index 817c0803d..d5ba14565 100644 --- a/catalystwan/models/policy/definition/device_access.py +++ b/catalystwan/models/policy/definition/device_access.py @@ -18,6 +18,8 @@ Match, PolicyActionType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, PolicyDefinitionSequenceBase, SourceDataPrefixListEntry, SourceIPEntry, @@ -104,3 +106,11 @@ def add_acl_sequence( seq.match_device_access_protocol(port=device_access_protocol) self.add(seq) return seq + + +class DeviceAccessPolicyEditPayload(DeviceAccessPolicy, PolicyDefinitionId): + pass + + +class DeviceAccessPolicyGetResponse(DeviceAccessPolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/device_access_ipv6.py b/catalystwan/models/policy/definition/device_access_ipv6.py index 6fe2f75f4..853dd49b3 100644 --- a/catalystwan/models/policy/definition/device_access_ipv6.py +++ b/catalystwan/models/policy/definition/device_access_ipv6.py @@ -18,6 +18,8 @@ Match, PolicyActionType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, PolicyDefinitionSequenceBase, SourceDataIPv6PrefixListEntry, SourceIPv6Entry, @@ -104,3 +106,11 @@ def add_acl_sequence( seq.match_device_access_protocol(port=device_access_protocol) self.add(seq) return seq + + +class DeviceAccessIPv6PolicyEditPayload(DeviceAccessIPv6Policy, PolicyDefinitionId): + pass + + +class DeviceAccessIPv6PolicyGetResponse(DeviceAccessIPv6Policy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/hub_and_spoke.py b/catalystwan/models/policy/definition/hub_and_spoke.py index 058eeaec8..75689c19e 100644 --- a/catalystwan/models/policy/definition/hub_and_spoke.py +++ b/catalystwan/models/policy/definition/hub_and_spoke.py @@ -5,7 +5,11 @@ from pydantic import BaseModel, ConfigDict, Field -from catalystwan.models.policy.policy_definition import PolicyDefinitionBase +from catalystwan.models.policy.policy_definition import ( + PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, +) class Hub(BaseModel): @@ -71,3 +75,11 @@ def add_hub_and_spoke( ) self.definition.sub_definitions.append(sub_definition) return sub_definition + + +class HubAndSpokePolicyEditPayload(HubAndSpokePolicy, PolicyDefinitionId): + pass + + +class HubAndSpokePolicyGetResponse(HubAndSpokePolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/mesh.py b/catalystwan/models/policy/definition/mesh.py index 291b161a0..924493653 100644 --- a/catalystwan/models/policy/definition/mesh.py +++ b/catalystwan/models/policy/definition/mesh.py @@ -5,7 +5,11 @@ from pydantic import BaseModel, ConfigDict, Field -from catalystwan.models.policy.policy_definition import PolicyDefinitionBase +from catalystwan.models.policy.policy_definition import ( + PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, +) class Region(BaseModel): @@ -33,3 +37,11 @@ def add_region(self, name: str, site_lists: List[UUID]) -> Region: region = Region(name=name, site_lists=site_lists) self.definition.regions.append(region) return region + + +class MeshPolicyEditPayload(MeshPolicy, PolicyDefinitionId): + pass + + +class MeshPolicyGetResponse(MeshPolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/qos_map.py b/catalystwan/models/policy/definition/qos_map.py index 2576b62b7..6201ffe89 100644 --- a/catalystwan/models/policy/definition/qos_map.py +++ b/catalystwan/models/policy/definition/qos_map.py @@ -6,7 +6,11 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator from catalystwan.models.common import IntStr -from catalystwan.models.policy.policy_definition import PolicyDefinitionBase +from catalystwan.models.policy.policy_definition import ( + PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, +) QoSScheduling = Literal[ "llq", @@ -97,3 +101,11 @@ def generate_default_control_scheduler(self): # Only when creating (not when value obtained from remote is present) self.definition = QoSMapDefinition(qos_schedulers=[QoSScheduler.get_default_control_scheduler()]) return self + + +class QoSMapPolicyEditPayload(QoSMapPolicy, PolicyDefinitionId): + pass + + +class QoSMapPolicyGetResponse(QoSMapPolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/rewrite.py b/catalystwan/models/policy/definition/rewrite.py index 41087903d..a85b8c9ac 100644 --- a/catalystwan/models/policy/definition/rewrite.py +++ b/catalystwan/models/policy/definition/rewrite.py @@ -9,6 +9,8 @@ DefinitionWithSequencesCommonBase, PLPEntryType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, ) @@ -35,3 +37,11 @@ def add_rule(self, class_map_ref: UUID, dscp: int, l2cos: int, plp: PLPEntryType self.definition.rules.append(RewritePolicyRule(class_=class_map_ref, plp=plp, dscp=str(dscp), l2cos=str(l2cos))) model_config = ConfigDict(populate_by_name=True) + + +class RewritePolicyEditPayload(RewritePolicy, PolicyDefinitionId): + pass + + +class RewritePolicyGetResponse(RewritePolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/rule_set.py b/catalystwan/models/policy/definition/rule_set.py index 2fdd5ff88..eff416321 100644 --- a/catalystwan/models/policy/definition/rule_set.py +++ b/catalystwan/models/policy/definition/rule_set.py @@ -8,7 +8,13 @@ from typing_extensions import Annotated from catalystwan.models.common import check_fields_exclusive -from catalystwan.models.policy.policy_definition import PolicyDefinitionBase, Reference, VariableName +from catalystwan.models.policy.policy_definition import ( + PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, + Reference, + VariableName, +) class RuleBase(BaseModel): @@ -254,3 +260,11 @@ def add_ipv4_rule( protocol_name_list=Reference(ref=protocol_name_list_id) if protocol_name_list_id else None, ) self.add(ipv4_rule) + + +class RuleSetEditPayload(RuleSet, PolicyDefinitionId): + pass + + +class RuleSetGetResponse(RuleSet, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/security_group.py b/catalystwan/models/policy/definition/security_group.py index 68c9214ef..3ecc56d38 100644 --- a/catalystwan/models/policy/definition/security_group.py +++ b/catalystwan/models/policy/definition/security_group.py @@ -6,7 +6,13 @@ from pydantic import BaseModel, ConfigDict, Field, model_validator from catalystwan.models.common import check_any_of_exclusive_field_sets, check_fields_exclusive -from catalystwan.models.policy.policy_definition import PolicyDefinitionBase, Reference, VariableName +from catalystwan.models.policy.policy_definition import ( + PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, + Reference, + VariableName, +) SequenceIPType = Literal[ "ipv4", @@ -67,3 +73,11 @@ def validate_by_sequence_ip_type(self): ): raise ValueError(f"Incompatible definition for {self.sequence_ip_type} sequence") return self + + +class SecurityGroupEditPayload(SecurityGroup, PolicyDefinitionId): + pass + + +class SecurityGroupGetResponse(SecurityGroup, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/traffic_data.py b/catalystwan/models/policy/definition/traffic_data.py index 6215f6329..c13b173e7 100644 --- a/catalystwan/models/policy/definition/traffic_data.py +++ b/catalystwan/models/policy/definition/traffic_data.py @@ -42,6 +42,8 @@ PolicerListEntry, PolicyActionType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, PolicyDefinitionSequenceBase, PrefferedColorGroupListEntry, ProtocolEntry, @@ -375,3 +377,11 @@ def add_ipv4_sequence( ) self.add(seq) return seq + + +class TrafficDataPolicyEditPayload(TrafficDataPolicy, PolicyDefinitionId): + pass + + +class TrafficDataPolicyGetResponse(TrafficDataPolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/vpn_membership.py b/catalystwan/models/policy/definition/vpn_membership.py index 769848dde..1b1aead82 100644 --- a/catalystwan/models/policy/definition/vpn_membership.py +++ b/catalystwan/models/policy/definition/vpn_membership.py @@ -5,7 +5,11 @@ from pydantic import BaseModel, ConfigDict, Field -from catalystwan.models.policy.policy_definition import PolicyDefinitionBase +from catalystwan.models.policy.policy_definition import ( + PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, +) class Site(BaseModel): @@ -28,3 +32,11 @@ def add_site(self, site_list: UUID, vpn_lists: List[UUID]) -> Site: site = Site(site_list=site_list, vpn_list=vpn_lists) self.definition.sites.append(site) return site + + +class VPNMembershipPolicyEditPayload(VPNMembershipPolicy, PolicyDefinitionId): + pass + + +class VPNMembershipPolicyGetResponse(VPNMembershipPolicy, PolicyDefinitionGetResponse): + pass diff --git a/catalystwan/models/policy/definition/zone_based_firewall.py b/catalystwan/models/policy/definition/zone_based_firewall.py index cd2500bf6..feb1b4c16 100644 --- a/catalystwan/models/policy/definition/zone_based_firewall.py +++ b/catalystwan/models/policy/definition/zone_based_firewall.py @@ -25,6 +25,8 @@ Match, PolicyActionType, PolicyDefinitionBase, + PolicyDefinitionGetResponse, + PolicyDefinitionId, PolicyDefinitionSequenceBase, ProtocolEntry, ProtocolNameEntry, @@ -251,3 +253,11 @@ def add_zone_pair(self, source_zone_id: UUID, destination_zone_id: UUID) -> None destination_zone_id=destination_zone_id, ) self.definition.entries.append(entry) + + +class ZoneBasedFWPolicyEditPayload(ZoneBasedFWPolicy, PolicyDefinitionId): + pass + + +class ZoneBasedFWPolicyGetResponse(ZoneBasedFWPolicy, PolicyDefinitionGetResponse): + pass From 935a28d8a29c0b49aadfae837e739d3adf2b525a Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 02:52:44 +0100 Subject: [PATCH 31/36] sort --- catalystwan/models/policy/__init__.py | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 8630c493a..55c274f26 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -71,20 +71,20 @@ AnyPolicyDefinition = Annotated[ Union[ + AclIPv6Policy, + AclPolicy, + ControlPolicy, + DeviceAccessIPv6Policy, + DeviceAccessPolicy, + HubAndSpokePolicy, + MeshPolicy, + QoSMapPolicy, + RewritePolicy, RuleSet, SecurityGroup, - ZoneBasedFWPolicy, TrafficDataPolicy, - QoSMapPolicy, - RewritePolicy, - ControlPolicy, VPNMembershipPolicy, - HubAndSpokePolicy, - MeshPolicy, - AclPolicy, - AclIPv6Policy, - DeviceAccessPolicy, - DeviceAccessIPv6Policy, + ZoneBasedFWPolicy, ], Field(discriminator="type"), ] @@ -151,8 +151,8 @@ SiteListInfo, SLAClassListInfo, TLOCListInfo, - URLBlockListInfo, URLAllowListInfo, + URLBlockListInfo, VPNListInfo, ZoneListInfo, ], @@ -161,20 +161,20 @@ AnyPolicyDefinitionInfo = Annotated[ Union[ - TrafficDataPolicyGetResponse, - RuleSetGetResponse, - SecurityGroupGetResponse, - ZoneBasedFWPolicyGetResponse, - QoSMapPolicyGetResponse, - RewritePolicyGetResponse, + AclIPv6PolicyGetResponse, + AclPolicyGetResponse, ControlPolicyGetResponse, - VPNMembershipPolicyGetResponse, + DeviceAccessIPv6PolicyGetResponse, + DeviceAccessPolicyGetResponse, HubAndSpokePolicyGetResponse, MeshPolicyGetResponse, - AclPolicyGetResponse, - AclIPv6PolicyGetResponse, - DeviceAccessPolicyGetResponse, - DeviceAccessIPv6PolicyGetResponse, + QoSMapPolicyGetResponse, + RewritePolicyGetResponse, + RuleSetGetResponse, + SecurityGroupGetResponse, + TrafficDataPolicyGetResponse, + VPNMembershipPolicyGetResponse, + ZoneBasedFWPolicyGetResponse, ], Field(discriminator="type"), ] From 2e5dd90a4adeb77e61c853195868408bfadbfe84 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 02:56:02 +0100 Subject: [PATCH 32/36] use AnyPolicyDefinitionInfo, AnyPolicyListInfo in UX1Config --- catalystwan/models/configuration/config_migration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catalystwan/models/configuration/config_migration.py b/catalystwan/models/configuration/config_migration.py index 3e8b3e8b9..7e67bdc7a 100644 --- a/catalystwan/models/configuration/config_migration.py +++ b/catalystwan/models/configuration/config_migration.py @@ -12,7 +12,7 @@ from catalystwan.models.configuration.feature_profile.sdwan.policy_object import AnyPolicyObjectParcel from catalystwan.models.configuration.feature_profile.sdwan.system import AnySystemParcel from catalystwan.models.configuration.topology_group import TopologyGroup -from catalystwan.models.policy import AnyPolicyDefinition, AnyPolicyListInfo +from catalystwan.models.policy import AnyPolicyDefinitionInfo, AnyPolicyListInfo from catalystwan.models.policy.centralized import CentralizedPolicyInfo from catalystwan.models.policy.localized import LocalizedPolicyInfo from catalystwan.models.policy.security import AnySecurityPolicyInfo @@ -37,7 +37,7 @@ class UX1Policies(BaseModel): security_policies: List[AnySecurityPolicyInfo] = Field( default=[], serialization_alias="securityPolicies", validation_alias="securityPolicies" ) - policy_definitions: List[AnyPolicyDefinition] = Field( + policy_definitions: List[AnyPolicyDefinitionInfo] = Field( default=[], serialization_alias="policyDefinitions", validation_alias="policyDefinitions" ) policy_lists: List[AnyPolicyListInfo] = Field( From 801f50d3388ca368ee342dc2f22de63502fdf22f Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 10:39:20 +0100 Subject: [PATCH 33/36] fix policy_list converter --- .../converters/policy/policy_lists.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/catalystwan/utils/config_migration/converters/policy/policy_lists.py b/catalystwan/utils/config_migration/converters/policy/policy_lists.py index 0ead146f1..4d6682735 100644 --- a/catalystwan/utils/config_migration/converters/policy/policy_lists.py +++ b/catalystwan/utils/config_migration/converters/policy/policy_lists.py @@ -216,7 +216,8 @@ def sla_class(in_: SLAClassList) -> SLAClassParcel: def tloc(in_: TLOCList) -> TlocParcel: out = TlocParcel(**_get_parcel_name_desc(in_)) for entry in in_.entries: - out.add_entry(tloc=entry.tloc, color=entry.color, encapsulation=entry.encap, preference=entry.preference) + _preference = str(entry.preference) if entry.preference is not None else None + out.add_entry(tloc=entry.tloc, color=entry.color, encapsulation=entry.encap, preference=_preference) return out @@ -281,8 +282,15 @@ class ConvertAllResult(NamedTuple): } +def _find_converter(in_: Input) -> Optional[Callable[[Any], Output]]: + for key in CONVERTERS.keys(): + if isinstance(in_, key): + return CONVERTERS[key] + return None + + def convert(in_: Input) -> Optional[Output]: - if converter := CONVERTERS.get(type(in_)): + if converter := _find_converter(in_): return converter(in_) return None From d9f9803cbb3df7496930a83892e05aba658f18f9 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 11:06:16 +0100 Subject: [PATCH 34/36] include missing file --- catalystwan/models/policy/list/app.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 catalystwan/models/policy/list/app.py diff --git a/catalystwan/models/policy/list/app.py b/catalystwan/models/policy/list/app.py new file mode 100644 index 000000000..9b04cf418 --- /dev/null +++ b/catalystwan/models/policy/list/app.py @@ -0,0 +1,23 @@ +from typing import List, Literal + +from catalystwan.models.policy.lists_entries import AppListEntry +from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo + + +class AppList(PolicyListBase): + type: Literal["app"] = "app" + entries: List[AppListEntry] = [] + + def add_app(self, app: str) -> None: + self._add_entry(AppListEntry(app=app)) + + def add_app_family(self, app_family: str) -> None: + self._add_entry(AppListEntry(app_family=app_family)) + + +class AppListEditPayload(AppList, PolicyListId): + pass + + +class AppListInfo(AppList, PolicyListInfo): + pass From cd1baf90e7ead6fc7d4ee1648b549f6d92cd0927 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 11:13:39 +0100 Subject: [PATCH 35/36] remove unused file --- catalystwan/models/policy/list/expanded_community.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 catalystwan/models/policy/list/expanded_community.py diff --git a/catalystwan/models/policy/list/expanded_community.py b/catalystwan/models/policy/list/expanded_community.py deleted file mode 100644 index 2cb417b59..000000000 --- a/catalystwan/models/policy/list/expanded_community.py +++ /dev/null @@ -1 +0,0 @@ -# Copyright 2022 Cisco Systems, Inc. and its affiliates From 267269b510edfc7b0db4de012cbb3316f3cee63b Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 14 Mar 2024 12:18:15 +0100 Subject: [PATCH 36/36] include entry definitions within owning policy list --- catalystwan/models/policy/__init__.py | 3 - catalystwan/models/policy/list/app.py | 18 +- catalystwan/models/policy/list/app_probe.py | 19 +- catalystwan/models/policy/list/as_path.py | 9 +- catalystwan/models/policy/list/class_map.py | 8 +- catalystwan/models/policy/list/color.py | 7 +- catalystwan/models/policy/list/communities.py | 9 +- .../models/policy/list/data_ipv6_prefix.py | 9 +- catalystwan/models/policy/list/data_prefix.py | 9 +- catalystwan/models/policy/list/fqdn.py | 7 +- .../models/policy/list/geo_location.py | 18 +- .../models/policy/list/ips_signature.py | 10 +- catalystwan/models/policy/list/ipv6_prefix.py | 12 +- catalystwan/models/policy/list/local_app.py | 18 +- .../models/policy/list/local_domain.py | 16 +- catalystwan/models/policy/list/mirror.py | 10 +- catalystwan/models/policy/list/policer.py | 17 +- catalystwan/models/policy/list/port.py | 16 +- .../policy/list/preferred_color_group.py | 45 +- catalystwan/models/policy/list/prefix.py | 12 +- .../models/policy/list/protocol_name.py | 9 +- catalystwan/models/policy/list/region.py | 24 +- catalystwan/models/policy/list/site.py | 9 +- catalystwan/models/policy/list/sla.py | 132 +++++- catalystwan/models/policy/list/tloc.py | 12 +- catalystwan/models/policy/list/url.py | 9 +- catalystwan/models/policy/list/vpn.py | 16 +- catalystwan/models/policy/list/zone.py | 25 +- catalystwan/models/policy/lists_entries.py | 416 ------------------ 29 files changed, 469 insertions(+), 455 deletions(-) delete mode 100644 catalystwan/models/policy/lists_entries.py diff --git a/catalystwan/models/policy/__init__.py b/catalystwan/models/policy/__init__.py index 55c274f26..9ab002d39 100644 --- a/catalystwan/models/policy/__init__.py +++ b/catalystwan/models/policy/__init__.py @@ -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, @@ -212,10 +211,8 @@ "MirrorList", "MultiRegionRole", "OriginProtocol", - "PathPreference", "PathType", "PLPEntryType", - "PolicerExceedAction", "PolicerList", "PolicyActionType", "PortList", diff --git a/catalystwan/models/policy/list/app.py b/catalystwan/models/policy/list/app.py index 9b04cf418..5ded99881 100644 --- a/catalystwan/models/policy/list/app.py +++ b/catalystwan/models/policy/list/app.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/app_probe.py b/catalystwan/models/policy/list/app_probe.py index e40c8f54f..cb788fd61 100644 --- a/catalystwan/models/policy/list/app_probe.py +++ b/catalystwan/models/policy/list/app_probe.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/as_path.py b/catalystwan/models/policy/list/as_path.py index 4aa8c0033..b263b7a24 100644 --- a/catalystwan/models/policy/list/as_path.py +++ b/catalystwan/models/policy/list/as_path.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/class_map.py b/catalystwan/models/policy/list/class_map.py index 4a82dfff4..cf2bd462b 100644 --- a/catalystwan/models/policy/list/class_map.py +++ b/catalystwan/models/policy/list/class_map.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/color.py b/catalystwan/models/policy/list/color.py index 28415f716..358cf8e64 100644 --- a/catalystwan/models/policy/list/color.py +++ b/catalystwan/models/policy/list/color.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/communities.py b/catalystwan/models/policy/list/communities.py index aac5f36da..798916e76 100644 --- a/catalystwan/models/policy/list/communities.py +++ b/catalystwan/models/policy/list/communities.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/data_ipv6_prefix.py b/catalystwan/models/policy/list/data_ipv6_prefix.py index 128c3b183..db326ff41 100644 --- a/catalystwan/models/policy/list/data_ipv6_prefix.py +++ b/catalystwan/models/policy/list/data_ipv6_prefix.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/data_prefix.py b/catalystwan/models/policy/list/data_prefix.py index ce12c0ea1..98ba2fe38 100644 --- a/catalystwan/models/policy/list/data_prefix.py +++ b/catalystwan/models/policy/list/data_prefix.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/fqdn.py b/catalystwan/models/policy/list/fqdn.py index 8162ba6e3..4bcc3e886 100644 --- a/catalystwan/models/policy/list/fqdn.py +++ b/catalystwan/models/policy/list/fqdn.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/geo_location.py b/catalystwan/models/policy/list/geo_location.py index 938845b56..eff5831e4 100644 --- a/catalystwan/models/policy/list/geo_location.py +++ b/catalystwan/models/policy/list/geo_location.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/ips_signature.py b/catalystwan/models/policy/list/ips_signature.py index 7d25d21ee..08dbe3715 100644 --- a/catalystwan/models/policy/list/ips_signature.py +++ b/catalystwan/models/policy/list/ips_signature.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/ipv6_prefix.py b/catalystwan/models/policy/list/ipv6_prefix.py index 5842e4375..8b5c59eec 100644 --- a/catalystwan/models/policy/list/ipv6_prefix.py +++ b/catalystwan/models/policy/list/ipv6_prefix.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/local_app.py b/catalystwan/models/policy/list/local_app.py index 10f13502b..d0fe37ed5 100644 --- a/catalystwan/models/policy/list/local_app.py +++ b/catalystwan/models/policy/list/local_app.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/local_domain.py b/catalystwan/models/policy/list/local_domain.py index 5c35a4d51..9fbe5679e 100644 --- a/catalystwan/models/policy/list/local_domain.py +++ b/catalystwan/models/policy/list/local_domain.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/mirror.py b/catalystwan/models/policy/list/mirror.py index d8a2e8587..03a842507 100644 --- a/catalystwan/models/policy/list/mirror.py +++ b/catalystwan/models/policy/list/mirror.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/policer.py b/catalystwan/models/policy/list/policer.py index e505fd098..502bae191 100644 --- a/catalystwan/models/policy/list/policer.py +++ b/catalystwan/models/policy/list/policer.py @@ -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" diff --git a/catalystwan/models/policy/list/port.py b/catalystwan/models/policy/list/port.py index 5a99c1905..e7759ab4c 100644 --- a/catalystwan/models/policy/list/port.py +++ b/catalystwan/models/policy/list/port.py @@ -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] = [] diff --git a/catalystwan/models/policy/list/preferred_color_group.py b/catalystwan/models/policy/list/preferred_color_group.py index 83581c707..e5fd2ae29 100644 --- a/catalystwan/models/policy/list/preferred_color_group.py +++ b/catalystwan/models/policy/list/preferred_color_group.py @@ -2,10 +2,51 @@ from typing import List, Literal, Optional, Set, Tuple -from catalystwan.models.common import TLOCColor -from catalystwan.models.policy.lists_entries import ColorGroupPreference, PathPreference, PreferredColorGroupListEntry +from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator + +from catalystwan.models.common import TLOCColor, str_as_str_list from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +PathPreference = Literal[ + "direct-path", + "multi-hop-path", + "all-paths", +] + + +class ColorGroupPreference(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + color_preference: Set[TLOCColor] = Field(serialization_alias="colorPreference", validation_alias="colorPreference") + path_preference: PathPreference = Field(serialization_alias="pathPreference", validation_alias="pathPreference") + + _color_pref = field_validator("color_preference", mode="before")(str_as_str_list) + + @staticmethod + def from_color_set_and_path( + color_preference: Set[TLOCColor], path_preference: PathPreference + ) -> "ColorGroupPreference": + return ColorGroupPreference(color_preference=color_preference, path_preference=path_preference) + + +class PreferredColorGroupListEntry(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + primary_preference: ColorGroupPreference = Field( + serialization_alias="primaryPreference", validation_alias="primaryPreference" + ) + secondary_preference: Optional[ColorGroupPreference] = Field( + default=None, serialization_alias="secondaryPreference", validation_alias="secondaryPreference" + ) + tertiary_preference: Optional[ColorGroupPreference] = Field( + default=None, serialization_alias="tertiaryPreference", validation_alias="tertiaryPreference" + ) + + @model_validator(mode="after") + def check_optional_preferences_order(self): + assert not (self.secondary_preference is None and self.tertiary_preference is not None) + return self + class PreferredColorGroupList(PolicyListBase): type: Literal["preferredColorGroup"] = "preferredColorGroup" diff --git a/catalystwan/models/policy/list/prefix.py b/catalystwan/models/policy/list/prefix.py index 663f11466..328231760 100644 --- a/catalystwan/models/policy/list/prefix.py +++ b/catalystwan/models/policy/list/prefix.py @@ -3,10 +3,20 @@ from ipaddress import IPv4Network from typing import List, Literal, Optional -from catalystwan.models.policy.lists_entries import PrefixListEntry +from pydantic import BaseModel, ConfigDict, Field + +from catalystwan.models.common import IntStr from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class PrefixListEntry(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + ip_prefix: IPv4Network = Field(serialization_alias="ipPrefix", validation_alias="ipPrefix") + ge: Optional[IntStr] = Field(default=None, ge=0, le=32) + le: Optional[IntStr] = Field(default=None, ge=0, le=32) + + class PrefixList(PolicyListBase): type: Literal["prefix"] = "prefix" entries: List[PrefixListEntry] = [] diff --git a/catalystwan/models/policy/list/protocol_name.py b/catalystwan/models/policy/list/protocol_name.py index 046ac1519..667c544cd 100644 --- a/catalystwan/models/policy/list/protocol_name.py +++ b/catalystwan/models/policy/list/protocol_name.py @@ -2,10 +2,17 @@ from typing import List, Literal -from catalystwan.models.policy.lists_entries import ProtocolNameListEntry +from pydantic import BaseModel, ConfigDict, Field + from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class ProtocolNameListEntry(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + protocol_name: str = Field(serialization_alias="protocolName", validation_alias="protocolName") + + class ProtocolNameList(PolicyListBase): type: Literal["protocolName"] = "protocolName" entries: List[ProtocolNameListEntry] = [] diff --git a/catalystwan/models/policy/list/region.py b/catalystwan/models/policy/list/region.py index 03848a361..bb6b9d068 100644 --- a/catalystwan/models/policy/list/region.py +++ b/catalystwan/models/policy/list/region.py @@ -2,20 +2,38 @@ from typing import List, Literal, Set, Tuple -from catalystwan.models.policy.lists_entries import RegionListEntry +from pydantic import BaseModel, ConfigDict, Field, field_validator + +from catalystwan.models.common import IntRangeStr from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class RegionListEntry(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + region_id: IntRangeStr = Field( + serialization_alias="regionId", validation_alias="regionId", description="Number in range 0-63" + ) + + @field_validator("region_id") + @classmethod + def check_region_range(cls, region_ids: IntRangeStr): + for i in region_ids: + if i is not None: + assert 0 <= i <= 63 + return region_ids + + class RegionList(PolicyListBase): type: Literal["region"] = "region" entries: List[RegionListEntry] = [] def add_regions(self, regions: Set[int]): for region in regions: - self._add_entry(RegionListEntry(region_id=str(region))) + self._add_entry(RegionListEntry(region_id=(region, None))) def add_region_range(self, region_range: Tuple[int, int]): - entry = RegionListEntry(region_id=f"{region_range[0]}-{region_range[1]}") + entry = RegionListEntry(region_id=region_range) self._add_entry(entry) diff --git a/catalystwan/models/policy/list/site.py b/catalystwan/models/policy/list/site.py index 6cf434c53..346a2e2f8 100644 --- a/catalystwan/models/policy/list/site.py +++ b/catalystwan/models/policy/list/site.py @@ -2,10 +2,17 @@ from typing import List, Literal, Set, Tuple -from catalystwan.models.policy.lists_entries import SiteListEntry +from pydantic import BaseModel, ConfigDict, Field + from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class SiteListEntry(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + site_id: str = Field(serialization_alias="siteId", validation_alias="siteId") + + class SiteList(PolicyListBase): type: Literal["site"] = "site" entries: List[SiteListEntry] = [] diff --git a/catalystwan/models/policy/list/sla.py b/catalystwan/models/policy/list/sla.py index e698cb600..3a79f754a 100644 --- a/catalystwan/models/policy/list/sla.py +++ b/catalystwan/models/policy/list/sla.py @@ -3,10 +3,140 @@ from typing import List, Literal, Optional from uuid import UUID -from catalystwan.models.policy.lists_entries import SLAClassListEntry +from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator + from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +def check_jitter_ms(jitter_str: Optional[str]) -> Optional[str]: + if jitter_str is not None: + assert 1 <= int(jitter_str) <= 1000 + return jitter_str + + +def check_latency_ms(latency_str: Optional[str]) -> Optional[str]: + if latency_str is not None: + assert 1 <= int(latency_str) <= 1000 + return latency_str + + +def check_loss_percent(loss_str: Optional[str]) -> Optional[str]: + if loss_str is not None: + assert 0 <= int(loss_str) <= 100 + return loss_str + + +class FallbackBestTunnel(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + criteria: str + jitter_variance: Optional[str] = Field( + default=None, + serialization_alias="jitterVariance", + validation_alias="jitterVariance", + description="jitter variance in ms", + ) + latency_variance: Optional[str] = Field( + default=None, + serialization_alias="latencyVariance", + validation_alias="latencyVariance", + description="latency variance in ms", + ) + loss_variance: Optional[str] = Field( + default=None, + serialization_alias="lossVariance", + validation_alias="lossVariance", + description="loss variance as percentage", + ) + _criteria_priority: List[Literal["jitter", "latency", "loss"]] = [] + + # validators + _jitter_validator = field_validator("jitter_variance")(check_jitter_ms) + _latency_validator = field_validator("latency_variance")(check_latency_ms) + _loss_validator = field_validator("loss_variance")(check_loss_percent) + + @model_validator(mode="after") + def check_criteria(self): + expected_criteria = set() + if self.jitter_variance is not None: + expected_criteria.add("jitter") + if self.latency_variance is not None: + expected_criteria.add("latency") + if self.loss_variance is not None: + expected_criteria.add("loss") + assert expected_criteria, "At least one variance type needs to be present" + self._criteria_priority = str(self.criteria).split("-") + observed_criteria = set(self._criteria_priority) + assert expected_criteria == observed_criteria + return self + + def _update_criteria_field(self) -> None: + self.criteria = f"{'-'.join(self._criteria_priority)}" + + def add_jitter_criteria(self, jitter_variance: int) -> None: + if self.jitter_variance is None: + self._criteria_priority.append("jitter") + self.jitter_variance = str(jitter_variance) + self._update_criteria_field() + self.check_criteria + + def add_latency_criteria(self, latency_variance: int) -> None: + if self.latency_variance is None: + self._criteria_priority.append("latency") + self.latency_variance = str(latency_variance) + self._update_criteria_field() + self.check_criteria + + def add_loss_criteria(self, loss_variance: int) -> None: + if self.loss_variance is None: + self._criteria_priority.append("loss") + self.loss_variance = str(loss_variance) + self._update_criteria_field() + self.check_criteria + + +class SLAClassListEntry(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + latency: Optional[str] = None + loss: Optional[str] = None + jitter: Optional[str] = None + app_probe_class: Optional[UUID] = Field( + default=None, serialization_alias="appProbeClass", validation_alias="appProbeClass" + ) + fallback_best_tunnel: Optional[FallbackBestTunnel] = Field( + default=None, serialization_alias="fallbackBestTunnel", validation_alias="fallbackBestTunnel" + ) + + # validators + _jitter_validator = field_validator("jitter")(check_jitter_ms) + _latency_validator = field_validator("latency")(check_latency_ms) + _loss_validator = field_validator("loss")(check_loss_percent) + + @model_validator(mode="after") + def check_at_least_one_criteria_is_set(self): + assert any([self.latency, self.loss, self.jitter]) + return self + + def add_fallback_jitter_criteria(self, jitter_variance: int) -> None: + if self.fallback_best_tunnel: + self.fallback_best_tunnel.add_jitter_criteria(jitter_variance) + else: + self.fallback_best_tunnel = FallbackBestTunnel(criteria="jitter", jitter_variance=str(jitter_variance)) + + def add_fallback_latency_criteria(self, latency_variance: int) -> None: + if self.fallback_best_tunnel: + self.fallback_best_tunnel.add_latency_criteria(latency_variance) + else: + self.fallback_best_tunnel = FallbackBestTunnel(criteria="latency", latency_variance=str(latency_variance)) + + def add_fallback_loss_criteria(self, loss_variance: int) -> None: + if self.fallback_best_tunnel: + self.fallback_best_tunnel.add_loss_criteria(loss_variance) + else: + self.fallback_best_tunnel = FallbackBestTunnel(criteria="loss", loss_variance=str(loss_variance)) + + class SLAClassList(PolicyListBase): type: Literal["sla"] = "sla" entries: List[SLAClassListEntry] = [] diff --git a/catalystwan/models/policy/list/tloc.py b/catalystwan/models/policy/list/tloc.py index fd63b001c..7cb13de01 100644 --- a/catalystwan/models/policy/list/tloc.py +++ b/catalystwan/models/policy/list/tloc.py @@ -3,11 +3,19 @@ from ipaddress import IPv4Address from typing import List, Literal, Optional -from catalystwan.models.common import EncapType, TLOCColor -from catalystwan.models.policy.lists_entries import TLOCListEntry +from pydantic import BaseModel, Field + +from catalystwan.models.common import EncapType, IntStr, TLOCColor from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class TLOCListEntry(BaseModel): + tloc: IPv4Address + color: TLOCColor + encap: EncapType + preference: Optional[IntStr] = Field(default=None, ge=0, le=2**32 - 1) + + class TLOCList(PolicyListBase): type: Literal["tloc"] = "tloc" entries: List[TLOCListEntry] = [] diff --git a/catalystwan/models/policy/list/url.py b/catalystwan/models/policy/list/url.py index add5f0a9d..9b4367eeb 100644 --- a/catalystwan/models/policy/list/url.py +++ b/catalystwan/models/policy/list/url.py @@ -2,10 +2,17 @@ from typing import List, Literal -from catalystwan.models.policy.lists_entries import URLListEntry +from pydantic import BaseModel, ConfigDict + from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class URLListEntry(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + pattern: str + + class URLAllowList(PolicyListBase): type: Literal["urlWhiteList"] = "urlWhiteList" entries: List[URLListEntry] = [] diff --git a/catalystwan/models/policy/list/vpn.py b/catalystwan/models/policy/list/vpn.py index 6baaffcd0..0812677dd 100644 --- a/catalystwan/models/policy/list/vpn.py +++ b/catalystwan/models/policy/list/vpn.py @@ -2,10 +2,24 @@ from typing import List, Literal, Set, Tuple -from catalystwan.models.policy.lists_entries import VPNListEntry +from pydantic import BaseModel, Field, field_validator + +from catalystwan.models.common import IntRangeStr from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class VPNListEntry(BaseModel): + vpn: IntRangeStr = Field(description="0-65530 range or single number") + + @field_validator("vpn") + @classmethod + def check_vpn_range(cls, vpn: IntRangeStr): + for i in vpn: + if i is not None: + assert 0 <= i <= 65_530 + return vpn + + class VPNList(PolicyListBase): type: Literal["vpn"] = "vpn" entries: List[VPNListEntry] = [] diff --git a/catalystwan/models/policy/list/zone.py b/catalystwan/models/policy/list/zone.py index 5b8a6f867..c0c1688c4 100644 --- a/catalystwan/models/policy/list/zone.py +++ b/catalystwan/models/policy/list/zone.py @@ -1,12 +1,31 @@ # Copyright 2022 Cisco Systems, Inc. and its affiliates -from typing import List, Literal, Set +from typing import List, Literal, Optional, Set -from catalystwan.models.common import InterfaceType -from catalystwan.models.policy.lists_entries import ZoneListEntry +from pydantic import BaseModel, Field, field_validator, model_validator + +from catalystwan.models.common import InterfaceType, IntRangeStr, check_fields_exclusive from catalystwan.models.policy.policy_list import PolicyListBase, PolicyListId, PolicyListInfo +class ZoneListEntry(BaseModel): + vpn: Optional[IntRangeStr] = Field(default=None, description="0-65530 single number") + interface: Optional[InterfaceType] = None + + @field_validator("vpn") + @classmethod + def check_vpn_range(cls, vpn: IntRangeStr): + for i in vpn: + if i is not None: + assert 0 <= i <= 65_530 + return vpn + + @model_validator(mode="after") + def check_vpn_xor_interface(self): + check_fields_exclusive(self.__dict__, {"vpn", "interface"}, True) + return self + + class ZoneList(PolicyListBase): type: Literal["zone"] = "zone" entries: List[ZoneListEntry] = [] diff --git a/catalystwan/models/policy/lists_entries.py b/catalystwan/models/policy/lists_entries.py deleted file mode 100644 index 0b7295272..000000000 --- a/catalystwan/models/policy/lists_entries.py +++ /dev/null @@ -1,416 +0,0 @@ -# Copyright 2023 Cisco Systems, Inc. and its affiliates - -from ipaddress import IPv4Address, IPv4Network, IPv6Interface -from typing import List, Literal, Optional, Set -from uuid import UUID - -from pydantic import BaseModel, ConfigDict, Field, IPvAnyAddress, field_validator, model_validator - -from catalystwan.models.common import ( - EncapType, - InterfaceType, - IntRangeStr, - IntStr, - TLOCColor, - check_fields_exclusive, - str_as_str_list, -) - - -def check_jitter_ms(jitter_str: Optional[str]) -> Optional[str]: - if jitter_str is not None: - assert 1 <= int(jitter_str) <= 1000 - return jitter_str - - -def check_latency_ms(latency_str: Optional[str]) -> Optional[str]: - if latency_str is not None: - assert 1 <= int(latency_str) <= 1000 - return latency_str - - -def check_loss_percent(loss_str: Optional[str]) -> Optional[str]: - if loss_str is not None: - assert 0 <= int(loss_str) <= 100 - return loss_str - - -PolicerExceedAction = Literal[ - "drop", - "remark", -] - -PathPreference = Literal[ - "direct-path", - "multi-hop-path", - "all-paths", -] - - -class ColorDSCPMap(BaseModel): - color: TLOCColor - dscp: int = Field(ge=0, le=63) - - -class ColorGroupPreference(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - color_preference: Set[TLOCColor] = Field(serialization_alias="colorPreference", validation_alias="colorPreference") - path_preference: PathPreference = Field(serialization_alias="pathPreference", validation_alias="pathPreference") - - _color_pref = field_validator("color_preference", mode="before")(str_as_str_list) - - @staticmethod - def from_color_set_and_path( - color_preference: Set[TLOCColor], path_preference: PathPreference - ) -> "ColorGroupPreference": - return ColorGroupPreference(color_preference=color_preference, path_preference=path_preference) - - -class FallbackBestTunnel(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - criteria: str - jitter_variance: Optional[str] = Field( - default=None, - serialization_alias="jitterVariance", - validation_alias="jitterVariance", - description="jitter variance in ms", - ) - latency_variance: Optional[str] = Field( - default=None, - serialization_alias="latencyVariance", - validation_alias="latencyVariance", - description="latency variance in ms", - ) - loss_variance: Optional[str] = Field( - default=None, - serialization_alias="lossVariance", - validation_alias="lossVariance", - description="loss variance as percentage", - ) - _criteria_priority: List[Literal["jitter", "latency", "loss"]] = [] - - # validators - _jitter_validator = field_validator("jitter_variance")(check_jitter_ms) - _latency_validator = field_validator("latency_variance")(check_latency_ms) - _loss_validator = field_validator("loss_variance")(check_loss_percent) - - @model_validator(mode="after") - def check_criteria(self): - expected_criteria = set() - if self.jitter_variance is not None: - expected_criteria.add("jitter") - if self.latency_variance is not None: - expected_criteria.add("latency") - if self.loss_variance is not None: - expected_criteria.add("loss") - assert expected_criteria, "At least one variance type needs to be present" - self._criteria_priority = str(self.criteria).split("-") - observed_criteria = set(self._criteria_priority) - assert expected_criteria == observed_criteria - return self - - def _update_criteria_field(self) -> None: - self.criteria = f"{'-'.join(self._criteria_priority)}" - - def add_jitter_criteria(self, jitter_variance: int) -> None: - if self.jitter_variance is None: - self._criteria_priority.append("jitter") - self.jitter_variance = str(jitter_variance) - self._update_criteria_field() - self.check_criteria - - def add_latency_criteria(self, latency_variance: int) -> None: - if self.latency_variance is None: - self._criteria_priority.append("latency") - self.latency_variance = str(latency_variance) - self._update_criteria_field() - self.check_criteria - - def add_loss_criteria(self, loss_variance: int) -> None: - if self.loss_variance is None: - self._criteria_priority.append("loss") - self.loss_variance = str(loss_variance) - self._update_criteria_field() - self.check_criteria - - -class DataPrefixListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - ip_prefix: IPv4Network = Field(serialization_alias="ipPrefix", validation_alias="ipPrefix") - - -class SiteListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - site_id: str = Field(serialization_alias="siteId", validation_alias="siteId") - - -class VPNListEntry(BaseModel): - vpn: IntRangeStr = Field(description="0-65530 range or single number") - - @field_validator("vpn") - @classmethod - def check_vpn_range(cls, vpn: IntRangeStr): - for i in vpn: - if i is not None: - assert 0 <= i <= 65_530 - return vpn - - -class ZoneListEntry(BaseModel): - vpn: Optional[IntRangeStr] = Field(default=None, description="0-65530 single number") - interface: Optional[InterfaceType] = None - - @field_validator("vpn") - @classmethod - def check_vpn_range(cls, vpn: IntRangeStr): - for i in vpn: - if i is not None: - assert 0 <= i <= 65_530 - return vpn - - @model_validator(mode="after") - def check_vpn_xor_interface(self): - check_fields_exclusive(self.__dict__, {"vpn", "interface"}, True) - return self - - -class FQDNListEntry(BaseModel): - pattern: str - - -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 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 ProtocolNameListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - protocol_name: str = Field(serialization_alias="protocolName", validation_alias="protocolName") - - -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 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 ColorListEntry(BaseModel): - color: TLOCColor - - -class DataIPv6PrefixListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - ipv6_prefix: IPv6Interface = Field(serialization_alias="ipv6Prefix", validation_alias="ipv6Prefix") - - -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 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 URLListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - pattern: str - - -class CommunityListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - community: str = Field(description="Example: 1000:10000 or internet or local-AS or no advertise or no-export") - - -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 ASPathListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - as_path: str = Field(serialization_alias="asPath", validation_alias="asPath") - - -class ClassMapListEntry(BaseModel): - queue: IntStr = Field(ge=0, le=7) - - -class MirrorListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - remote_dest: IPvAnyAddress = Field(serialization_alias="remoteDest", validation_alias="remoteDest") - source: IPvAnyAddress - - -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 SLAClassListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - latency: Optional[str] = None - loss: Optional[str] = None - jitter: Optional[str] = None - app_probe_class: Optional[UUID] = Field( - default=None, serialization_alias="appProbeClass", validation_alias="appProbeClass" - ) - fallback_best_tunnel: Optional[FallbackBestTunnel] = Field( - default=None, serialization_alias="fallbackBestTunnel", validation_alias="fallbackBestTunnel" - ) - - # validators - _jitter_validator = field_validator("jitter")(check_jitter_ms) - _latency_validator = field_validator("latency")(check_latency_ms) - _loss_validator = field_validator("loss")(check_loss_percent) - - @model_validator(mode="after") - def check_at_least_one_criteria_is_set(self): - assert any([self.latency, self.loss, self.jitter]) - return self - - def add_fallback_jitter_criteria(self, jitter_variance: int) -> None: - if self.fallback_best_tunnel: - self.fallback_best_tunnel.add_jitter_criteria(jitter_variance) - else: - self.fallback_best_tunnel = FallbackBestTunnel(criteria="jitter", jitter_variance=str(jitter_variance)) - - def add_fallback_latency_criteria(self, latency_variance: int) -> None: - if self.fallback_best_tunnel: - self.fallback_best_tunnel.add_latency_criteria(latency_variance) - else: - self.fallback_best_tunnel = FallbackBestTunnel(criteria="latency", latency_variance=str(latency_variance)) - - def add_fallback_loss_criteria(self, loss_variance: int) -> None: - if self.fallback_best_tunnel: - self.fallback_best_tunnel.add_loss_criteria(loss_variance) - else: - self.fallback_best_tunnel = FallbackBestTunnel(criteria="loss", loss_variance=str(loss_variance)) - - -class TLOCListEntry(BaseModel): - tloc: IPv4Address - color: TLOCColor - encap: EncapType - preference: Optional[IntStr] = Field(default=None, ge=0, le=2**32 - 1) - - -class PreferredColorGroupListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - primary_preference: ColorGroupPreference = Field( - serialization_alias="primaryPreference", validation_alias="primaryPreference" - ) - secondary_preference: Optional[ColorGroupPreference] = Field( - default=None, serialization_alias="secondaryPreference", validation_alias="secondaryPreference" - ) - tertiary_preference: Optional[ColorGroupPreference] = Field( - default=None, serialization_alias="tertiaryPreference", validation_alias="tertiaryPreference" - ) - - @model_validator(mode="after") - def check_optional_preferences_order(self): - assert not (self.secondary_preference is None and self.tertiary_preference is not None) - return self - - -class PrefixListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - ip_prefix: IPv4Network = Field(serialization_alias="ipPrefix", validation_alias="ipPrefix") - ge: Optional[IntStr] = Field(default=None, ge=0, le=32) - le: Optional[IntStr] = Field(default=None, ge=0, le=32) - - -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 RegionListEntry(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - region_id: str = Field( - serialization_alias="regionId", validation_alias="regionId", description="Number in range 0-63" - ) - - @field_validator("region_id") - @classmethod - def check_region_id(cls, region_id_str: str): - regions = [int(region_id) for region_id in region_id_str.split("-")] - assert len(regions) <= 2 - for region in regions: - assert 0 <= region <= 63 - if len(regions) == 2: - assert regions[0] <= regions[1] - return region_id_str