From f71a7461e44a98e862810bed3d0b9d280ee5dae0 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Mon, 23 Mar 2020 02:35:46 +0000 Subject: tunnel: T31: add support for vrf on tunnels --- python/vyos/ifconfig/control.py | 4 ++-- python/vyos/ifconfig/interface.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'python/vyos') diff --git a/python/vyos/ifconfig/control.py b/python/vyos/ifconfig/control.py index 635b626e8..89deba40a 100644 --- a/python/vyos/ifconfig/control.py +++ b/python/vyos/ifconfig/control.py @@ -48,7 +48,7 @@ class Control: """ Using the defined names, set data write to sysfs. """ - if not value: + if not value and not self._command_set[name].get('force', False): return None # the code can pass int as int @@ -108,7 +108,7 @@ class Control: """ Using the defined names, set data write to sysfs. """ - if not value: + if not value and not self._sysfs_set[name].get('force', False): return None # the code can pass int as int diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 21ffa88f6..9de24d729 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -89,7 +89,12 @@ class Interface(Control): 'shellcmd': 'ip link set dev {ifname} master {value}', }, 'del_vrf': { - 'shellcmd': 'ip link set dev {ifname} nomaster {value}', + 'shellcmd': 'ip link set dev {ifname} nomaster', + }, + 'vrf': { + 'force': True, + 'convert': lambda v: f'master {v}' if v else 'nomaster', + 'shellcmd': 'ip link set dev {ifname} {value}', }, } @@ -308,7 +313,7 @@ class Interface(Control): """ self.set_interface('add_vrf', vrf) - def del_vrf(self, vrf): + def del_vrf(self, vrf=''): """ Remove interface from given VRF instance. -- cgit v1.2.3 From 193d0f416807b3eb5980dcf209e93774282b85f3 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Mon, 23 Mar 2020 11:50:22 +0000 Subject: ifconfig: T31: convert all interface to set_vrf api --- python/vyos/ifconfig/interface.py | 25 +++++-------------------- python/vyos/ifconfig_vlan.py | 7 ++----- src/conf_mode/interfaces-bonding.py | 7 ++----- src/conf_mode/interfaces-bridge.py | 7 ++----- src/conf_mode/interfaces-dummy.py | 7 ++----- src/conf_mode/interfaces-ethernet.py | 7 ++----- src/conf_mode/interfaces-pseudo-ethernet.py | 7 ++----- src/conf_mode/interfaces-wireless.py | 7 ++----- 8 files changed, 19 insertions(+), 55 deletions(-) (limited to 'python/vyos') diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 9de24d729..718fe93db 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -85,12 +85,6 @@ class Interface(Control): 'validate': assert_mac, 'shellcmd': 'ip link set dev {ifname} address {value}', }, - 'add_vrf': { - 'shellcmd': 'ip link set dev {ifname} master {value}', - }, - 'del_vrf': { - 'shellcmd': 'ip link set dev {ifname} nomaster', - }, 'vrf': { 'force': True, 'convert': lambda v: f'master {v}' if v else 'nomaster', @@ -303,25 +297,16 @@ class Interface(Control): """ self.set_interface('mac', mac) - def add_vrf(self, vrf): - """ - Add interface to given VRF instance. - - Example: - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').add_vrf('foo') - """ - self.set_interface('add_vrf', vrf) - - def del_vrf(self, vrf=''): + def set_vrf(self, vrf=''): """ - Remove interface from given VRF instance. + Add/Remove interface from given VRF instance. Example: >>> from vyos.ifconfig import Interface - >>> Interface('eth0').del_vrf('foo') + >>> Interface('eth0').set_vrf('foo') + >>> Interface('eth0').set_vrf() """ - self.set_interface('del_vrf', vrf) + self.set_interface('vrf', vrf) def set_arp_cache_tmo(self, tmo): """ diff --git a/python/vyos/ifconfig_vlan.py b/python/vyos/ifconfig_vlan.py index 1d57283ac..fe94a5af4 100644 --- a/python/vyos/ifconfig_vlan.py +++ b/python/vyos/ifconfig_vlan.py @@ -68,11 +68,8 @@ def apply_vlan_config(vlan, config): # Maximum Transmission Unit (MTU) vlan.set_mtu(config['mtu']) - # assign to VRF - if config['vrf']: - vlan.add_vrf(config['vrf']) - else: - vlan.del_vrf(config['vrf']) + # assign/remove VRF + vlan.set_vrf(config['vrf']) # Change VLAN interface MAC address if config['mac']: diff --git a/src/conf_mode/interfaces-bonding.py b/src/conf_mode/interfaces-bonding.py index a75beabd1..03df6e16a 100755 --- a/src/conf_mode/interfaces-bonding.py +++ b/src/conf_mode/interfaces-bonding.py @@ -461,11 +461,8 @@ def apply(bond): for addr in bond['address']: b.add_addr(addr) - # assign to VRF - if bond['vrf']: - b.add_vrf(bond['vrf']) - else: - b.del_vrf(bond['vrf']) + # assign/remove VRF + b.set_vrf(bond['vrf']) # remove no longer required service VLAN interfaces (vif-s) for vif_s in bond['vif_s_remove']: diff --git a/src/conf_mode/interfaces-bridge.py b/src/conf_mode/interfaces-bridge.py index f189ce36d..f8f20bf5c 100755 --- a/src/conf_mode/interfaces-bridge.py +++ b/src/conf_mode/interfaces-bridge.py @@ -295,11 +295,8 @@ def apply(bridge): # store DHCPv6 config dictionary - used later on when addresses are aquired br.set_dhcpv6_options(opt) - # assign to VRF - if bridge['vrf']: - br.add_vrf(bridge['vrf']) - else: - br.del_vrf(bridge['vrf']) + # assign/remove VRF + br.set_vrf(bridge['vrf']) # Change interface MAC address if bridge['mac']: diff --git a/src/conf_mode/interfaces-dummy.py b/src/conf_mode/interfaces-dummy.py index 10cae5d7d..bf55b13ec 100755 --- a/src/conf_mode/interfaces-dummy.py +++ b/src/conf_mode/interfaces-dummy.py @@ -105,11 +105,8 @@ def apply(dummy): for addr in dummy['address']: d.add_addr(addr) - # assign to VRF - if dummy['vrf']: - d.add_vrf(dummy['vrf']) - else: - d.del_vrf(dummy['vrf']) + # assign/remove VRF + d.set_vrf(dummy['vrf']) # disable interface on demand if dummy['disable']: diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py index ba3a5e8c8..2f5d796b4 100755 --- a/src/conf_mode/interfaces-ethernet.py +++ b/src/conf_mode/interfaces-ethernet.py @@ -369,11 +369,8 @@ def apply(eth): for addr in eth['address']: e.add_addr(addr) - # assign to VRF - if eth['vrf']: - e.add_vrf(eth['vrf']) - else: - e.del_vrf(eth['vrf']) + # assign/remove VRF + e.set_vrf(eth['vrf']) # remove no longer required service VLAN interfaces (vif-s) for vif_s in eth['vif_s_remove']: diff --git a/src/conf_mode/interfaces-pseudo-ethernet.py b/src/conf_mode/interfaces-pseudo-ethernet.py index 989b1432b..0afae8388 100755 --- a/src/conf_mode/interfaces-pseudo-ethernet.py +++ b/src/conf_mode/interfaces-pseudo-ethernet.py @@ -297,11 +297,8 @@ def apply(peth): # Enable private VLAN proxy ARP on this interface p.set_proxy_arp_pvlan(peth['ip_proxy_arp_pvlan']) - # assign to VRF - if peth['vrf']: - p.add_vrf(peth['vrf']) - else: - p.del_vrf(peth['vrf']) + # assign/remove VRF + p.set_vrf(peth['vrf']) # Change interface MAC address if peth['mac']: diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py index 40d8912cc..59fb21125 100755 --- a/src/conf_mode/interfaces-wireless.py +++ b/src/conf_mode/interfaces-wireless.py @@ -1443,11 +1443,8 @@ def apply(wifi): # ignore link state changes w.set_link_detect(wifi['disable_link_detect']) - # assign to VRF - if wifi['vrf']: - w.add_vrf(wifi['vrf']) - else: - w.del_vrf(wifi['vrf']) + # assign/remove VRF + w.set_vrf(wifi['vrf']) # Change interface MAC address - re-set to real hardware address (hw-id) # if custom mac is removed -- cgit v1.2.3