diff --git a/catalystwan/api/template_api.py b/catalystwan/api/template_api.py index b1b68b89..d8a7dd73 100644 --- a/catalystwan/api/template_api.py +++ b/catalystwan/api/template_api.py @@ -746,3 +746,8 @@ def get_device_templates(self) -> DataSequence[DeviceTemplateInformation]: params = {"feature": "all"} templates = self.session.get(url=endpoint, params=params) return templates.dataseq(DeviceTemplateInformation) + + def get_device_template(self, template_id: str) -> DeviceTemplate: + endpoint = f"/dataservice/template/device/object/{template_id}" + response = self.session.get(endpoint) + return DeviceTemplate(**response.json()) diff --git a/catalystwan/api/templates/device_template/device_template.py b/catalystwan/api/templates/device_template/device_template.py index b286bcfa..85103afc 100644 --- a/catalystwan/api/templates/device_template/device_template.py +++ b/catalystwan/api/templates/device_template/device_template.py @@ -9,8 +9,6 @@ from jinja2 import DebugUndefined, Environment, FileSystemLoader, meta # type: ignore from pydantic import BaseModel, ConfigDict, Field, field_validator -from catalystwan.utils.device_model import DeviceModel - if TYPE_CHECKING: from catalystwan.session import ManagerSession @@ -46,9 +44,9 @@ class DeviceTemplate(BaseModel): template_name: str = Field(alias="templateName") template_description: str = Field(alias="templateDescription") - general_templates: List[GeneralTemplate] = Field(alias="generalTemplates") + general_templates: List[GeneralTemplate] = Field(default=[], alias="generalTemplates") device_role: str = Field(default="sdwan-edge", alias="deviceRole") - device_type: DeviceModel = Field(alias="deviceType") + device_type: str = Field(alias="deviceType") security_policy_id: str = Field(default="", alias="securityPolicyId") policy_id: str = Field(default="", alias="policyId") diff --git a/catalystwan/models/configuration/config_migration.py b/catalystwan/models/configuration/config_migration.py index f68558d9..4a210502 100644 --- a/catalystwan/models/configuration/config_migration.py +++ b/catalystwan/models/configuration/config_migration.py @@ -5,7 +5,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing_extensions import Annotated -from catalystwan.api.template_api import DeviceTemplateInformation, FeatureTemplateInformation +from catalystwan.api.template_api import FeatureTemplateInformation +from catalystwan.api.templates.device_template.device_template import DeviceTemplate from catalystwan.endpoints.configuration_group import ConfigGroup from catalystwan.models.configuration.feature_profile.common import FeatureProfileCreationPayload from catalystwan.models.configuration.feature_profile.sdwan.policy_object import AnyPolicyObjectParcel @@ -51,7 +52,7 @@ class UX1Templates(BaseModel): feature_templates: List[FeatureTemplateInformation] = Field( default=[], serialization_alias="featureTemplates", validation_alias="featureTemplates" ) - device_templates: List[DeviceTemplateInformation] = Field( + device_templates: List[DeviceTemplate] = Field( default=[], serialization_alias="deviceTemplates", validation_alias="deviceTemplates" ) diff --git a/catalystwan/workflows/config_migration.py b/catalystwan/workflows/config_migration.py index 06535fee..90c5ae3c 100644 --- a/catalystwan/workflows/config_migration.py +++ b/catalystwan/workflows/config_migration.py @@ -94,10 +94,12 @@ def collect_ux1_config(session: ManagerSession, progress: Callable[[str, int, in progress("Collecting Templates Info", 0, 2) ux1.templates.feature_templates = [t for t in template_api.get_feature_templates()] - progress("Collecting Templates Info", 1, 2) + progress("Collecting Feature Templates", 1, 2) - ux1.templates.device_templates = [t for t in template_api.get_device_templates()] - progress("Collecting Templates Info", 2, 2) + device_templates_ids = [t.id for t in template_api.get_device_templates()] + for i, dtid in enumerate(device_templates_ids): + ux1.templates.device_templates.append(template_api.get_device_template(dtid)) + progress("Collecting Device Templates", i + 1, len(device_templates_ids)) return ux1