From c3c514c002725b1acb37536e9c9133a33a7d2f67 Mon Sep 17 00:00:00 2001 From: Jakub Krajewski <95274389+jpkrajewski@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:31:56 +0100 Subject: [PATCH] dev: Add models - translation rule, translation profile (#4) * Add models * Add models to init * Change ethernet field serializtion --- .../sdwan/service/lan/ethernet.py | 14 +++------ .../sdwan/uc_voice/__init__.py | 17 ++++++---- .../sdwan/uc_voice/translation_profile.py | 29 +++++++++++++++++ .../sdwan/uc_voice/translation_rule.py | 31 +++++++++++++++++++ 4 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_profile.py create mode 100644 catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_rule.py diff --git a/catalystwan/models/configuration/feature_profile/sdwan/service/lan/ethernet.py b/catalystwan/models/configuration/feature_profile/sdwan/service/lan/ethernet.py index e3f95653..e966237b 100644 --- a/catalystwan/models/configuration/feature_profile/sdwan/service/lan/ethernet.py +++ b/catalystwan/models/configuration/feature_profile/sdwan/service/lan/ethernet.py @@ -138,12 +138,9 @@ def serialize(self, handler: SerializerFunctionWrapHandler, info: SerializationI class Trustsec(BaseModel): model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True, extra="forbid") - enable_sgt_propagation: Annotated[ - Union[Global[bool], Default[bool]], - VersionedField(versions="<=20.13", serialization_alias="enableSGTPropogation"), - ] = Field( + enable_sgt_propagation: Union[Global[bool], Default[bool]] = Field( serialization_alias="enableSGTPropagation", - validation_alias=AliasChoices("enableSGTPropagation", "enableSGTPropogation"), + validation_alias="enableSGTPropogation", default=Default[bool](value=False), ) propagate: Annotated[ @@ -152,13 +149,10 @@ class Trustsec(BaseModel): security_group_tag: Optional[Union[Global[int], Variable, Default[None]]] = Field( serialization_alias="securityGroupTag", validation_alias="securityGroupTag", default=None ) - enable_enforced_propagation: Annotated[ - Union[Global[bool], Default[None]], - VersionedField(versions="<=20.13", serialization_alias="enableEnforcedPropogation"), - ] = Field( + enable_enforced_propagation: Union[Global[bool], Default[None]] = Field( default=Default[None](value=None), serialization_alias="enableEnforcedPropagation", - validation_alias=AliasChoices("enableEnforcedPropagation", "enableEnforcedPropogation"), + validation_alias="enableEnforcedPropogation", ) enforced_security_group_tag: Union[Global[int], Variable, Default[None]] = Field( default=Default[None](value=None), diff --git a/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/__init__.py b/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/__init__.py index d85d9533..82d04f45 100644 --- a/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/__init__.py +++ b/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/__init__.py @@ -6,20 +6,25 @@ from typing_extensions import Annotated from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.media_profile import MediaProfileParcel +from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.translation_profile import TranslationProfileParcel +from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.translation_rule import TranslationRuleParcel from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.trunk_group import TrunkGroupParcel from .dsp_farm import DspFarmParcel AnyUcVoiceParcel = Annotated[ - Union[ - DspFarmParcel, - MediaProfileParcel, - TrunkGroupParcel, - ], + Union[DspFarmParcel, MediaProfileParcel, TrunkGroupParcel, TranslationRuleParcel, TranslationProfileParcel], Field(discriminator="type_"), ] -__all__ = ("AnyUcVoiceParcel", "DspFarmParcel", "MediaProfileParcel", "TrunkGroupParcel") +__all__ = ( + "AnyUcVoiceParcel", + "DspFarmParcel", + "MediaProfileParcel", + "TrunkGroupParcel", + "TranslationProfileParcel", + "TranslationRuleParcel", +) def __dir__() -> "List[str]": diff --git a/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_profile.py b/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_profile.py new file mode 100644 index 00000000..b0b52b1c --- /dev/null +++ b/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_profile.py @@ -0,0 +1,29 @@ +# Copyright 2024 Cisco Systems, Inc. and its affiliates +from typing import List, Literal, Optional, Union + +from pydantic import AliasPath, BaseModel, ConfigDict, Field + +from catalystwan.api.configuration_groups.parcel import Global, Variable, _ParcelBase +from catalystwan.models.configuration.feature_profile.common import RefIdItem + +CallType = Literal[ + "called", + "calling", +] + + +class TranslationProfileSettings(BaseModel): + model_config = ConfigDict(populate_by_name=True, extra="forbid") + call_type: Union[Variable, Global[CallType]] = Field(validation_alias="callType", serialization_alias="callType") + translation_rule: Optional[RefIdItem] = Field( + default=None, validation_alias="translationRule", serialization_alias="translationRule" + ) + + +class TranslationProfileParcel(_ParcelBase): + model_config = ConfigDict(populate_by_name=True, extra="forbid") + type_: Literal["translation-profile"] = Field(default="translation-profile", exclude=True) + translation_profile_settings: List[TranslationProfileSettings] = Field( + validation_alias=AliasPath("data", "translationProfileSettings"), + description="Translation Profile configuration", + ) diff --git a/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_rule.py b/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_rule.py new file mode 100644 index 00000000..24faebe0 --- /dev/null +++ b/catalystwan/models/configuration/feature_profile/sdwan/uc_voice/translation_rule.py @@ -0,0 +1,31 @@ +# Copyright 2024 Cisco Systems, Inc. and its affiliates +from typing import List, Literal, Optional + +from pydantic import AliasPath, BaseModel, ConfigDict, Field + +from catalystwan.api.configuration_groups.parcel import Global, _ParcelBase + +Action = Literal[ + "reject", + "replace", +] + + +class RuleSettings(BaseModel): + model_config = ConfigDict(populate_by_name=True, extra="forbid") + action: Optional[Global[Action]] = Field(default=None) + match: Optional[Global[str]] = Field(default=None) + replacement_pattern: Optional[Global[str]] = Field( + default=None, validation_alias="replacementPattern", serialization_alias="replacementPattern" + ) + rule_num: Optional[Global[int]] = Field(default=None, validation_alias="ruleNum", serialization_alias="ruleNum") + + +class TranslationRuleParcel(_ParcelBase): + model_config = ConfigDict(populate_by_name=True, extra="forbid") + type_: Literal["translation-rule"] = Field(default="translation-rule", exclude=True) + rule_settings: List[RuleSettings] = Field( + validation_alias=AliasPath("data", "ruleSettings"), + description="Translation Rule configuration", + ) + rule_name: Optional[Global[int]] = Field(default=None, validation_alias="ruleName", serialization_alias="ruleName")