summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig/vxlan.py
diff options
context:
space:
mode:
authorMichael Petö <michael@petoe.me>2020-03-17 18:36:55 +0100
committerGitHub <noreply@github.com>2020-03-17 18:36:55 +0100
commit8f56d13e11eb98497d7d48bdd6ced465d88bb591 (patch)
tree849476f8e985e195ed7413e9c3b35851ab0418cd /python/vyos/ifconfig/vxlan.py
parentc488ddc235467a920381c9cb6ec71f0826a55b32 (diff)
downloadvyos-1x-8f56d13e11eb98497d7d48bdd6ced465d88bb591.tar.gz
vyos-1x-8f56d13e11eb98497d7d48bdd6ced465d88bb591.zip
vxlan: T2134: fix NameError: name 'config' is not defined
Diffstat (limited to 'python/vyos/ifconfig/vxlan.py')
-rw-r--r--python/vyos/ifconfig/vxlan.py29
1 files 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 <http://www.gnu.org/licenses/>.
-
+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