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
'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' :
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 = {
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):
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,
return cur_peers
+ def tunnel_create(self, tunnelname, mode, attrs={}):
+ """ generic link_create function """
+ if self.link_exists(tunnelname):
+ return
+ cmd = 'tunnel add'
+ cmd += ' %s mode %s' %(tunnelname, 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 link_create_vxlan(self, name, vxlanid,
localtunnelip=None,
svcnodeip=None,