From 89bce4667bf551b76c409dedecc97be1a33b45b6 Mon Sep 17 00:00:00 2001 From: Jakub Krajewski Date: Thu, 28 Mar 2024 10:13:06 +0100 Subject: [PATCH] Move TemplateInformation models to separate file in models folder --- catalystwan/api/template_api.py | 42 +----------------- .../models/configuration/config_migration.py | 2 +- catalystwan/models/templates.py | 43 +++++++++++++++++++ 3 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 catalystwan/models/templates.py diff --git a/catalystwan/api/template_api.py b/catalystwan/api/template_api.py index 4904099e..692e0cf5 100644 --- a/catalystwan/api/template_api.py +++ b/catalystwan/api/template_api.py @@ -2,14 +2,12 @@ from __future__ import annotations -import datetime as dt import json import logging from enum import Enum -from typing import TYPE_CHECKING, Any, List, Optional, Type, overload +from typing import TYPE_CHECKING, Any, Optional, Type, overload from ciscoconfparse import CiscoConfParse # type: ignore -from pydantic import BaseModel, ConfigDict, Field from catalystwan.api.task_status_api import Task from catalystwan.api.templates.cli_template import CLITemplate @@ -42,6 +40,7 @@ from catalystwan.dataclasses import Device, DeviceTemplateInfo, FeatureTemplateInfo, FeatureTemplatesTypes, TemplateInfo from catalystwan.endpoints.configuration_device_template import FeatureToCLIPayload from catalystwan.exceptions import AttachedError, TemplateNotFoundError +from catalystwan.models.templates import DeviceTemplateInformation, FeatureTemplateInformation from catalystwan.response import ManagerResponse from catalystwan.typed_list import DataSequence from catalystwan.utils.device_model import DeviceModel @@ -71,43 +70,6 @@ class DeviceTemplateFeature(Enum): ALL = "all" -class TemplateInformation(BaseModel): - model_config = ConfigDict(populate_by_name=True) - - last_updated_by: str = Field(serialization_alias="lastUpdatedBy", validation_alias="lastUpdatedBy") - id: str = Field(serialization_alias="templateId", validation_alias="templateId") - factory_default: bool = Field(serialization_alias="factoryDefault", validation_alias="factoryDefault") - name: str = Field(serialization_alias="templateName", validation_alias="templateName") - devices_attached: int = Field(serialization_alias="devicesAttached", validation_alias="devicesAttached") - description: str = Field(serialization_alias="templateDescription", validation_alias="templateDescription") - last_updated_on: dt.datetime = Field(serialization_alias="lastUpdatedOn", validation_alias="lastUpdatedOn") - resource_group: Optional[str] = Field( - default=None, serialization_alias="resourceGroup", validation_alias="resourceGroup" - ) - - -class FeatureTemplateInformation(TemplateInformation): - model_config = ConfigDict(populate_by_name=True) - - template_type: str = Field(serialization_alias="templateType", validation_alias="templateType") - device_type: List[str] = Field(serialization_alias="deviceType", validation_alias="deviceType") - version: str = Field(serialization_alias="templateMinVersion", validation_alias="templateMinVersion") - template_definiton: Optional[str] = Field( - default=None, serialization_alias="templateDefinition", validation_alias="templateDefinition" - ) - - -class DeviceTemplateInformation(TemplateInformation): - model_config = ConfigDict(populate_by_name=True) - - device_type: str = Field(serialization_alias="deviceType", validation_alias="deviceType") - template_class: str = Field(serialization_alias="templateClass", validation_alias="templateClass") - config_type: str = Field(serialization_alias="configType", validation_alias="configType") - template_attached: int = Field(serialization_alias="templateAttached", validation_alias="templateAttached") - draft_mode: Optional[str] = Field(default=None, serialization_alias="draftMode", validation_alias="draftMode") - device_role: Optional[str] = Field(default=None, serialization_alias="deviceRole", validation_alias="deviceRole") - - class TemplatesAPI: def __init__(self, session: ManagerSession) -> None: self.session = session diff --git a/catalystwan/models/configuration/config_migration.py b/catalystwan/models/configuration/config_migration.py index 0ea343c0..8c439645 100644 --- a/catalystwan/models/configuration/config_migration.py +++ b/catalystwan/models/configuration/config_migration.py @@ -6,7 +6,6 @@ from pydantic import BaseModel, ConfigDict, Field, model_validator from typing_extensions import Annotated -from catalystwan.api.template_api import FeatureTemplateInformation, TemplateInformation from catalystwan.api.templates.device_template.device_template import DeviceTemplate from catalystwan.endpoints.configuration_group import ConfigGroupCreationPayload from catalystwan.models.configuration.feature_profile.common import FeatureProfileCreationPayload, ProfileType @@ -20,6 +19,7 @@ from catalystwan.models.policy.centralized import CentralizedPolicyInfo from catalystwan.models.policy.localized import LocalizedPolicyInfo from catalystwan.models.policy.security import AnySecurityPolicyInfo +from catalystwan.models.templates import FeatureTemplateInformation, TemplateInformation AnyParcel = Annotated[ Union[AnySystemParcel, AnyPolicyObjectParcel, AnyServiceParcel, AnyOtherParcel, AnyTransportParcel], diff --git a/catalystwan/models/templates.py b/catalystwan/models/templates.py new file mode 100644 index 00000000..248099cd --- /dev/null +++ b/catalystwan/models/templates.py @@ -0,0 +1,43 @@ +# Copyright 2022 Cisco Systems, Inc. and its affiliates + +import datetime as dt +from typing import List, Optional + +from pydantic import BaseModel, ConfigDict, Field + + +class TemplateInformation(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + last_updated_by: str = Field(serialization_alias="lastUpdatedBy", validation_alias="lastUpdatedBy") + id: str = Field(serialization_alias="templateId", validation_alias="templateId") + factory_default: bool = Field(serialization_alias="factoryDefault", validation_alias="factoryDefault") + name: str = Field(serialization_alias="templateName", validation_alias="templateName") + devices_attached: int = Field(serialization_alias="devicesAttached", validation_alias="devicesAttached") + description: str = Field(serialization_alias="templateDescription", validation_alias="templateDescription") + last_updated_on: dt.datetime = Field(serialization_alias="lastUpdatedOn", validation_alias="lastUpdatedOn") + resource_group: Optional[str] = Field( + default=None, serialization_alias="resourceGroup", validation_alias="resourceGroup" + ) + + +class FeatureTemplateInformation(TemplateInformation): + model_config = ConfigDict(populate_by_name=True) + + template_type: str = Field(serialization_alias="templateType", validation_alias="templateType") + device_type: List[str] = Field(serialization_alias="deviceType", validation_alias="deviceType") + version: str = Field(serialization_alias="templateMinVersion", validation_alias="templateMinVersion") + template_definiton: Optional[str] = Field( + default=None, serialization_alias="templateDefinition", validation_alias="templateDefinition" + ) + + +class DeviceTemplateInformation(TemplateInformation): + model_config = ConfigDict(populate_by_name=True) + + device_type: str = Field(serialization_alias="deviceType", validation_alias="deviceType") + template_class: str = Field(serialization_alias="templateClass", validation_alias="templateClass") + config_type: str = Field(serialization_alias="configType", validation_alias="configType") + template_attached: int = Field(serialization_alias="templateAttached", validation_alias="templateAttached") + draft_mode: Optional[str] = Field(default=None, serialization_alias="draftMode", validation_alias="draftMode") + device_role: Optional[str] = Field(default=None, serialization_alias="deviceRole", validation_alias="deviceRole")