1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

tunnel changes

This commit is contained in:
Sven Auhagen
2018-04-04 19:49:34 +02:00
parent 8a0aa008bb
commit 12425dc496
2 changed files with 53 additions and 3 deletions

View File

@@ -7,6 +7,7 @@
from ifupdown.iface import *
from ifupdownaddons.modulebase import moduleBase
from ifupdownaddons.iproute2 import iproute2
from ifupdown.netlink import netlink
import ifupdown.ifupdownflags as ifupdownflags
import logging
@@ -18,7 +19,7 @@ class tunnel (moduleBase):
'attrs' : {
'mode' :
{ 'help' : 'type of tunnel as in \'ip link\' command.',
'validvals' : ['gre', 'gretap', 'ipip', 'sit'],
'validvals' : ['gre', 'gretap', 'ipip', 'sit', 'vti', 'ip6gre', 'ipip6', 'ip6ip6', 'vti6'],
'required' : True,
'example' : ['mode gre']},
'local' :
@@ -55,6 +56,17 @@ class tunnel (moduleBase):
return True
return False
def _check_settings(self, ifaceobj, attrs):
linkup = self.ipcmd.is_link_up(ifaceobj.name)
try:
if attrs:
self.ipcmd.tunnel_change(ifaceobj.name, attrs)
except:
raise
finally:
if attrs and linkup:
netlink.link_set_updown(ifaceobj.name, 'up')
def _up (self, ifaceobj):
attr_map = {
@@ -75,7 +87,11 @@ class tunnel (moduleBase):
if attr_val != None:
attrs[iproute_attr] = attr_val
self.ipcmd.link_create (ifaceobj.name, mode, attrs)
if not self.ipcmd.link_exists(ifaceobj.name):
self.ipcmd.tunnel_create (ifaceobj.name, mode, attrs)
else:
attrs['mode'] = mode
self._check_settings(ifaceobj, attrs)
def _down (self, ifaceobj):

View File

@@ -103,7 +103,7 @@ class iproute2(utilsBase):
linkattrs['state'] = citems[i + 1]
elif citems[i] == 'link/ether':
linkattrs['hwaddress'] = citems[i + 1]
elif citems[i] in [ 'link/gre', 'link/sit', 'gretap' ]:
elif citems[i] in [ 'link/gre', 'link/ipip', 'link/sit', 'link/gre6', 'link/tunnel6', 'gretap' ]:
linkattrs['kind'] = 'tunnel'
tunattrs = {'mode' : citems[i].split ('/')[-1],
'endpoint' : None,
@@ -757,6 +757,40 @@ class iproute2(utilsBase):
else:
return self._cache_get('link', [ifacename, 'master'])
def tunnel_create(self, tunnelname, mode, attrs={}):
""" generic link_create function """
if self.link_exists(tunnelname):
return
cmd = 'tunnel add'
cmd += ' %s mode %s' %(ifacename, mode)
if attrs:
for k, v in attrs.iteritems():
cmd += ' %s' %k
if v:
cmd += ' %s' %v
if self.ipbatch and not self.ipbatch_pause:
self.add_to_batch(cmd)
else:
utils.exec_command('ip %s' % cmd)
self._cache_update([tunnelname], {})
def tunnel_change(self, tunnelname, attrs={}):
""" tunnel change function """
if not self.link_exists(tunnelname):
return
cmd = 'tunnel change'
cmd += ' %s' %(tunnelname)
if attrs:
for k, v in attrs.iteritems():
cmd += ' %s' %k
if v:
cmd += ' %s' %v
if self.ipbatch and not self.ipbatch_pause:
self.add_to_batch(cmd)
else:
utils.exec_command('ip %s' % cmd)
self._cache_update([tunnelname], {})
def bridge_port_vids_add(self, bridgeportname, vids):
[utils.exec_command('bridge vlan add vid %s dev %s' %
(v, bridgeportname)) for v in vids]