Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add banner, add more template types, work on Basic
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrajewski committed Mar 6, 2024
1 parent c1bd2bb commit 663b6a6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from catalystwan.models.configuration.feature_profile.sdwan.system import BannerParcel


class BannerTemplateConverter:
@staticmethod
def create_parcel(name: str, description: str, template_values: dict) -> BannerParcel:
"""
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
return BannerParcel(**template_values)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from catalystwan.api.configuration_groups.parcel import Global
from catalystwan.models.configuration.feature_profile.sdwan.system import BasicParcel
from catalystwan.models.configuration.feature_profile.sdwan.system.basic import ConsoleBaudRate


class SystemToBasicTemplateConverter:
@staticmethod
def create_parcel(name: str, description: str, template_values: dict) -> BasicParcel:
"""
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["parcel_description"] = description
if template_values.get("console_baud_rate") is not None:
value = template_values["console_baud_rate"].value
if value == "":
value = "9600" # Default value for console baud rate
template_values["console_baud_rate"] = Global[ConsoleBaudRate](value=value)

if template_values.get("site_id") is not None:
del template_values["site_id"]
if template_values.get("system_ip") is not None:
del template_values["system_ip"]
if template_values.get("host_name") is not None:
del template_values["host_name"]
if template_values.get("enable") is not None:
del template_values["enable"]
return BasicParcel(**template_values)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from catalystwan.utils.feature_template import find_template_values

from .aaa import AAATemplateConverter
from .banner import BannerTemplateConverter
from .base import FeatureTemplateConverter
from .basic import SystemToBasicTemplateConverter
from .bfd import BFDTemplateConverter
from .global_ import GlobalTemplateConverter
from .logging_ import LoggingTemplateConverter
Expand All @@ -18,13 +20,21 @@

logger = logging.getLogger(__name__)

# TODO: Move tuples inside of template converter classes then assamble them here
supported_parcel_converters: Dict[Any, FeatureTemplateConverter] = {
("cisco_aaa", "cedge_aaa"): AAATemplateConverter, # type: ignore[dict-item]
("cisco_aaa", "cedge_aaa", "aaa"): AAATemplateConverter, # type: ignore[dict-item]
("cisco_bfd",): BFDTemplateConverter, # type: ignore[dict-item]
("cisco_logging", "logging"): LoggingTemplateConverter, # type: ignore[dict-item]
("cisco_security", "security"): SecurityTemplateConverter, # type: ignore[dict-item]
("cisco_omp",): OMPTemplateConverter,
(
"cisco_security",
"security",
"security-vsmart",
"security-vedge",
): SecurityTemplateConverter, # type: ignore[dict-item]
("cisco_omp", "omp-vedge", "omp-vsmart"): OMPTemplateConverter,
("cedge_global",): GlobalTemplateConverter,
("cisco_banner",): BannerTemplateConverter,
("cisco_system", "system-vsmart", "system-vedge"): SystemToBasicTemplateConverter,
}


Expand Down Expand Up @@ -65,7 +75,7 @@ def create_parcel_from_template(template: FeatureTemplateInformation) -> AnySyst
converter = choose_parcel_converter(template.template_type)
template_definition_as_dict = json.loads(cast(str, template.template_definiton))
template_values = find_template_values(template_definition_as_dict)
print(template_values)
template_values_normalized = template_definition_normalization(template_values)
print(template_values_normalized)
logger.debug(f"Normalized template {template.name}: {template_values_normalized}")
return converter.create_parcel(template.name, template.description, template_values_normalized)

0 comments on commit 663b6a6

Please sign in to comment.