This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from CiscoDevNet/dev/other/ucse
Add UCSE model, converter and integration test
- Loading branch information
Showing
6 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
catalystwan/models/configuration/feature_profile/sdwan/other/ucse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from __future__ import annotations | ||
|
||
from ipaddress import IPv4Address | ||
from typing import List, Literal, Optional, Union | ||
|
||
from pydantic import AliasPath, BaseModel, ConfigDict, Field | ||
|
||
from catalystwan.api.configuration_groups.parcel import Default, Global, Variable, _ParcelBase, as_default, as_variable | ||
|
||
FailOverType = Literal["ge2", "te2"] | ||
LomType = Literal["ge1", "ge2", "ge3", "te2", "te3", "console", "failover"] | ||
|
||
|
||
class SharedLom(BaseModel): | ||
model_config = ConfigDict( | ||
extra="forbid", | ||
populate_by_name=True, | ||
) | ||
lom_type: Global[LomType] = Field(..., serialization_alias="lomType", validation_alias="lomType") | ||
fail_over_type: Optional[Global[FailOverType]] = Field( | ||
default=None, serialization_alias="failOverType", validation_alias="failOverType" | ||
) | ||
|
||
|
||
class AccessPort(BaseModel): | ||
model_config = ConfigDict( | ||
populate_by_name=True, | ||
) | ||
dedicated: Union[Global[bool], Default[bool]] = Field(default=as_default(True), description="Dedicated") | ||
shared_lom: SharedLom = Field(..., serialization_alias="sharedLom", validation_alias="sharedLom") | ||
|
||
|
||
class Ip(BaseModel): | ||
model_config = ConfigDict( | ||
extra="forbid", | ||
populate_by_name=True, | ||
) | ||
address: Union[Global[str], Variable] = Field( | ||
default=as_variable("{{ipv4Addr}}"), description="Assign IPv4 address" | ||
) | ||
default_gateway: Union[Global[IPv4Address], Variable, Default[None]] = Field( | ||
default=Default[None](value=None), | ||
serialization_alias="defaultGateway", | ||
validation_alias="defaultGateway", | ||
description="Assign default gateway", | ||
) | ||
|
||
|
||
class Vlan(BaseModel): | ||
model_config = ConfigDict( | ||
populate_by_name=True, | ||
) | ||
vlan_id: Union[Global[int], Variable, Default[None]] = Field( | ||
default=Default[None](value=None), | ||
serialization_alias="vlanId", | ||
validation_alias="vlanId", | ||
description="Assign Vlan Id", | ||
) | ||
priority: Union[Global[int], Variable, Default[None]] = Field( | ||
default=Default[None](value=None), description="Assign priority" | ||
) | ||
|
||
|
||
class Imc(BaseModel): | ||
model_config = ConfigDict( | ||
populate_by_name=True, | ||
) | ||
access_port: AccessPort = Field(..., serialization_alias="access-port", validation_alias="access-port") | ||
ip: Ip = Field(default_factory=Ip) | ||
vlan: Optional[Vlan] = None | ||
|
||
|
||
class InterfaceItem(BaseModel): | ||
model_config = ConfigDict( | ||
extra="forbid", | ||
populate_by_name=True, | ||
) | ||
if_name: Union[Global[str], Variable, Default[None]] = Field( | ||
default=Default[None](value=None), | ||
serialization_alias="ifName", | ||
validation_alias="ifName", | ||
description="Set Inteface name", | ||
) | ||
l3: Default[bool] = Field(default=as_default(True), description="L3") | ||
ucse_interface_vpn: Optional[Union[Global[int], Variable, Default[None]]] = Field( | ||
default=Default[None](value=None), | ||
serialization_alias="ucseInterfaceVpn", | ||
validation_alias="ucseInterfaceVpn", | ||
description="UCSE Interface VPN", | ||
) | ||
address: Optional[Union[Global[str], Variable]] = Field(default=None, description="Assign IPv4 address") | ||
|
||
|
||
class UcseParcel(_ParcelBase): | ||
type_: Literal["ucse"] = Field(default="ucse", exclude=True) | ||
model_config = ConfigDict( | ||
extra="forbid", | ||
populate_by_name=True, | ||
) | ||
bay: Global[int] = Field(..., validation_alias=AliasPath("data", "bay"), description="Bay") | ||
slot: Global[int] = Field(..., validation_alias=AliasPath("data", "slot"), description="Slot") | ||
imc: Optional[Imc] = Field(default=None, validation_alias=AliasPath("data", "imc"), description="IMC") | ||
interface: Optional[List[InterfaceItem]] = Field( | ||
default=None, | ||
validation_alias=AliasPath("data", "interface"), | ||
description="Interface name: GigabitEthernet0/<>/<> when present", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
catalystwan/utils/config_migration/converters/feature_template/ucse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from copy import deepcopy | ||
|
||
from catalystwan.api.configuration_groups.parcel import Global | ||
from catalystwan.models.configuration.feature_profile.sdwan.other import UcseParcel | ||
from catalystwan.models.configuration.feature_profile.sdwan.other.ucse import LomType | ||
|
||
|
||
class UcseTemplateConverter: | ||
""" | ||
A class for converting template values into a UcseParcel object. | ||
""" | ||
|
||
supported_template_types = ("ucse",) | ||
|
||
@staticmethod | ||
def create_parcel(name: str, description: str, template_values: dict) -> UcseParcel: | ||
""" | ||
Creates a UcseParcel object based on the provided template values. | ||
Args: | ||
name (str): The name of the parcel. | ||
description (str): The description of the parcel. | ||
template_values (dict): A dictionary containing the template values. | ||
Returns: | ||
UcseParcel: A UcseParcel object with the provided values. | ||
""" | ||
parcel_values = deepcopy(template_values) | ||
|
||
for interface_values in parcel_values.get("interface", []): | ||
ip = interface_values.pop("ip", None) | ||
if ip: | ||
interface_values["address"] = ip.get("static_case", {}).get("address") | ||
|
||
imc = parcel_values.get("imc", {}) | ||
static_case = imc.get("ip", {}).get("static_case") | ||
if static_case: | ||
imc["ip"] = static_case | ||
|
||
access_port = imc.get("access_port", {}) | ||
shared_lom = access_port.get("shared_lom") | ||
if shared_lom: | ||
lom_type = list(shared_lom.keys())[0] | ||
shared_lom.clear() | ||
access_port["shared_lom"]["lom_type"] = Global[LomType](value=lom_type) | ||
|
||
for key in ["module_type", "subslot_name"]: | ||
parcel_values.pop(key, None) | ||
|
||
parcel_values.update({"parcel_name": name, "parcel_description": description}) | ||
return UcseParcel(**parcel_values) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
"bgp", | ||
"cisco_bgp", | ||
"cisco_thousandeyes", | ||
"ucse", | ||
] | ||
|
||
|
||
|