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

Commit

Permalink
Revert "Dev/rebase migration" (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan authored Mar 8, 2024
1 parent a9709f4 commit faba69a
Show file tree
Hide file tree
Showing 83 changed files with 677 additions and 4,116 deletions.
3 changes: 1 addition & 2 deletions 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, SDWANFeatureProfilesAPI
from catalystwan.api.feature_profile_api import SDRoutingFeatureProfilesAPI
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,4 +66,3 @@ 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: 5 additions & 11 deletions catalystwan/api/config_group_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

from __future__ import annotations

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

from catalystwan.typed_list import DataSequence
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from catalystwan.session import ManagerSession

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

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

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

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

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

from catalystwan.exceptions import CatalystwanException
from pydantic import AliasPath, BaseModel, ConfigDict, Field, PrivateAttr, model_serializer

T = TypeVar("T")


class _ParcelBase(BaseModel):
model_config = ConfigDict(
extra="allow", arbitrary_types_allowed=True, populate_by_name=True, json_schema_mode_override="validation"
)
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, populate_by_name=True)
parcel_name: str = Field(
min_length=1,
max_length=128,
Expand All @@ -35,18 +23,11 @@ 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: 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
"""
def envelope_parcel_data(self, handler) -> Dict[str, Any]:
model_dict = handler(self)
model_dict[self._parcel_data_key] = {}
remove_keys = []
Expand All @@ -62,13 +43,6 @@ def envelope_parcel_data(self, handler: SerializerFunctionWrapHandler) -> Dict[s
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 @@ -77,7 +51,7 @@ class OptionType(str, Enum):


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


Expand Down
Loading

0 comments on commit faba69a

Please sign in to comment.