summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/qos/base.py21
-rw-r--r--python/vyos/template.py14
2 files changed, 28 insertions, 7 deletions
diff --git a/python/vyos/qos/base.py b/python/vyos/qos/base.py
index 378e11acf..33bb8ae28 100644
--- a/python/vyos/qos/base.py
+++ b/python/vyos/qos/base.py
@@ -121,13 +121,20 @@ class QoSBase:
}
if rate == 'auto' or rate.endswith('%'):
- speed = read_file(f'/sys/class/net/{self._interface}/speed')
- if not speed.isnumeric():
- Warning('Interface speed cannot be determined (assuming 10 Mbit/s)')
- speed = 10
- if rate.endswith('%'):
- percent = rate.rstrip('%')
- speed = int(speed) * int(percent) // 100
+ speed = 10
+ # Not all interfaces have valid entries in the speed file. PPPoE
+ # interfaces have the appropriate speed file, but you can not read it:
+ # cat: /sys/class/net/pppoe7/speed: Invalid argument
+ try:
+ speed = read_file(f'/sys/class/net/{self._interface}/speed')
+ if not speed.isnumeric():
+ Warning('Interface speed cannot be determined (assuming 10 Mbit/s)')
+ if rate.endswith('%'):
+ percent = rate.rstrip('%')
+ speed = int(speed) * int(percent) // 100
+ except:
+ pass
+
return int(speed) *1000000 # convert to MBit/s
rate_numeric = int(''.join([n for n in rate if n.isdigit()]))
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 6367f51e5..7f417992e 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -663,7 +663,21 @@ def nat_static_rule(rule_conf, rule_id, nat_type):
@register_filter('range_to_regex')
def range_to_regex(num_range):
+ """Convert range of numbers or list of ranges
+ to regex
+
+ % range_to_regex('11-12')
+ '(1[1-2])'
+ % range_to_regex(['11-12', '14-15'])
+ '(1[1-2]|1[4-5])'
+ """
from vyos.range_regex import range_to_regex
+ if isinstance(num_range, list):
+ data = []
+ for entry in num_range:
+ data.append(range_to_regex(entry))
+ return f'({"|".join(data)})'
+
if '-' not in num_range:
return num_range