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

Commit

Permalink
draft: uc-voice profile api
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Oct 17, 2024
1 parent 4217958 commit 35a2396
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 16 deletions.
149 changes: 142 additions & 7 deletions catalystwan/api/feature_profile_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from catalystwan.endpoints.configuration.feature_profile.sdwan.system import SystemFeatureProfile
from catalystwan.endpoints.configuration.feature_profile.sdwan.topology import TopologyFeatureProfile
from catalystwan.endpoints.configuration.feature_profile.sdwan.transport import TransportFeatureProfile
from catalystwan.endpoints.configuration.feature_profile.sdwan.uc_voice import UcVoiceFeatureProfile
from catalystwan.exceptions import CatalystwanException, ManagerHTTPError
from catalystwan.models.configuration.feature_profile.sdwan.acl.ipv4acl import Ipv4AclParcel
from catalystwan.models.configuration.feature_profile.sdwan.acl.ipv6acl import Ipv6AclParcel
Expand Down Expand Up @@ -106,6 +107,10 @@
InterfaceEthPPPoEParcel,
)
from catalystwan.models.configuration.feature_profile.sdwan.transport.wan.interface.t1e1serial import T1E1SerialParcel
from catalystwan.models.configuration.feature_profile.sdwan.uc_voice import AnyUcVoiceParcel
from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.dsp_farm import DspFarmParcel
from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.media_profile import MediaProfileParcel
from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.trunk_group import TrunkGroupParcel
from catalystwan.typed_list import DataSequence

if TYPE_CHECKING:
Expand Down Expand Up @@ -193,17 +198,18 @@ def __init__(self, session: ManagerSession):

class SDWANFeatureProfilesAPI:
def __init__(self, session: ManagerSession):
self.policy_object = PolicyObjectFeatureProfileAPI(session=session)
self.system = SystemFeatureProfileAPI(session=session)
self.application_priority = ApplicationPriorityFeatureProfileAPI(session=session)
self.cli = CliFeatureProfileAPI(session=session)
self.dns_security = DnsSecurityFeatureProfileAPI(session=session)
self.embedded_security = EmbeddedSecurityFeatureProfileAPI(session=session)
self.other = OtherFeatureProfileAPI(session=session)
self.policy_object = PolicyObjectFeatureProfileAPI(session=session)
self.service = ServiceFeatureProfileAPI(session=session)
self.sig_security = SIGSecurityAPI(session=session)
self.system = SystemFeatureProfileAPI(session=session)
self.topology = TopologyFeatureProfileAPI(session=session)
self.transport = TransportFeatureProfileAPI(session=session)
self.embedded_security = EmbeddedSecurityFeatureProfileAPI(session=session)
self.cli = CliFeatureProfileAPI(session=session)
self.dns_security = DnsSecurityFeatureProfileAPI(session=session)
self.sig_security = SIGSecurityAPI(session=session)
self.application_priority = ApplicationPriorityFeatureProfileAPI(session=session)
self.uc_voice = UcVoiceFeatureProfileAPI(session=session)


