Skip to content

Commit 2ed6c74

Browse files
authored
[dev]: add get or create method to service feature profile builder for dhcp server (#193)
* feat: add get or create method to service feature profile builder for dhcp server * chore: bump SDK version
1 parent 4110f13 commit 2ed6c74

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

catalystwan/api/builders/feature_profiles/service.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(self, session: ManagerSession):
6969
self._interfaces_with_attached_dhcp_server: Dict[str, LanVpnDhcpServerParcel] = {}
7070
# Trackers
7171
self.init_tracker()
72+
self._dhcp_server_uuids: Dict[str, UUID] = {}
7273

7374
def add_profile_name_and_description(self, feature_profile: FeatureProfileCreationPayload) -> None:
7475
"""
@@ -216,7 +217,7 @@ def build(self) -> FeatureProfileBuildReport:
216217
continue
217218

218219
if dhcp_server:
219-
dhcp_server_uuid = self._create_parcel(profile_uuid, dhcp_server)
220+
dhcp_server_uuid = self._get_or_create_dhcp_server_uuid(profile_uuid, dhcp_server)
220221
if dhcp_server_uuid is not None:
221222
with handle_association_request(self.build_report, sub_parcel):
222223
self._endpoints.associate_dhcp_server_with_vpn_interface(
@@ -246,3 +247,11 @@ def build(self) -> FeatureProfileBuildReport:
246247
@handle_create_parcel
247248
def _create_parcel(self, profile_uuid: UUID, parcel: AnyServiceParcel, vpn_uuid: Optional[None] = None) -> UUID:
248249
return self._api.create_parcel(profile_uuid, parcel, vpn_uuid).id
250+
251+
def _get_or_create_dhcp_server_uuid(self, profile_uuid: UUID, dhcp_server: LanVpnDhcpServerParcel) -> UUID:
252+
existing_uuid = self._dhcp_server_uuids.get(dhcp_server.parcel_name)
253+
if existing_uuid:
254+
return existing_uuid
255+
dhcp_server_uuid = self._create_parcel(profile_uuid, dhcp_server)
256+
self._dhcp_server_uuids[dhcp_server.parcel_name] = dhcp_server_uuid
257+
return dhcp_server_uuid

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "catalystwan"
3-
version = "0.41.5dev0"
3+
version = "0.41.5dev1"
44
description = "Cisco Catalyst WAN SDK for Python"
55
authors = ["sbasan <sbasan@cisco.com>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)