This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* draft - save work * draft * bump dev version * migrate ConfigGroup to pydantic v2 * bump dev version * Created Factory and adapters for model migration. Modeled templates for UX2 - BFD and AAA * use typing.List * Refactor. Add Logging model * Plural form in features * fix variable --------- Co-authored-by: sbasan <[email protected]> Co-authored-by: Kuba <[email protected]>
- Loading branch information
1 parent
671370a
commit 2239e37
Showing
25 changed files
with
641 additions
and
45 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
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
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
58 changes: 58 additions & 0 deletions
58
catalystwan/models/configuration/feature_profile/converters/feature_template/__init__.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,58 @@ | ||
from typing import Any, Dict, List | ||
|
||
from catalystwan.api.template_api import FeatureTemplateInformation | ||
from catalystwan.models.configuration.feature_profile.sdwan.system import AnySystemParcel | ||
|
||
from .aaa import AAATemplateConverter | ||
from .base import FeatureTemplateConverter | ||
from .bfd import BFDTemplateConverter | ||
from .normalizator import template_definition_normalization | ||
|
||
supported_parcel_converters: Dict[Any, FeatureTemplateConverter] = { | ||
("cisco_aaa", "cedge_aaa"): AAATemplateConverter, # type: ignore[dict-item] | ||
("cisco_bfd",): BFDTemplateConverter, # type: ignore[dict-item] | ||
} | ||
|
||
|
||
def choose_parcel_converter(template_type: str) -> FeatureTemplateConverter: | ||
""" | ||
This function is used to choose the correct parcel factory based on the template type. | ||
Args: | ||
template_type (str): The template type used to determine the correct factory. | ||
Returns: | ||
BaseFactory: The chosen parcel factory. | ||
Raises: | ||
ValueError: If the template type is not supported. | ||
""" | ||
for key in supported_parcel_converters.keys(): | ||
if template_type in key: | ||
return supported_parcel_converters[key] | ||
raise ValueError(f"Template type {template_type} not supported") | ||
|
||
|
||
def create_parcel_from_template(template: FeatureTemplateInformation) -> AnySystemParcel: | ||
""" | ||
Creates a new instance of a _ParcelBase based on the given template. | ||
Args: | ||
template (FeatureTemplateInformation): The template to use for creating the _ParcelBase instance. | ||
Returns: | ||
_ParcelBase: The created _ParcelBase instance. | ||
Raises: | ||
ValueError: If the given template type is not supported. | ||
""" | ||
converter = choose_parcel_converter(template.template_type) | ||
template_values = template_definition_normalization(template.template_definiton) | ||
return converter.create_parcel(template.name, template.description, template_values) | ||
|
||
|
||
__all__ = ["create_parcel_from_template"] | ||
|
||
|
||
def __dir__() -> "List[str]": | ||
return list(__all__) |
30 changes: 30 additions & 0 deletions
30
catalystwan/models/configuration/feature_profile/converters/feature_template/aaa.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,30 @@ | ||
from catalystwan.models.configuration.feature_profile.sdwan.system import AAA | ||
|
||
|
||
class AAATemplateConverter: | ||
@staticmethod | ||
def create_parcel(name: str, description: str, template_values: dict) -> AAA: | ||
""" | ||
Creates an AAA object based on the provided template values. | ||
Returns: | ||
AAA: An AAA object with the provided template values. | ||
""" | ||
template_values["name"] = name | ||
template_values["description"] = description | ||
|
||
delete_properties = ( | ||
"radius_client", | ||
"radius_trustsec_group", | ||
"rda_server_key", | ||
"domain_stripping", | ||
"auth_type", | ||
"port", | ||
"cts_auth_list", | ||
) | ||
|
||
for prop in delete_properties: | ||
if template_values.get(prop) is not None: | ||
del template_values[prop] | ||
|
||
return AAA(**template_values) |
9 changes: 9 additions & 0 deletions
9
catalystwan/models/configuration/feature_profile/converters/feature_template/base.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,9 @@ | ||
from typing_extensions import Protocol | ||
|
||
from catalystwan.models.configuration.feature_profile.sdwan.system import AnySystemParcel | ||
|
||
|
||
class FeatureTemplateConverter(Protocol): | ||
@staticmethod | ||
def create_parcel(name: str, description: str, template_values: dict) -> AnySystemParcel: | ||
... |
20 changes: 20 additions & 0 deletions
20
catalystwan/models/configuration/feature_profile/converters/feature_template/bfd.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,20 @@ | ||
from catalystwan.models.configuration.feature_profile.sdwan.system import BFD | ||
|
||
|
||
class BFDTemplateConverter: | ||
@staticmethod | ||
def create_parcel(name: str, description: str, template_values: dict) -> BFD: | ||
""" | ||
Creates an BFD object based on the provided template values. | ||
Returns: | ||
BFD: An BFD object with the provided template values. | ||
""" | ||
template_values["name"] = name | ||
template_values["description"] = description | ||
|
||
if template_values.get("color") is not None: | ||
template_values["colors"] = template_values["color"] | ||
del template_values["color"] | ||
|
||
return BFD(**template_values) |
27 changes: 27 additions & 0 deletions
27
catalystwan/models/configuration/feature_profile/converters/feature_template/logging.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,27 @@ | ||
# from catalystwan.models.configuration.feature_profile.sdwan.system import Logging | ||
|
||
# class LoggingTemplateConverter: | ||
|
||
# @staticmethod | ||
# def create_parcel(name, description, template_values: dict): | ||
# """ | ||
# Creates an Logging object based on the provided template values. | ||
|
||
# Returns: | ||
# Logging: An Logging object with the provided template values. | ||
# """ | ||
# template_values["name"] = name | ||
# template_values["description"] = description | ||
|
||
# template_values["disk"] = { | ||
# "disk_enable": template_values["enable"], | ||
# "file": { | ||
# "disk_file_size": template_values["size"], | ||
# "disk_file_rotate": template_values["rotate"] | ||
# } | ||
# } | ||
# del template_values["enable"] | ||
# del template_values["size"] | ||
# del template_values["rotate"] | ||
|
||
# return Logging(**template_values) |
Oops, something went wrong.