diff options
author | Daniil Baturin <daniil@vyos.io> | 2023-03-16 14:11:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-16 14:11:19 +0000 |
commit | fda93b223239eb5040374754323ae51160785610 (patch) | |
tree | ded2a94c895a817cdc8d256c1e9c1eea86c5d0d7 /python | |
parent | 34cab2599c5bb32d38973dfcd60c51d30a5fdb3b (diff) | |
parent | 4eccfe6a19b457720ece4ab9a66b10a95f34b635 (diff) | |
download | vyos-1x-fda93b223239eb5040374754323ae51160785610.tar.gz vyos-1x-fda93b223239eb5040374754323ae51160785610.zip |
Merge pull request #1885 from sever-sever/T5058-eq
T5058: Fix IPoE regex Jinja2 for interface
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/template.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py index 4778bf1c8..c98d6874e 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -362,3 +362,28 @@ def get_ipv4(interface): """ Get interface IPv4 addresses""" from vyos.ifconfig import Interface return Interface(interface).get_addr_v4() + +@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: + if '-' not in entry: + data.append(entry) + else: + data.append(range_to_regex(entry)) + return f'({"|".join(data)})' + + if '-' not in num_range: + return num_range + + regex = range_to_regex(num_range) + return f'({regex})' |