diff options
author | Christian Poessinger <christian@poessinger.com> | 2022-11-24 20:35:31 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2022-11-24 20:35:31 +0100 |
commit | f9a5286f163b27b51eb5e9a801c5d646c07a7990 (patch) | |
tree | 70acf89e4db741e7e9c0dc8b18e49dacfac49a6f | |
parent | 1e6710d8e193cb919b50da336a27378e130c54b0 (diff) | |
download | vyos-1x-f9a5286f163b27b51eb5e9a801c5d646c07a7990.tar.gz vyos-1x-f9a5286f163b27b51eb5e9a801c5d646c07a7990.zip |
veth: T4825: minor improvements on XML peer-name handling
-rw-r--r-- | interface-definitions/interfaces-virtual-ethernet.xml.in | 9 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-virtual-ethernet.py | 23 |
2 files changed, 20 insertions, 12 deletions
diff --git a/interface-definitions/interfaces-virtual-ethernet.xml.in b/interface-definitions/interfaces-virtual-ethernet.xml.in index 3b78b3637..d52e9ef80 100644 --- a/interface-definitions/interfaces-virtual-ethernet.xml.in +++ b/interface-definitions/interfaces-virtual-ethernet.xml.in @@ -4,7 +4,7 @@ <children> <tagNode name="virtual-ethernet" owner="${vyos_conf_scripts_dir}/interfaces-virtual-ethernet.py"> <properties> - <help>Virtual Ethernet Interface (veth)</help> + <help>Virtual Ethernet (veth) Interface</help> <priority>300</priority> <constraint> <regex>veth[0-9]+</regex> @@ -23,6 +23,13 @@ <leafNode name="peer-name"> <properties> <help>Virtual ethernet peer interface name</help> + <completionHelp> + <path>interfaces virtual-ethernet</path> + </completionHelp> + <valueHelp> + <format>txt</format> + <description>Name of peer interface</description> + </valueHelp> <constraint> <regex>veth[0-9]+</regex> </constraint> diff --git a/src/conf_mode/interfaces-virtual-ethernet.py b/src/conf_mode/interfaces-virtual-ethernet.py index 91609ded9..b1819233c 100755 --- a/src/conf_mode/interfaces-virtual-ethernet.py +++ b/src/conf_mode/interfaces-virtual-ethernet.py @@ -28,7 +28,6 @@ from vyos.ifconfig import VethIf airbag.enable() - def get_config(config=None): """ Retrive CLI config as dictionary. Dictionary can never be empty, as at @@ -41,10 +40,12 @@ def get_config(config=None): base = ['interfaces', 'virtual-ethernet'] ifname, veth = get_interface_dict(conf, base) - veth_dict = conf.get_config_dict(base, key_mangling=('-', '_'), - get_first_key=True, - no_tag_node_value_mangle=True) - veth['config_dict'] = veth_dict + # We need to know all other veth related interfaces as veth requires a 1:1 + # mapping for the peer-names. The Linux kernel automatically creates both + # interfaces, the local one and the peer-name, but VyOS also needs a peer + # interfaces configrued on the CLI so we can assign proper IP addresses etc. + veth['other_interfaces'] = conf.get_config_dict(base, key_mangling=('-', '_'), + get_first_key=True, no_tag_node_value_mangle=True) return veth @@ -58,12 +59,13 @@ def verify(veth): verify_address(veth) if 'peer_name' not in veth: - raise ConfigError( - f'Remote peer name must be set for \"{veth["ifname"]}\"!') + raise ConfigError(f'Remote peer name must be set for "{veth["ifname"]}"!') - if veth['peer_name'] not in veth['config_dict'].keys(): - raise ConfigError( - f'Interface \"{veth["peer_name"]}\" is not configured!') + if veth['peer_name'] not in veth['other_interfaces']: + peer_name = veth['peer_name'] + ifname = veth['ifname'] + raise ConfigError(f'Used peer-name "{peer_name}" on interface "{ifname}" ' \ + 'is not configured!') return None @@ -71,7 +73,6 @@ def verify(veth): def generate(peth): return None - def apply(veth): # Check if the Veth interface already exists if 'rebuild_required' in veth or 'deleted' in veth: |