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

Move TemplateInformation models to separate file in models folder #540

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Move TemplateInformation models to separate file in models folder
  • Loading branch information
jpkrajewski committed Mar 28, 2024
commit 89bce4667bf551b76c409dedecc97be1a33b45b6
42 changes: 2 additions & 40 deletions catalystwan/api/template_api.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion catalystwan/models/configuration/config_migration.py
Original file line number Diff line number Diff line change
@@ -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],
43 changes: 43 additions & 0 deletions catalystwan/models/templates.py
Original file line number Diff line number Diff line change
@@ -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")