diff options
-rw-r--r-- | op-mode-definitions/container.xml.in | 35 | ||||
-rw-r--r-- | python/vyos/configverify.py | 27 | ||||
-rw-r--r-- | python/vyos/ethtool.py | 24 | ||||
-rw-r--r-- | python/vyos/ifconfig/ethernet.py | 31 | ||||
-rwxr-xr-x | smoketest/scripts/cli/test_protocols_isis.py | 8 | ||||
-rwxr-xr-x | src/conf_mode/protocols_isis.py | 16 | ||||
-rwxr-xr-x | src/migration-scripts/policy/3-to-4 | 8 | ||||
-rwxr-xr-x | src/op_mode/dhcp.py | 3 |
8 files changed, 73 insertions, 79 deletions
diff --git a/op-mode-definitions/container.xml.in b/op-mode-definitions/container.xml.in index 4aa13e913..bb6f97b02 100644 --- a/op-mode-definitions/container.xml.in +++ b/op-mode-definitions/container.xml.in @@ -103,12 +103,28 @@ </properties> <command>sudo ${vyos_op_scripts_dir}/container.py show_container</command> <children> - <leafNode name="image"> + <node name="json"> + <properties> + <help>Show containers in JSON format</help> + </properties> + <!-- no admin check --> + <command>sudo ${vyos_op_scripts_dir}/container.py show_container --raw</command> + </node> + <node name="image"> <properties> <help>Show container image</help> </properties> <command>sudo ${vyos_op_scripts_dir}/container.py show_image</command> - </leafNode> + <children> + <node name="json"> + <properties> + <help>Show container image in JSON format</help> + </properties> + <!-- no admin check --> + <command>sudo ${vyos_op_scripts_dir}/container.py show_image --raw</command> + </node> + </children> + </node> <tagNode name="log"> <properties> <help>Show logs from a given container</help> @@ -116,14 +132,25 @@ <path>container name</path> </completionHelp> </properties> + <!-- no admin check --> <command>sudo podman logs --names "$4"</command> </tagNode> - <leafNode name="network"> + <node name="network"> <properties> <help>Show available container networks</help> </properties> + <!-- no admin check --> <command>sudo ${vyos_op_scripts_dir}/container.py show_network</command> - </leafNode> + <children> + <node name="json"> + <properties> + <help>Show available container networks in JSON format</help> + </properties> + <!-- no admin check --> + <command>sudo ${vyos_op_scripts_dir}/container.py show_network --raw</command> + </node> + </children> + </node> </children> </node> <node name="log"> diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index 5d3723876..6508ccdd9 100644 --- a/python/vyos/configverify.py +++ b/python/vyos/configverify.py @@ -269,14 +269,33 @@ def verify_bridge_delete(config): raise ConfigError(f'Interface "{interface}" cannot be deleted as it ' f'is a member of bridge "{bridge_name}"!') -def verify_interface_exists(ifname): +def verify_interface_exists(ifname, warning_only=False): """ Common helper function used by interface implementations to perform - recurring validation if an interface actually exists. + recurring validation if an interface actually exists. We first probe + if the interface is defined on the CLI, if it's not found we try if + it exists at the OS level. """ import os - if not os.path.exists(f'/sys/class/net/{ifname}'): - raise ConfigError(f'Interface "{ifname}" does not exist!') + from vyos.base import Warning + from vyos.configquery import ConfigTreeQuery + from vyos.utils.dict import dict_search_recursive + + # Check if interface is present in CLI config + config = ConfigTreeQuery() + tmp = config.get_config_dict(['interfaces'], get_first_key=True) + if bool(list(dict_search_recursive(tmp, ifname))): + return True + + # Interface not found on CLI, try Linux Kernel + if os.path.exists(f'/sys/class/net/{ifname}'): + return True + + message = f'Interface "{ifname}" does not exist!' + if warning_only: + Warning(message) + return False + raise ConfigError(message) def verify_source_interface(config): """ diff --git a/python/vyos/ethtool.py b/python/vyos/ethtool.py index 473c98d0c..5e241fc08 100644 --- a/python/vyos/ethtool.py +++ b/python/vyos/ethtool.py @@ -24,7 +24,6 @@ from vyos.utils.process import popen _drivers_without_speed_duplex_flow = ['vmxnet3', 'virtio_net', 'xen_netfront', 'iavf', 'ice', 'i40e', 'hv_netvsc', 'veth', 'ixgbevf', 'tun'] -_drivers_without_eee = ['vmxnet3', 'virtio_net', 'xen_netfront', 'hv_netvsc'] class Ethtool: """ @@ -63,8 +62,6 @@ class Ethtool: _auto_negotiation = False _auto_negotiation_supported = None _flow_control = None - _eee = False - _eee_enabled = None def __init__(self, ifname): # Get driver used for interface @@ -118,15 +115,6 @@ class Ethtool: if not bool(err): self._flow_control = loads(out) - # Get current Energy Efficient Ethernet (EEE) settings, but this is - # not supported by all NICs (e.g. vmxnet3 does not support is) - out, _ = popen(f'ethtool --show-eee {ifname}') - if len(out.splitlines()) > 1: - self._eee = True - # read current EEE setting, this returns: - # EEE status: disabled || EEE status: enabled - inactive || EEE status: enabled - active - self._eee_enabled = bool('enabled' in out.splitlines()[1]) - def check_auto_negotiation_supported(self): """ Check if the NIC supports changing auto-negotiation """ return self._auto_negotiation_supported @@ -211,15 +199,3 @@ class Ethtool: 'flow-control settings!') return 'on' if bool(self._flow_control[0]['autonegotiate']) else 'off' - - def check_eee(self): - """ Check if the NIC supports eee """ - if self.get_driver_name() in _drivers_without_eee: - return False - return self._eee - - def get_eee(self): - if self._eee_enabled == None: - raise ValueError('Interface does not support changing '\ - 'EEE settings!') - return self._eee_enabled diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py index c3f5bbf47..8d96c863f 100644 --- a/python/vyos/ifconfig/ethernet.py +++ b/python/vyos/ifconfig/ethernet.py @@ -404,34 +404,6 @@ class EthernetIf(Interface): print(f'could not set "{rx_tx}" ring-buffer for {ifname}') return output - def set_eee(self, enable): - """ - Enable/Disable Energy Efficient Ethernet (EEE) settings - - Example: - >>> from vyos.ifconfig import EthernetIf - >>> i = EthernetIf('eth0') - >>> i.set_eee(enable=False) - """ - if not isinstance(enable, bool): - raise ValueError('Value out of range') - - if not self.ethtool.check_eee(): - self._debug_msg(f'NIC driver does not support changing EEE settings!') - return False - - current = self.ethtool.get_eee() - if current != enable: - # Assemble command executed on system. Unfortunately there is no way - # to change this setting via sysfs - cmd = f'ethtool --set-eee {self.ifname} eee ' - cmd += 'on' if enable else 'off' - output, code = self._popen(cmd) - if code: - Warning(f'could not change "{self.ifname}" EEE setting!') - return output - return None - def update(self, config): """ General helper function which works on a dictionary retrived by get_config_dict(). It's main intention is to consolidate the scattered @@ -442,9 +414,6 @@ class EthernetIf(Interface): value = 'off' if 'disable_flow_control' in config else 'on' self.set_flow_control(value) - # Always disable Energy Efficient Ethernet - self.set_eee(False) - # GRO (generic receive offload) self.set_gro(dict_search('offload.gro', config) != None) diff --git a/smoketest/scripts/cli/test_protocols_isis.py b/smoketest/scripts/cli/test_protocols_isis.py index 94f4ec5c9..a7663a720 100755 --- a/smoketest/scripts/cli/test_protocols_isis.py +++ b/smoketest/scripts/cli/test_protocols_isis.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2021-2023 VyOS maintainers and contributors +# Copyright (C) 2021-2024 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -73,6 +73,12 @@ class TestProtocolsISIS(VyOSUnitTestSHIM.TestCase): self.cli_commit() self.isis_base_config() + + self.cli_set(base_path + ['redistribute', 'ipv4', 'connected']) + # verify() - Redistribute level-1 or level-2 should be specified + with self.assertRaises(ConfigSessionError): + self.cli_commit() + self.cli_set(base_path + ['redistribute', 'ipv4', 'connected', 'level-2', 'route-map', route_map]) self.cli_set(base_path + ['log-adjacency-changes']) diff --git a/src/conf_mode/protocols_isis.py b/src/conf_mode/protocols_isis.py index 8d594bb68..6c9925b80 100755 --- a/src/conf_mode/protocols_isis.py +++ b/src/conf_mode/protocols_isis.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2020-2022 VyOS maintainers and contributors +# Copyright (C) 2020-2024 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -155,12 +155,12 @@ def verify(isis): for proto, proto_config in isis['redistribute'][afi].items(): if 'level_1' not in proto_config and 'level_2' not in proto_config: raise ConfigError(f'Redistribute level-1 or level-2 should be specified in ' \ - f'"protocols isis {process} redistribute {afi} {proto}"!') + f'"protocols isis redistribute {afi} {proto}"!') for redistr_level, redistr_config in proto_config.items(): if proc_level and proc_level != 'level_1_2' and proc_level != redistr_level: - raise ConfigError(f'"protocols isis {process} redistribute {afi} {proto} {redistr_level}" ' \ - f'can not be used with \"protocols isis {process} level {proc_level}\"') + raise ConfigError(f'"protocols isis redistribute {afi} {proto} {redistr_level}" ' \ + f'can not be used with \"protocols isis level {proc_level}\"!') # Segment routing checks if dict_search('segment_routing.global_block', isis): @@ -220,8 +220,8 @@ def verify(isis): if ("explicit_null" in prefix_config['index']) and ("no_php_flag" in prefix_config['index']): raise ConfigError(f'Segment routing prefix {prefix} cannot have both explicit-null '\ f'and no-php-flag configured at the same time.') - - # Check for index ranges being larger than the segment routing global block + + # Check for index ranges being larger than the segment routing global block if dict_search('segment_routing.global_block', isis): g_high_label_value = dict_search('segment_routing.global_block.high_label_value', isis) g_low_label_value = dict_search('segment_routing.global_block.low_label_value', isis) @@ -233,7 +233,7 @@ def verify(isis): if int(index_size) > int(g_label_difference): raise ConfigError(f'Segment routing prefix {prefix} cannot have an '\ f'index base size larger than the SRGB label base.') - + # Check for LFA tiebreaker index duplication if dict_search('fast_reroute.lfa.local.tiebreaker', isis): comparison_dictionary = {} @@ -311,4 +311,4 @@ if __name__ == '__main__': apply(c) except ConfigError as e: print(e) - exit(1)
\ No newline at end of file + exit(1) diff --git a/src/migration-scripts/policy/3-to-4 b/src/migration-scripts/policy/3-to-4 index 1ebb248b0..476fa3af2 100755 --- a/src/migration-scripts/policy/3-to-4 +++ b/src/migration-scripts/policy/3-to-4 @@ -51,7 +51,7 @@ def community_migrate(config: ConfigTree, rule: list[str]) -> bool: :rtype: bool """ community_list = list((config.return_value(rule)).split(" ")) - + config.delete(rule) if 'none' in community_list: config.set(rule + ['none']) return False @@ -61,10 +61,8 @@ def community_migrate(config: ConfigTree, rule: list[str]) -> bool: community_action = 'add' community_list.remove('additive') for community in community_list: - if len(community): - config.set(rule + [community_action], value=community, - replace=False) - config.delete(rule) + config.set(rule + [community_action], value=community, + replace=False) if community_action == 'replace': return False else: diff --git a/src/op_mode/dhcp.py b/src/op_mode/dhcp.py index d6b8aa0b8..b1fa6b918 100755 --- a/src/op_mode/dhcp.py +++ b/src/op_mode/dhcp.py @@ -79,8 +79,7 @@ def _get_raw_server_leases(family='inet', pool=None, sorted=None, state=[], orig """ lease_file = '/config/dhcpdv6.leases' if family == 'inet6' else '/config/dhcpd.leases' data = [] - leases = IscDhcpLeases(lease_file).get() - + leases = IscDhcpLeases(lease_file).get(include_backups=True) if pool is None: pool = _get_dhcp_pools(family=family) aux = False |