From 109dbf9789bdc0b1e35b2b5ebd2fd0ce2a1ebe4a Mon Sep 17 00:00:00 2001 From: Jernej Jakob Date: Fri, 1 May 2020 17:36:47 +0200 Subject: ifconfig: T2241: fix section _basename vlan stripping Previously the function returned the correct basename only for vif interfaces as it stopped at the 2nd dot. If we had a vif-s vif-c interface 'eth0.1.2' it would return 'eth0.'. It is now fixed to strip both vif-s and vif-c if 'vlan=True' (default). --- python/vyos/ifconfig/section.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/vyos/ifconfig/section.py') diff --git a/python/vyos/ifconfig/section.py b/python/vyos/ifconfig/section.py index 092236fef..2d77c42cc 100644 --- a/python/vyos/ifconfig/section.py +++ b/python/vyos/ifconfig/section.py @@ -54,7 +54,7 @@ class Section: name = name.rstrip('0123456789') name = name.rstrip('.') if vlan: - name = name.rstrip('0123456789') + name = name.rstrip('0123456789.') return name @classmethod -- cgit v1.2.3 From 6f784231283ec3a63335145e914f2b15e28795dc Mon Sep 17 00:00:00 2001 From: Jernej Jakob Date: Fri, 1 May 2020 17:40:58 +0200 Subject: ifconfig: section: T2241: add get_config_path function Add a function that converts an interface name to its config path. For example: 'eth0.1.2' -> 'ethernet eth0 vif-s 1 vif-c 2' --- python/vyos/ifconfig/section.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'python/vyos/ifconfig/section.py') diff --git a/python/vyos/ifconfig/section.py b/python/vyos/ifconfig/section.py index 2d77c42cc..926c22e8a 100644 --- a/python/vyos/ifconfig/section.py +++ b/python/vyos/ifconfig/section.py @@ -137,3 +137,22 @@ class Section: eth, lo, vxlan, dum, ... """ return list(cls._prefixes.keys()) + + @classmethod + def get_config_path(cls, name): + """ + get config path to interface with .vif or .vif-s.vif-c + example: eth0.1.2 -> 'ethernet eth0 vif-s 1 vif-c 2' + Returns False if interface name is invalid (not found in sections) + """ + sect = cls.section(name) + if sect: + splinterface = name.split('.') + intfpath = f'{sect} {splinterface[0]}' + if len(splinterface) == 2: + intfpath += f' vif {splinterface[1]}' + elif len(splinterface) == 3: + intfpath += f' vif-s {splinterface[1]} vif-c {splinterface[2]}' + return intfpath + else: + return False -- cgit v1.2.3