Skip to content

Commit

Permalink
Allow non-templated do_edit_wlan attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ms264556 committed Apr 20, 2024
1 parent 9f3c551 commit 4bf5f22
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
6 changes: 6 additions & 0 deletions aioruckus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class WlanEncryption(Enum):
WPA23_MIXED = "wpa23-mixed"
WPA3 = "wpa3"

class PatchNewAttributeMode(Enum):
"""Treatment of patch attributes which are missing from existing XML"""
ERROR = "error"
IGNORE = "ignore"
ADD = "add"

URL_FILTERING_CATEGORIES = {
"1": "Real Estate",
"2": "Computer and Internet Security",
Expand Down
23 changes: 13 additions & 10 deletions aioruckus/nativeajaxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ERROR_SAEPASSPHRASE_MISSING,
ERROR_INVALID_WLAN,
ERROR_PASSPHRASE_NAME,
PatchNewAttributeMode,
SystemStat,
WlanEncryption
)
Expand Down Expand Up @@ -240,13 +241,13 @@ async def do_clone_wlan(
await self._add_wlan_template(wlansvc)

async def do_edit_wlan(
self, name: str, patch: dict, ignore_unknown_attributes: bool = False
self, name: str, patch: dict, patch_new_attributes: PatchNewAttributeMode = PatchNewAttributeMode.ERROR
) -> None:
"""Edit a WLAN"""
wlansvc = await self._get_wlan_template(name)
if wlansvc:
self._normalize_encryption(wlansvc, patch)
self._patch_template(wlansvc, patch, ignore_unknown_attributes)
self._patch_template(wlansvc, patch, patch_new_attributes)
await self._update_wlan_template(wlansvc)

async def do_delete_wlan(self, name: str) -> bool:
Expand Down Expand Up @@ -413,7 +414,7 @@ def _patch_template(
self,
element: ET.Element,
patch: dict,
ignore_unknown_attributes: bool = False,
patch_new_attributes: PatchNewAttributeMode = PatchNewAttributeMode.ERROR,
current_path: str = ""
) -> None:
visited_children = set()
Expand All @@ -422,7 +423,7 @@ def _patch_template(
self._patch_template(
child,
patch[child.tag],
ignore_unknown_attributes,
patch_new_attributes,
f"{current_path}/{child.tag}"
)
visited_children.add(child.tag)
Expand All @@ -434,14 +435,16 @@ def _patch_template(
if isinstance(value, List):
raise ValueError(f"Applying lists is unsupported: {current_path}/{name}")
if current_value is None:
if not ignore_unknown_attributes:
if patch_new_attributes == PatchNewAttributeMode.ERROR:
raise ValueError(f"Unknown attribute: {current_path}/{name}")
elif patch_new_attributes == PatchNewAttributeMode.IGNORE:
continue
else:
new_value = self._normalize_conf_value(current_value, value)
element.set(name, new_value)
x_name = f"x-{name}"
if x_name not in patch and x_name in element.attrib:
element.set(x_name, new_value)
value = self._normalize_conf_value(current_value, value)
element.set(name, value)
x_name = f"x-{name}"
if x_name not in patch and x_name in element.attrib:
element.set(x_name, value)

async def _update_wlan_template(self, wlansvc: ET.Element):
"""Update WLAN template"""
Expand Down
7 changes: 7 additions & 0 deletions aioruckus/ruckusajaxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ERROR_INVALID_MAC,
ERROR_PASSPHRASE_LEN,
ERROR_PASSPHRASE_JS,
PatchNewAttributeMode,
SystemStat
)
from .ruckusapi import RuckusApi
Expand Down Expand Up @@ -134,6 +135,12 @@ async def do_enable_wlan(self, name: str) -> None:
"""Enable a WLAN"""
pass

@abstractmethod
async def do_edit_wlan(
self, name: str, patch: dict, patch_new_attributes: PatchNewAttributeMode = PatchNewAttributeMode.ERROR
) -> None:
pass

@abstractmethod
async def do_set_wlan_password(
self,
Expand Down

0 comments on commit 4bf5f22

Please sign in to comment.