From e42af881f93a3505a744e40758deec6702c9ab9b Mon Sep 17 00:00:00 2001 From: sbasan Date: Wed, 27 Mar 2024 11:22:53 +0100 Subject: [PATCH 1/4] fix validation --- catalystwan/api/configuration_groups/parcel.py | 2 +- catalystwan/models/configuration/config_migration.py | 12 ++++++++++-- .../sdwan/policy_object/security/url.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/catalystwan/api/configuration_groups/parcel.py b/catalystwan/api/configuration_groups/parcel.py index ec68994f..c3217ef8 100644 --- a/catalystwan/api/configuration_groups/parcel.py +++ b/catalystwan/api/configuration_groups/parcel.py @@ -116,7 +116,7 @@ class Default(ParcelAttribute, Generic[T]): option_type: OptionType = Field( default=OptionType.DEFAULT, serialization_alias="optionType", validation_alias="optionType" ) - value: Any + value: Optional[Any] = None def as_global(value: Any, generic_alias: Any = None): diff --git a/catalystwan/models/configuration/config_migration.py b/catalystwan/models/configuration/config_migration.py index f238956f..54520bf8 100644 --- a/catalystwan/models/configuration/config_migration.py +++ b/catalystwan/models/configuration/config_migration.py @@ -1,9 +1,9 @@ # Copyright 2024 Cisco Systems, Inc. and its affiliates -from typing import List, Set, Tuple, Union +from typing import Any, Dict, List, Set, Tuple, Union from uuid import UUID -from pydantic import BaseModel, ConfigDict, Field +from pydantic import BaseModel, ConfigDict, Field, model_validator from typing_extensions import Annotated from catalystwan.api.template_api import FeatureTemplateInformation @@ -110,6 +110,14 @@ class UX2Config(BaseModel): default=[], serialization_alias="profileParcels", validation_alias="profileParcels" ) + @model_validator(mode="before") + @classmethod + def insert_parcel_type_from_headers(cls, values: Dict[str, Any]): + profile_parcels = values.get("profileParcels", []) + for profile_parcel in profile_parcels: + profile_parcel["parcel"]["type_"] = profile_parcel["header"]["type"] + return values + class UX2ConfigRollback(BaseModel): config_group_ids: List[UUID] = Field( diff --git a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py index 9b2f96cb..41952d44 100644 --- a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py +++ b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py @@ -14,7 +14,7 @@ class BaseURLListEntry(BaseModel): class URLParcel(_ParcelBase): type_: Literal["security-urllist"] = Field(default="security-urllist", exclude=True) - parcel_type: Literal["urlallowed", "urlblocked"] + type: Literal["urlallowed", "urlblocked"] entries: List[BaseURLListEntry] = Field(default=[], validation_alias=AliasPath("data", "entries")) def add_url(self, pattern: str): From 738a2c6340f5546b410f74d9b9ef45b19c878298 Mon Sep 17 00:00:00 2001 From: sbasan Date: Wed, 27 Mar 2024 11:46:12 +0100 Subject: [PATCH 2/4] fix url allow/block type fields --- .../feature_profile/sdwan/policy_object/security/url.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py index 41952d44..15ab4c65 100644 --- a/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py +++ b/catalystwan/models/configuration/feature_profile/sdwan/policy_object/security/url.py @@ -23,13 +23,9 @@ def add_url(self, pattern: str): class URLAllowParcel(URLParcel): type_: Literal["security-urllist"] = Field(default="security-urllist", exclude=True) - parcel_type: Literal["urlallowed"] = Field( - default="urlallowed", validation_alias="type", serialization_alias="type" - ) + type: Literal["urlallowed"] = "urlallowed" class URLBlockParcel(URLParcel): type_: Literal["security-urllist"] = Field(default="security-urllist", exclude=True) - parcel_type: Literal["urlblocked"] = Field( - default="urlblocked", validation_alias="type", serialization_alias="type" - ) + type: Literal["urlblocked"] = "urlblocked" From f29f3c73a941507988bd9681b6104ae55ab68612 Mon Sep 17 00:00:00 2001 From: Jakub Krajewski Date: Wed, 27 Mar 2024 12:30:40 +0100 Subject: [PATCH 3/4] Temporary solution to keyerror --- .../config_migration/creators/strategy/parcels.py | 4 +++- catalystwan/workflows/config_migration.py | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/catalystwan/utils/config_migration/creators/strategy/parcels.py b/catalystwan/utils/config_migration/creators/strategy/parcels.py index 077f949d..0cb039f1 100644 --- a/catalystwan/utils/config_migration/creators/strategy/parcels.py +++ b/catalystwan/utils/config_migration/creators/strategy/parcels.py @@ -33,5 +33,7 @@ class SimpleParcelPusher(ParcelPusher): def push(self, profile_uuid: UUID, parcel_uuids: List[UUID], mapping: Dict[UUID, TransformedParcel]): # Parcels don't have references to other parcels, so we can create them directly for parcel_uuid in parcel_uuids: - transformed_parcel = mapping[parcel_uuid] + transformed_parcel = mapping.get(parcel_uuid) + if transformed_parcel is None: + continue self.api.create_parcel(profile_uuid, transformed_parcel.parcel) # type: ignore diff --git a/catalystwan/workflows/config_migration.py b/catalystwan/workflows/config_migration.py index c839b6fd..57a7cf8e 100644 --- a/catalystwan/workflows/config_migration.py +++ b/catalystwan/workflows/config_migration.py @@ -34,8 +34,8 @@ "cisco_system", "system-vsmart", "system-vedge", - "cisco_bfd", - "bfd-vedge", + # "cisco_bfd", + # "bfd-vedge", "cedge_global", "cisco_logging", "logging", @@ -64,8 +64,8 @@ "cisco_system", "system-vsmart", "system-vedge", - "cisco_bfd", - "bfd-vedge", + # "cisco_bfd", + # "bfd-vedge", "cedge_global", "cisco_logging", "logging", @@ -74,8 +74,8 @@ "omp-vsmart", "cisco_ntp", "ntp", - "bgp", - "cisco_bgp", + # "bgp", + # "cisco_bgp", "cisco_snmp", ] From ca387a774046e9dc6b66f9d1c651d6ef893f513e Mon Sep 17 00:00:00 2001 From: sbasan Date: Wed, 27 Mar 2024 12:47:51 +0100 Subject: [PATCH 4/4] bump dev version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a64712e2..8dae859d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "catalystwan" -version = "0.31.2dev0" +version = "0.31.2dev1" description = "Cisco Catalyst WAN SDK for Python" authors = ["kagorski "] readme = "README.md"