summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/configdict.py13
-rw-r--r--python/vyos/defaults.py1
-rw-r--r--python/vyos/opmode.py35
-rw-r--r--python/vyos/template.py17
-rw-r--r--python/vyos/util.py6
5 files changed, 69 insertions, 3 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py
index 53decfbf5..434ff99d7 100644
--- a/python/vyos/configdict.py
+++ b/python/vyos/configdict.py
@@ -427,6 +427,10 @@ def get_interface_dict(config, base, ifname=''):
# Add interface instance name into dictionary
dict.update({'ifname': ifname})
+ # Check if QoS policy applied on this interface - See ifconfig.interface.set_mirror_redirect()
+ if config.exists(['qos', 'interface', ifname]):
+ dict.update({'traffic_policy': {}})
+
# XXX: T2665: When there is no DHCPv6-PD configuration given, we can safely
# remove the default values from the dict.
if 'dhcpv6_options' not in dict:
@@ -498,6 +502,9 @@ def get_interface_dict(config, base, ifname=''):
# Add subinterface name to dictionary
dict['vif'][vif].update({'ifname' : f'{ifname}.{vif}'})
+ if config.exists(['qos', 'interface', f'{ifname}.{vif}']):
+ dict['vif'][vif].update({'traffic_policy': {}})
+
default_vif_values = defaults(base + ['vif'])
# XXX: T2665: When there is no DHCPv6-PD configuration given, we can safely
# remove the default values from the dict.
@@ -532,6 +539,9 @@ def get_interface_dict(config, base, ifname=''):
# Add subinterface name to dictionary
dict['vif_s'][vif_s].update({'ifname' : f'{ifname}.{vif_s}'})
+ if config.exists(['qos', 'interface', f'{ifname}.{vif_s}']):
+ dict['vif_s'][vif_s].update({'traffic_policy': {}})
+
default_vif_s_values = defaults(base + ['vif-s'])
# XXX: T2665: we only wan't the vif-s defaults - do not care about vif-c
if 'vif_c' in default_vif_s_values: del default_vif_s_values['vif_c']
@@ -571,6 +581,9 @@ def get_interface_dict(config, base, ifname=''):
# Add subinterface name to dictionary
dict['vif_s'][vif_s]['vif_c'][vif_c].update({'ifname' : f'{ifname}.{vif_s}.{vif_c}'})
+ if config.exists(['qos', 'interface', f'{ifname}.{vif_s}.{vif_c}']):
+ dict['vif_s'][vif_s]['vif_c'][vif_c].update({'traffic_policy': {}})
+
default_vif_c_values = defaults(base + ['vif-s', 'vif-c'])
# XXX: T2665: When there is no DHCPv6-PD configuration given, we can safely
diff --git a/python/vyos/defaults.py b/python/vyos/defaults.py
index 060a0ba03..d4ffc249e 100644
--- a/python/vyos/defaults.py
+++ b/python/vyos/defaults.py
@@ -30,6 +30,7 @@ directories = {
'templates' : '/usr/share/vyos/templates/',
'certbot' : '/config/auth/letsencrypt',
'api_schema': f'{base_dir}/services/api/graphql/graphql/schema/',
+ 'api_client_op': f'{base_dir}/services/api/graphql/graphql/client_op/',
'api_templates': f'{base_dir}/services/api/graphql/session/templates/',
'vyos_udev_dir' : '/run/udev/vyos'
}
diff --git a/python/vyos/opmode.py b/python/vyos/opmode.py
index d02ad4de6..d7172a0b5 100644
--- a/python/vyos/opmode.py
+++ b/python/vyos/opmode.py
@@ -128,6 +128,25 @@ def _get_arg_type(t):
else:
return t
+def _is_literal_type(t):
+ if _is_optional_type(t):
+ t = _get_arg_type(t)
+
+ if typing.get_origin(t) == typing.Literal:
+ return True
+
+ return False
+
+def _get_literal_values(t):
+ """ Returns the tuple of allowed values for a Literal type
+ """
+ if not _is_literal_type(t):
+ return tuple()
+ if _is_optional_type(t):
+ t = _get_arg_type(t)
+
+ return typing.get_args(t)
+
def _normalize_field_name(name):
# Convert the name to string if it is not
# (in some cases they may be numbers)
@@ -194,9 +213,21 @@ def run(module):
subparser.add_argument(f"--{opt}", action='store_true')
else:
if _is_optional_type(th):
- subparser.add_argument(f"--{opt}", type=_get_arg_type(th), default=None)
+ if _is_literal_type(th):
+ subparser.add_argument(f"--{opt}",
+ choices=list(_get_literal_values(th)),
+ default=None)
+ else:
+ subparser.add_argument(f"--{opt}",
+ type=_get_arg_type(th), default=None)
else:
- subparser.add_argument(f"--{opt}", type=_get_arg_type(th), required=True)
+ if _is_literal_type(th):
+ subparser.add_argument(f"--{opt}",
+ choices=list(_get_literal_values(th)),
+ required=True)
+ else:
+ subparser.add_argument(f"--{opt}",
+ type=_get_arg_type(th), required=True)
# Get options as a dict rather than a namespace,
# so that we can modify it and pack for passing to functions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 6367f51e5..06a292706 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -663,7 +663,24 @@ 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:
+ 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
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 66ded464d..0593184cc 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -874,12 +874,16 @@ def convert_data(data):
Returns:
str | list | dict: converted data
"""
+ from base64 import b64encode
from collections import OrderedDict
if isinstance(data, str):
return data
if isinstance(data, bytes):
- return data.decode()
+ try:
+ return data.decode()
+ except UnicodeDecodeError:
+ return b64encode(data).decode()
if isinstance(data, list):
list_tmp = []
for item in data: