Skip to content

Commit

Permalink
mac_qos continued
Browse files Browse the repository at this point in the history
* mac_qos_continued.

* Added validate_weekday method.
  • Loading branch information
dzhuang authored Feb 14, 2024
1 parent 25fed5a commit 1e6bf40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ The access control of device via mac address. The implemented methods include: `
### mac_comment

The management of alias of devices, mapping mac addresses. The implemented methods include: `add_mac_comment`, `list_mac_comment`, `edit_mac_comment`, `del_mac_comment`.

### mac_qos

The interface for limiting download/upload speed of devices, mapping mac addresses. The implemented methods include: `add_mac_qos`, `list_mac_qos`, `edit_mac_qos`, `del_mac_qos`, `enable_mac_qos`, `disable_mac_qos`.
24 changes: 24 additions & 0 deletions src/pyikuai/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ def exec(self, func_name, action, param, ensure_success=True):
raise RequestError(
f"Request failed with response status code: {response.status_code}")

@staticmethod
def validate_weekday(weekdays_str):
input_chars_set = set(weekdays_str)
invalid_chars = input_chars_set - set("1234567")

if invalid_chars:
raise ValueError(
f"weekdays str contains invalid characters: {invalid_chars}")

sorted_unique_chars = sorted(input_chars_set)
return ''.join(sorted_unique_chars)

@staticmethod
def validate_time_range(time_range_str):
# 分割字符串以检查两个时间
Expand Down Expand Up @@ -230,6 +242,7 @@ def _get_acl_l7_param(
week="1234567"):

self.validate_time_range(time)
self.validate_weekday(week)

app_protos = app_protos or []
enabled = "yes" if enabled else "no"
Expand Down Expand Up @@ -331,6 +344,7 @@ def _get_domain_blacklist_param(
weekdays="1234567"):

self.validate_time_range(time)
self.validate_weekday(weekdays)

domain_groups = domain_groups or []
enabled = "yes" if enabled else "no"
Expand Down Expand Up @@ -507,6 +521,7 @@ def _get_acl_mac_param(
week="1234567"):

self.validate_time_range(time)
self.validate_weekday(week)

enabled = "yes" if enabled else "no"
comment = comment or ""
Expand Down Expand Up @@ -606,6 +621,14 @@ def enable_acl_mac(self, acl_mac_id):
# {{{ mac_qos CRUD
# 流控分流 之 MAC限速

def list_mac_qos(self, **query_kwargs):
result = self.exec(
func_name=rp_func_name.mac_qos,
action=rp_action.show,
param=QueryRPParam(**query_kwargs).as_dict()
)
return result[JSON_RESPONSE_DATA]

def _get_mac_qos_param(
self,
mac_addrs,
Expand Down Expand Up @@ -643,6 +666,7 @@ def _get_mac_qos_param(
ip_type = str(ip_type)

self.validate_time_range(time)
self.validate_weekday(week)

enabled = "yes" if enabled else "no"
comment = comment or ""
Expand Down

0 comments on commit 1e6bf40

Please sign in to comment.