class FeatureProfileAPI(Protocol):
Expand Down Expand Up @@ -2246,3 +2252,132 @@ def get_parcel(
Get one Topology Parcel given profile id, parcel type and parcel id
"""
return self.endpoint.get_any_parcel_by_id(profile_id, parcel_type._get_parcel_type(), parcel_id)


class UcVoiceFeatureProfileAPI:
"""
SDWAN Feature Profile UC Voice APIs
"""

def __init__(self, session: ManagerSession):
self.session = session
self.endpoint = UcVoiceFeatureProfile(session)

def get_profiles(
self, limit: Optional[int] = None, offset: Optional[int] = None
) -> DataSequence[FeatureProfileInfo]:
"""
Get all UC Voice Feature Profiles
"""
payload = GetFeatureProfilesParams(limit=limit if limit else None, offset=offset if offset else None)

return self.endpoint.get_uc_voice_feature_profiles(payload)

def create_profile(self, name: str, description: str) -> FeatureProfileCreationResponse:
"""
Create UC Voice Feature Profile
"""
payload = FeatureProfileCreationPayload(name=name, description=description)
return self.endpoint.create_uc_voice_feature_profile(payload)

def delete_profile(self, profile_id: UUID) -> None:
"""
Delete UC Voice Feature Profile
"""
self.endpoint.delete_uc_voice_feature_profile(str(profile_id))

def delete_all_profiles(self) -> None:
"""
Delete all UC Voice Feature Profiles
"""
profiles = self.get_profiles()
for profile in profiles:
self.delete_profile(profile.profile_id)

@overload
def get_parcels(
self,
profile_id: UUID,
parcel_type: Type[DspFarmParcel],
) -> DataSequence[Parcel[DspFarmParcel]]:
...

@overload
def get_parcels(
self,
profile_id: UUID,
parcel_type: Type[MediaProfileParcel],
) -> DataSequence[Parcel[MediaProfileParcel]]:
...

@overload
def get_parcels(
self,
profile_id: UUID,
parcel_type: Type[TrunkGroupParcel],
) -> DataSequence[Parcel[TrunkGroupParcel]]:
...

def get_parcels(self, profile_id: UUID, parcel_type: Type[AnyUcVoiceParcel]) -> DataSequence[Parcel]:
"""
Get all UC Voice Parcels given profile id and parcel type
"""
return self.endpoint.get_all(profile_id, parcel_type._get_parcel_type())

@overload
def get_parcel(
self,
profile_id: UUID,
parcel_type: Type[DspFarmParcel],
parcel_id: UUID,
) -> Parcel[DspFarmParcel]:
...

@overload
def get_parcel(
self,
profile_id: UUID,
parcel_type: Type[MediaProfileParcel],
parcel_id: UUID,
) -> Parcel[MediaProfileParcel]:
...

@overload
def get_parcel(
self,
profile_id: UUID,
parcel_type: Type[TrunkGroupParcel],
parcel_id: UUID,
) -> Parcel[TrunkGroupParcel]:
...

def get_parcel(
self,
profile_id: UUID,
parcel_type: Type[AnyUcVoiceParcel],
parcel_id: UUID,
) -> Parcel:
"""
Get one UC Voice Parcel given profile id, parcel type and parcel id
"""
return self.endpoint.get_by_id(profile_id, parcel_type._get_parcel_type(), parcel_id)

def create_parcel(self, profile_id: UUID, payload: AnyUcVoiceParcel) -> ParcelCreationResponse:
"""
Create UC Voice Parcel for selected profile_id based on payload type
"""

return self.endpoint.create(profile_id, payload._get_parcel_type(), payload)

def update_parcel(self, profile_id: UUID, payload: AnyUcVoiceParcel, parcel_id: UUID) -> ParcelCreationResponse:
"""
Update UC Voice Parcel for selected profile_id based on payload type
"""

return self.endpoint.update(profile_id, payload._get_parcel_type(), parcel_id, payload)

def delete_parcel(self, profile_id: UUID, parcel_type: Type[AnyUcVoiceParcel], parcel_id: UUID) -> None:
"""
Delete UC Voice Parcel for selected profile_id based on payload type
"""
return self.endpoint.delete(profile_id, parcel_type._get_parcel_type(), parcel_id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

# mypy: disable-error-code="empty-body"
from uuid import UUID

from catalystwan.endpoints import APIEndpoints, delete, get, post, put, versions
from catalystwan.models.configuration.feature_profile.common import (
FeatureProfileCreationPayload,
FeatureProfileCreationResponse,
FeatureProfileDetail,
FeatureProfileEditPayload,
FeatureProfileInfo,
GetFeatureProfilesParams,
)
from catalystwan.models.configuration.feature_profile.parcel import Parcel, ParcelCreationResponse
from catalystwan.models.configuration.feature_profile.sdwan.uc_voice import AnyUcVoiceParcel
from catalystwan.typed_list import DataSequence


class UcVoiceFeatureProfile(APIEndpoints):
@versions(supported_versions=(">=20.13"), raises=False)
@post("/v1/feature-profile/sdwan/uc-voice")
def create_uc_voice_feature_profile(self, payload: FeatureProfileCreationPayload) -> FeatureProfileCreationResponse:
...

@versions(supported_versions=(">=20.13"), raises=False)
@get("/v1/feature-profile/sdwan/uc-voice")
def get_uc_voice_feature_profiles(self, params: GetFeatureProfilesParams) -> DataSequence[FeatureProfileInfo]:
...

@versions(supported_versions=(">=20.13"), raises=False)
@get("/v1/feature-profile/sdwan/uc-voice/{profile_id}")
def get_uc_voice_feature_profile(self, profile_id: str, params: GetFeatureProfilesParams) -> FeatureProfileDetail:
...

@versions(supported_versions=(">=20.13"), raises=False)
@put("/v1/feature-profile/sdwan/uc-voice/{profile_id}")
def edit_uc_voice_feature_profile(
self, profile_id: str, payload: FeatureProfileEditPayload
) -> FeatureProfileCreationResponse:
...

@versions(supported_versions=(">=20.13"), raises=False)
@delete("/v1/feature-profile/sdwan/uc-voice/{profile_id}")
def delete_uc_voice_feature_profile(self, profile_id: str) -> None:
...

@versions(supported_versions=(">=20.13"), raises=False)
@post("/v1/feature-profile/sdwan/uc-voice/{profile_id}/{uc_voice_list_type}")
def create(self, profile_id: UUID, uc_voice_list_type: str, payload: AnyUcVoiceParcel) -> ParcelCreationResponse:
...

@versions(supported_versions=(">=20.13"), raises=False)
@delete("/v1/feature-profile/sdwan/uc-voice/{profile_id}/{uc_voice_list_type}/{parcel_id}")
def delete(self, profile_id: UUID, uc_voice_list_type: str, parcel_id: UUID) -> None:
...

@versions(supported_versions=(">=20.13"), raises=False)
@put("/v1/feature-profile/sdwan/uc-voice/{profile_id}/{uc_voice_list_type}/{parcel_id}")
def update(
self,
profile_id: UUID,
uc_voice_list_type: str,
parcel_id: UUID,
payload: AnyUcVoiceParcel,
) -> ParcelCreationResponse:
...

@versions(supported_versions=(">=20.13"), raises=False)
@get("/v1/feature-profile/sdwan/uc-voice/{profile_id}/{uc_voice_list_type}/{parcel_id}")
def get_by_id(self, profile_id: UUID, uc_voice_list_type: str, parcel_id: UUID) -> Parcel[AnyUcVoiceParcel]:
...

@versions(supported_versions=(">=20.13"), raises=False)
@get("/v1/feature-profile/sdwan/uc-voice/{profile_id}/{uc_voice_list_type}", resp_json_key="data")
def get_all(self, profile_id: UUID, uc_voice_list_type: str) -> DataSequence[Parcel[AnyUcVoiceParcel]]:
...
23 changes: 14 additions & 9 deletions catalystwan/models/configuration/feature_profile/parcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from catalystwan.models.configuration.feature_profile.sdwan.system import AnySystemParcel
from catalystwan.models.configuration.feature_profile.sdwan.topology import AnyTopologyParcel
from catalystwan.models.configuration.feature_profile.sdwan.transport import AnyTransportParcel
from catalystwan.models.configuration.feature_profile.sdwan.uc_voice import AnyUcVoiceParcel
from catalystwan.models.configuration.network_hierarchy import AnyNetworkHierarchyParcel
from catalystwan.utils.model import resolve_nested_base_model_unions

Expand All @@ -42,6 +43,7 @@
"data-prefix",
"dhcp-server",
"dns",
"dsp-farm",
"expanded-community",
"ext-community",
"full-config",
Expand All @@ -60,6 +62,7 @@
"logging",
"management/vpn",
"management/vpn/interface/ethernet",
"media-profile",
"mesh",
"mirror",
"mrf",
Expand Down Expand Up @@ -100,6 +103,7 @@
"tracker",
"trackergroup",
"traffic-policy",
"trunk-group",
"unified/advanced-inspection-profile",
"unified/advanced-malware-protection",
"unified/intrusion-prevention",
Expand All @@ -124,19 +128,20 @@

AnyParcel = Annotated[
Union[
AnySystemParcel,
AnyPolicyObjectParcel,
AnyServiceParcel,
AnyOtherParcel,
AnyTransportParcel,
AnyEmbeddedSecurityParcel,
AnyApplicationPriorityParcel,
AnyCliParcel,
AnyDnsSecurityParcel,
AnyEmbeddedSecurityParcel,
AnyNetworkHierarchyParcel,
AnyOtherParcel,
AnyPolicyObjectParcel,
AnyRoutingParcel,
AnyServiceParcel,
AnySIGSecurityParcel,
AnyApplicationPriorityParcel,
AnySystemParcel,
AnyTopologyParcel,
AnyRoutingParcel,
AnyNetworkHierarchyParcel,
AnyTransportParcel,
AnyUcVoiceParcel,
],
Field(discriminator="type_"),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from typing import List, Union

from pydantic import Field
from typing_extensions import Annotated

from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.media_profile import MediaProfileParcel
from catalystwan.models.configuration.feature_profile.sdwan.uc_voice.trunk_group import TrunkGroupParcel

from .dsp_farm import DspFarmParcel

AnyUcVoiceParcel = Annotated[
Union[
DspFarmParcel,
MediaProfileParcel,
TrunkGroupParcel,
],
Field(discriminator="type_"),
]

__all__ = ("AnyUcVoiceParcel", "DspFarmParcel", "MediaProfileParcel", "TrunkGroupParcel")


def __dir__() -> "List[str]":
return list(__all__)
Loading

0 comments on commit 35a2396

Please sign in to comment.