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

Commit

Permalink
Merge pull request #515 from CiscoDevNet/dev/device-templates
Browse files Browse the repository at this point in the history
Add get_device_template method, remove dont use device model enum, th…
  • Loading branch information
jkrajew authored Mar 11, 2024
2 parents f46e467 + 150361e commit cdcd531
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions catalystwan/api/template_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
6 changes: 2 additions & 4 deletions catalystwan/api/templates/device_template/device_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")

Expand Down
5 changes: 3 additions & 2 deletions catalystwan/models/configuration/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)

Expand Down
8 changes: 5 additions & 3 deletions catalystwan/workflows/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cdcd531

Please sign in to comment.