package documentation

Mwan utilities

From __init__.py:

Function clear_config Clears mwan3 configuration.
Function delete_policy Deletes a mwan3 policy.
Function delete_rule Deletes a mwan3 rule.
Function edit_policy Edits a mwan3 policy.
Function edit_rule Edits a mwan3 rule.
Function get_default_config Returns default configuration for mwan3.
Function index_policies Returns a list of policies with their members, interfaces and metrics/weights.
Function index_rules Returns a list of rules with their policies.
Function order_rules Orders mwan3 rules, moves everything else but rules to the end of the list.
Function set_default_config Sets default configuration for mwan3.
Function store_policy Stores a policy for mwan3, takes care of creating interfaces and members.
Function store_rule Stores a rule for mwan3
Function update_rules Updates mwan3 rules with objects addresses
Function __add_interfaces Add interfaces to policy, takes care of creating interfaces and members.
Function __fetch_interface_status Undocumented
Function __generate_metric Generates a metric for an interface.
Function __parse_member Parses a member configuration and returns formatted data.
Function __set_interface_defaults Undocumented
Function __store_interface Stores interface configuration for mwan3 and network, not suited to be used outside store_policy.
Function __store_member Stores member configuration for mwan3, not suited to be used outside store_policy.
Function _is_valid_dst Validate the given object for destination. Destination objects can be only: - dhcp reservation - dns domain - vpn user - a singleton host set
Function _is_valid_src Validate the given object for source. Source objects can be only: - dhcp reservation - dns domain - vpn user - a singleton host set
def clear_config(e_uci: EUci): (source)

Clears mwan3 configuration.

Args:
e_uci: euci instance
def delete_policy(e_uci: EUci, name: str) -> list[str]: (source)

Deletes a mwan3 policy.

Args:
e_uci: euci instance name: name of policy to delete
Returns:
list of deleted mwan3 entries
def delete_rule(e_uci: EUci, name: str): (source)

Deletes a mwan3 rule.

Args:
e_uci: euci instance name: rule name to delete
Returns:
name of rule deleted
def edit_policy(e_uci: EUci, name: str, label: str, interfaces: list[dict]) -> list[str]: (source)

Edits a mwan3 policy.

Args:
e_uci: euci instance name: name of policy to edit label: policy label interfaces: dict of interfaces to add to policy
Returns:
list of changed mwan3 entries
Raises:
ValidationError: if name is not valid
def edit_rule(e_uci: EUci, name: str, policy: str, label: str, protocol: str = None, source_address: str = None, source_port: str = None, destination_address: str = None, destination_port: str = None, sticky: bool = False, ns_src: str = None, ns_dst: str = None): (source)

Edits a mwan3 rule.

Args:
e_uci: EUci instance name: rule name policy: policy to use for the rule label: rule label protocol: protocol in which the rule applies source_address: CIDR notation of source address source_port: port or port range destination_address: CIDR notation of destination address destination_port: port or port range sticky: whether to use sticky connections ns_src: source object, it overrides source_address ns_dst: destination object, it overrides destination_address
Raises:
ValidationError: if name is not valid or policy is not valid
def get_default_config(e_uci: EUci) -> dict: (source)

Returns default configuration for mwan3.

Args:
e_uci: euci instance
Returns:
dict with default configuration
def index_policies(e_uci: EUci) -> list[dict]: (source)

Returns a list of policies with their members, interfaces and metrics/weights.

Args:
e_uci: EUci instance
Returns:
list of dicts with policy data
def index_rules(e_uci: EUci) -> list[dict]: (source)

Returns a list of rules with their policies.

Args:
e_uci: euci instance
Returns:
parsed list of rules with assigned policy
def order_rules(e_uci: EUci, rules: list[str]) -> list[str]: (source)

Orders mwan3 rules, moves everything else but rules to the end of the list.

Args:
e_uci: euci instance rules: which order to put rules
Returns:
list of ordered mwan3 entries
Raises:
ValidationError: if a rule is not present in /etc/config/mwan3
def set_default_config(e_uci: EUci, track_ip: list[str], ping_timeout: int, ping_interval: int, ping_failure_interval: int, interface_down_threshold: int, interface_up_threshold: int): (source)

