From 8f56d13e11eb98497d7d48bdd6ced465d88bb591 Mon Sep 17 00:00:00 2001 From: Michael Petö Date: Tue, 17 Mar 2020 18:36:55 +0100 Subject: vxlan: T2134: fix NameError: name 'config' is not defined --- python/vyos/ifconfig/vxlan.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/python/vyos/ifconfig/vxlan.py b/python/vyos/ifconfig/vxlan.py index bc2ec508b..86702b2cd 100644 --- a/python/vyos/ifconfig/vxlan.py +++ b/python/vyos/ifconfig/vxlan.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library. If not, see . - +from vyos import ConfigError from vyos.ifconfig.interface import Interface @@ -54,20 +54,23 @@ class VXLANIf(Interface): super().__init__(ifname, **kargs) def _create(self): - # we assume that by default a multicast interface is created - group = 'group {}'.format(self.config['group']) - - # if remote host is specified we ignore the multicast address + cmd = '' if self.config['remote']: - group = 'remote {}'.format(self.config['remote']) - - # an underlay device is not always specified - dev = '' - if self.config['dev']: - dev = 'dev {}'.format(self.config['dev']) + # an underlay device is only mandatory with multicast, not unicast + dev = '' + if self.config['dev']: + dev = 'dev {}'.format(self.config['dev']) + # iproute2 command for unicast + cmd = 'ip link add {ifname} type vxlan id {vni} remote {remote} {dev_optional} dstport {port}'.format( + **self.config, dev_optional=dev) + else: + if not self.config['dev']: + raise ConfigError( + f'VXLAN "{self.config["ifname"]}" is missing mandatory underlay interface for a multicast network.') + # iproute2 command for multicast + cmd = 'ip link add {ifname} type vxlan id {vni} group {group} dev {dev} dstport {port}'.format( + **self.config) - cmd = 'ip link add {ifname} type vxlan id {vni} {group} {dev} dstport {port}'.format( - **config) self._cmd(cmd) @staticmethod -- cgit v1.2.3