Skip to content

Commit

Permalink
feat: added order_rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Sep 27, 2023
1 parent 98bd886 commit 1797d70
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/nethsec/mwan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,31 @@ def index_rules(e_uci: EUci) -> list[dict]:

data.append(rule_data)
return data


def order_rules(e_uci: EUci, rules: list[str]) -> list[str]:
for rule in utils.get_all_by_type(e_uci, 'mwan3', 'rule').keys():
if rule not in rules:
raise ValidationError('rules', 'missing', rule)

order: list[str] = []

for key in e_uci.get_all('mwan3').keys():
if key not in rules:
order.append(key)

order.extend(rules)

subprocess.check_output([
'ubus',
'call',
'uci',
'order',
json.dumps({
'config': 'mwan3',
'sections': order,
})
])

e_uci.save('mwan3')
return order

0 comments on commit 1797d70

Please sign in to comment.