diff --git a/addons/loopback.py b/addons/link.py similarity index 59% rename from addons/loopback.py rename to addons/link.py index dd35917..867141d 100644 --- a/addons/loopback.py +++ b/addons/link.py @@ -11,20 +11,25 @@ from ifupdownaddons.modulebase import moduleBase from ifupdownaddons.iproute2 import iproute2 import logging -class loopback(moduleBase): - _modinfo = {'mhelp' : 'configure extra loopback module based on ' + - 'dummy device' } +class link(moduleBase): + _modinfo = {'mhelp' : 'create/configure link types. similar to ip-link', + 'attrs' : { + 'link-type' : + {'help' : 'type of link as in \'ip link\' command.', + 'example' : ['link-type ']}}} def __init__(self, *args, **kargs): moduleBase.__init__(self, *args, **kargs) self.ipcmd = None - def _is_loopback_by_name(self, ifacename): - return 'loop' in ifacename + def _is_my_interface(self, ifaceobj): + if ifaceobj.get_attr_value_first('link-type'): + return True + return False def _up(self, ifaceobj): - if self._is_loopback_by_name(ifaceobj.name): - self.ipcmd.link_create(ifaceobj.name, 'dummy') + self.ipcmd.link_create(ifaceobj.name, + ifaceobj.get_attr_value_first('link-type')) def _down(self, ifaceobj): if not self.PERFMODE and not self.ipcmd.link_exists(ifaceobj.name): @@ -36,7 +41,15 @@ class loopback(moduleBase): def _query_check(self, ifaceobj, ifaceobjcurr): if not self.ipcmd.link_exists(ifaceobj.name): - return + ifaceobjcurr.update_config_with_status('link-type', 'None', 1) + else: + link_type = ifaceobj.get_attr_value_first('link-type') + if self.ipcmd.link_get_kind(ifaceobj.name) == link_type: + ifaceobjcurr.update_config_with_status('link-type', + link_type, 0) + else: + ifaceobjcurr.update_config_with_status('link-type', + link_type, 1) _run_ops = {'pre-up' : _up, 'post-down' : _down, @@ -54,7 +67,7 @@ class loopback(moduleBase): if not op_handler: return if (operation != 'query-running' and - not self._is_loopback_by_name(ifaceobj.name)): + not self._is_my_interface(ifaceobj)): return self._init_command_handlers() if operation == 'query-checkcurr': diff --git a/config/addons.conf b/config/addons.conf index a9dc0ef..864b625 100644 --- a/config/addons.conf +++ b/config/addons.conf @@ -1,4 +1,6 @@ +pre-up,link pre-up,bond +pre-up,clagd pre-up,vlan pre-up,vxlan pre-up,clagd @@ -29,3 +31,4 @@ post-down,vxlan post-down,vlan post-down,bond post-down,usercmds +post-down,link diff --git a/ifupdownaddons/iproute2.py b/ifupdownaddons/iproute2.py index 6e6643e..022fd06 100644 --- a/ifupdownaddons/iproute2.py +++ b/ifupdownaddons/iproute2.py @@ -67,7 +67,11 @@ class iproute2(utilsBase): elif citems[i] == 'link/ether': linkattrs['hwaddress'] = citems[i+1] elif citems[i] == 'vlan' and citems[i+1] == 'id': linkattrs['linkinfo'] = {'vlanid' : citems[i+2]} + linkattrs['kind'] = 'vlan' + elif citems[i] == 'dummy': + linkattrs['kind'] = 'dummy' elif citems[i] == 'vxlan' and citems[i+1] == 'id': + linkattrs['kind'] = 'vxlan' vattrs = {'vxlanid' : citems[i+2], 'svcnode' : [], 'remote' : [], @@ -568,6 +572,9 @@ class iproute2(utilsBase): def link_get_mtu(self, ifacename): return self._cache_get('link', [ifacename, 'mtu']) + def link_get_kind(self, ifacename): + return self._cache_get('link', [ifacename, 'kind']) + def link_get_hwaddress(self, ifacename): address = self._cache_get('link', [ifacename, 'hwaddress']) # newly created logical interface addresses dont end up in the cache diff --git a/setup.py b/setup.py index 5e58357..d98910e 100755 --- a/setup.py +++ b/setup.py @@ -37,8 +37,9 @@ setup(name='ifupdown2', 'addons/bond.py', 'addons/vlan.py', 'addons/mstpctl.py', 'addons/address.py', 'addons/dhcp.py', 'addons/usercmds.py', - 'addons/ethtool.py', 'addons/loopback.py', + 'addons/ethtool.py', 'addons/addressvirtual.py', 'addons/vxlan.py', + 'addons/link.py', 'addons/bridgevlan.py']), ('/var/lib/ifupdownaddons/', ['config/addons.conf']), ('/var/lib/ifupdownaddons/policy.d/', []),