Sets default configuration for mwan3.

Args:
e_uci: euci instance track_ip: list of IPs to track ping_timeout: timeout for ping ping_interval: interval between pings ping_failure_interval: interval between failed pings interface_down_threshold: threshold for interface down interface_up_threshold: threshold for interface up
def store_policy(e_uci: EUci, name: str, interfaces: list[dict]) -> list[str]: (source)

Stores a policy for mwan3, takes care of creating interfaces and members.

Args:
e_uci: EUci instance name: name of policy interfaces: list of interfaces to add to policy, must have name, metric and weight fields
Returns:
list of changed configuration
Raises:
ValidationError: if name is not unique or length or get_id > 15
def store_rule(e_uci: EUci, name: str, policy: str, protocol: str = None, source_address: str = None, source_port: str = None, destination_address: str = None, destination_port: str = None, sticky: bool = False, ns_src: str = None, ns_dst: str = None) -> str: (source)

Stores a rule for mwan3

Args:
e_uci: EUci instance name: name of the rule, must be unique policy: policy to use for the rule, must be already set protocol: must be one of tcp, udp, icmp or all, defaults to 'all' source_address: source addresses to match source_port: source ports to match or range destination_address: destination addresses to match destination_port: destination ports to match or range sticky: whether to use sticky connections ns_src: source object, it overrides source_address ns_dst: destination object, it overrides destination_address
Returns:
name of the rule created
Raises:
ValidationError if name is not unique, policy is not valid or length get_id > 15
def update_rules(e_uci: EUci): (source)

Updates mwan3 rules with objects addresses

Args:
e_uci: euci instance
def __add_interfaces(e_uci: EUci, interfaces: list[dict], changed_config: list[str] = None) -> list[str]: (source)

Add interfaces to policy, takes care of creating interfaces and members.

Args:
e_uci: euci instance interfaces: list of interfaces to add changed_config: array of changed configuration
Returns:
list of member names added to policy
Raises:
ValidationError: if interface name is not defined in /etc/config/network
def __fetch_interface_status(interface_name: str) -> str: (source)

Undocumented

def __generate_metric(e_uci: EUci) -> int: (source)

Generates a metric for an interface.

Args:
e_uci: EUci instance
Returns:
first metric that is not present in interface_metrics
def __parse_member(e_uci: EUci, member_name: str) -> dict: (source)

Parses a member configuration and returns formatted data.

Args:
e_uci: EUci instance member_name: member name
Returns:
dict with member data
def __set_interface_defaults(e_uci: EUci, name: str): (source)

Undocumented

def __store_interface(e_uci: EUci, name: str) -> tuple[bool, bool]: (source)

Stores interface configuration for mwan3 and network, not suited to be used outside store_policy.

Args:
e_uci: EUci instance name: name of interface
Returns:
tuple of booleans, first one indicates if mwan interface was created, second one indicates if metric was added to network interface
Raises:
ValidationError: if interface name is not defined in /etc/config/network
def __store_member(e_uci: EUci, interface_name: str, metric: int, weight: int) -> tuple[str, bool]: (source)

Stores member configuration for mwan3, not suited to be used outside store_policy.

Args:
e_uci: EUci instance interface_name: name of interface to link the member to metric: metric of the member weight: weight of the member
Returns:
tuple of string and boolean, first one is the generated name of the member, second one indicates if the member was created
def _is_valid_dst(e_uci: EUci, database_id: str): (source)

Validate the given object for destination. Destination objects can be only: - dhcp reservation - dns domain - vpn user - a singleton host set

Args:
e_uci: EUci instance database_id: id of object
Returns:
True if object is valid, False otherwise
def _is_valid_src(e_uci: EUci, database_id: str): (source)

Validate the given object for source. Source objects can be only: - dhcp reservation - dns domain - vpn user - a singleton host set

Args:
e_uci: EUci instance database_id: id of object
Returns:
True if object is valid, False otherwise