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

Commit

Permalink
Main rebase to ux migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrajewski committed Mar 7, 2024
1 parent 5e6238a commit 9fee3e6
Show file tree
Hide file tree
Showing 87 changed files with 4,128 additions and 774 deletions.
3 changes: 2 additions & 1 deletion catalystwan/api/api_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from catalystwan.api.config_device_inventory_api import ConfigurationDeviceInventoryAPI
from catalystwan.api.config_group_api import ConfigGroupAPI
from catalystwan.api.dashboard_api import DashboardAPI
from catalystwan.api.feature_profile_api import SDRoutingFeatureProfilesAPI
from catalystwan.api.feature_profile_api import SDRoutingFeatureProfilesAPI, SDWANFeatureProfilesAPI
from catalystwan.api.logs_api import LogsAPI
from catalystwan.api.omp_api import OmpAPI
from catalystwan.api.packet_capture_api import PacketCaptureAPI
Expand Down Expand Up @@ -66,3 +66,4 @@ def __init__(self, session: ManagerSession):
self.sessions = SessionsAPI(session)
self.policy = PolicyAPI(session)
self.sd_routing_feature_profiles = SDRoutingFeatureProfilesAPI(session)
self.sdwan_feature_profiles = SDWANFeatureProfilesAPI(session)
16 changes: 11 additions & 5 deletions catalystwan/api/config_group_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional, Union
from uuid import UUID

from catalystwan.typed_list import DataSequence

if TYPE_CHECKING:
from catalystwan.session import ManagerSession

from catalystwan.endpoints.configuration_group import (
ConfigGroup,
ConfigGroupAssociatePayload,
ConfigGroupCreationPayload,
ConfigGroupCreationResponse,
Expand All @@ -16,7 +20,6 @@
ConfigGroupDisassociateResponse,
ConfigGroupEditPayload,
ConfigGroupEditResponse,
ConfigGroupResponsePayload,
ConfigGroupVariablesCreatePayload,
ConfigGroupVariablesCreateResponse,
ConfigGroupVariablesEditPayload,
Expand Down Expand Up @@ -110,11 +113,14 @@ def edit(

return self.endpoint.edit_config_group(config_group_id=cg_id, payload=payload)

def get(self) -> ConfigGroupResponsePayload:
def get(self, group_id: Optional[UUID] = None) -> Union[DataSequence[ConfigGroup], ConfigGroup, None]:
"""
Gets list of existing config-groups
Gets list of existing config-groups or single config-group with given ID
If given ID is not correct return None
"""
return self.endpoint.get()
if group_id is None:
return self.endpoint.get()
return self.endpoint.get().filter(id=group_id).single_or_default()

def update_variables(self, cg_id: str, solution: Solution, device_variables: list) -> None:
"""
Expand Down
36 changes: 31 additions & 5 deletions catalystwan/api/configuration_groups/parcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@
from enum import Enum
from typing import Any, Dict, Generic, Literal, Optional, TypeVar, get_origin

from pydantic import AliasPath, BaseModel, ConfigDict, Field, PrivateAttr, model_serializer
from pydantic import (
AliasPath,
BaseModel,
ConfigDict,
Field,
PrivateAttr,
SerializerFunctionWrapHandler,
model_serializer,
)

from catalystwan.exceptions import CatalystwanException

T = TypeVar("T")


class _ParcelBase(BaseModel):
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, populate_by_name=True)
model_config = ConfigDict(
extra="allow", arbitrary_types_allowed=True, populate_by_name=True, json_schema_mode_override="validation"
)
parcel_name: str = Field(
min_length=1,
max_length=128,
Expand All @@ -23,11 +35,18 @@ class _ParcelBase(BaseModel):
validation_alias="description",
description="Set the parcel description",
)
data: Optional[Any] = None
_parcel_data_key: str = PrivateAttr(default="data")

@model_serializer(mode="wrap")
def envelope_parcel_data(self, handler) -> Dict[str, Any]:
def envelope_parcel_data(self, handler: SerializerFunctionWrapHandler) -> Dict[str, Any]:
"""
serializes model fields with respect to field validation_alias,
sub-classing parcel fields can be defined like following:
>>> entries: List[SecurityZoneListEntry] = Field(default=[], validation_alias=AliasPath("data", "entries"))
"data" is default _parcel_data_key which must match validation_alias prefix,
this attribute can be overriden in sub-class when needed
"""
model_dict = handler(self)
model_dict[self._parcel_data_key] = {}
remove_keys = []
Expand All @@ -43,6 +62,13 @@ def envelope_parcel_data(self, handler) -> Dict[str, Any]:
del model_dict[key]
return model_dict

@classmethod
def _get_parcel_type(cls) -> str:
field_info = cls.model_fields.get("type_")
if field_info is not None:
return str(field_info.default)
raise CatalystwanException("Field parcel type is not set.")


class OptionType(str, Enum):
GLOBAL = "global"
Expand All @@ -51,7 +77,7 @@ class OptionType(str, Enum):


class ParcelAttribute(BaseModel):
model_config = ConfigDict(extra="forbid")
model_config = ConfigDict(extra="forbid", populate_by_name=True)
option_type: OptionType = Field(serialization_alias="optionType", validation_alias="optionType")


Expand Down
Loading

0 comments on commit 9fee3e6

Please sign in to comment.