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

Commit

Permalink
Add device template model with id and devices attached
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrajewski committed Mar 27, 2024
1 parent 83f1b5a commit 0cd390f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions catalystwan/api/template_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from catalystwan.api.templates.device_template.device_template import (
DeviceSpecificValue,
DeviceTemplate,
DeviceTemplateWithTracking,
GeneralTemplate,
)
from catalystwan.api.templates.feature_template import FeatureTemplate
Expand Down Expand Up @@ -747,7 +748,7 @@ def get_device_templates(self) -> DataSequence[DeviceTemplateInformation]:
templates = self.session.get(url=endpoint, params=params)
return templates.dataseq(DeviceTemplateInformation)

def get_device_template(self, template_id: str) -> DeviceTemplate:
def get_device_template(self, template_id: str) -> DeviceTemplateWithTracking:
endpoint = f"/dataservice/template/device/object/{template_id}"
response = self.session.get(endpoint)
return DeviceTemplate(**response.json())
return DeviceTemplateWithTracking(**response.json())
5 changes: 5 additions & 0 deletions catalystwan/api/templates/device_template/device_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,10 @@ def get(self, name: str, session: ManagerSession) -> DeviceTemplate:
model_config = ConfigDict(populate_by_name=True, use_enum_values=True)


class DeviceTemplateWithTracking(DeviceTemplate):
id: str = Field(default="", alias="templateId")
devices_attached: int = Field(default=0, alias="devicesAttached")


class DeviceSpecificValue(BaseModel):
property: str
4 changes: 2 additions & 2 deletions catalystwan/models/configuration/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing_extensions import Annotated

from catalystwan.api.template_api import FeatureTemplateInformation
from catalystwan.api.templates.device_template.device_template import DeviceTemplate
from catalystwan.api.templates.device_template.device_template import DeviceTemplateWithTracking
from catalystwan.endpoints.configuration_group import ConfigGroupCreationPayload
from catalystwan.models.configuration.feature_profile.common import FeatureProfileCreationPayload, ProfileType
from catalystwan.models.configuration.feature_profile.sdwan.other import AnyOtherParcel
Expand Down Expand Up @@ -50,7 +50,7 @@ class UX1Templates(BaseModel):
feature_templates: List[FeatureTemplateInformation] = Field(
default=[], serialization_alias="featureTemplates", validation_alias="featureTemplates"
)
device_templates: List[DeviceTemplate] = Field(
device_templates: List[DeviceTemplateWithTracking] = Field(
default=[], serialization_alias="deviceTemplates", validation_alias="deviceTemplates"
)

Expand Down
11 changes: 7 additions & 4 deletions catalystwan/workflows/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,13 @@ def collect_ux1_config(session: ManagerSession, progress: Callable[[str, int, in
ux1.templates.feature_templates = [t for t in template_api.get_feature_templates()]
progress("Collecting Feature Templates", 1, 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))
device_templates_information = template_api.get_device_templates()
for i, device_template_information in enumerate(device_templates_information):
device_template = template_api.get_device_template(device_template_information.id)
device_template.id = device_template_information.id
device_template.devices_attached = device_template_information.devices_attached
ux1.templates.device_templates.append(device_template)
progress("Collecting Device Templates", i + 1, len(device_templates_information))

return ux1

Expand Down

0 comments on commit 0cd390f

Please sign in to comment.