]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
ifupdown: fixes to make addon scripts work via special config options
authorRoopa Prabhu <roopa@cumulusnetworks.com>
Mon, 11 Jul 2016 05:48:42 +0000 (22:48 -0700)
committerJulien Fortin <julien@cumulusnetworks.com>
Fri, 15 Jul 2016 12:13:28 +0000 (13:13 +0100)
ifupdown2 can invoke scripts under /etc/network/if-*.d/*
in the required order with the required environment variables.
This patch includes fixes to execute these scripts.

The following attributes in /etc/network/ifupdown2/ifupdown.conf
can influence the execution behaviour of python-addon modules
and /etc/network/if-*.d/*

<ifupdown.conf>
addon_syntax_check=0

addon_scripts_support=1

addon_python_modules_support=1
</ifupdown.conf>

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
config/ifupdown2.conf
ifupdown/iface.py
ifupdown/ifupdownmain.py

index 13cbbdc793c234b6d73ac761ab776569d223f522..0f9794646ab3a02257f851673cec5c69517f23bf 100644 (file)
@@ -18,9 +18,24 @@ default_interfaces_configfile=/etc/network/interfaces
 # reduce security issues (due to the pre- and post- commands)
 disable_cli_interfacesfile=0
 
-# Support /etc/network/if-*/ scripts
+
+# enable addon module syntax check:
+# Python addon modules register dictionary of supported attributes.
+# The syntax checker in ifupdown2 uses this dictionary for syntax
+# checks in the interfaces file. This works well, when only python modules
+# are used. But when a mix of scripts and modules are used (which is the
+# default case), you may get false warnings for attributes supported
+# by scripts
+addon_syntax_check=1
+
+# Support executing of ifupdown style scripts.
+# Note that by default python addon modules override scripts with the same
+# name
 addon_scripts_support=0
 
+# enable python addons
+addon_python_modules_support=1
+
 # By default ifupdown2 only supports a single vlan filtering bridge
 # on the system. Set this flag to 1 to support multiple vlan
 # filtering bridges
index 3c707618e4dcbfb4fa9f2d24d68771fdaae827fd..9dd5e14c3bf931468eba5e7125d8587509a5e229 100644 (file)
@@ -483,7 +483,6 @@ class iface():
                 return None
         return None
 
-    @property
     def get_env(self):
         """ get shell environment variables the interface must execute in """
         if not self.env:
@@ -498,10 +497,9 @@ class iface():
         config = self.config
         env['IFACE'] = self.name
         for attr, attr_value in config.items():
-            attr_env_name = 'IF_%s' %attr.upper()
+            attr_env_name = 'IF_%s' %attr.upper().replace("-", "_")
             env[attr_env_name] = attr_value[0]
-        if env:
-            self.env = env
+        self.env = env
 
     def update_config(self, attr_name, attr_value):
         """ add attribute name and value to the interface config """
index c9f8d33eb588ff34d44b14912af690fcb9206a90..ed9ad53d15661e98dc836e59d2aceb4f6ca5f358 100644 (file)
@@ -220,9 +220,10 @@ class ifupdownMain(ifupdownBase):
         self.pp = pprint.PrettyPrinter(indent=4)
         self.modules = OrderedDict({})
         self.module_attrs = {}
-        
-        self.load_addon_modules(self.addon_modules_dir)
-        if self.flags.COMPAT_EXEC_SCRIPTS:
+      
+        if self.config.get('addon_python_modules_support', '1') == '1':
+            self.load_addon_modules(self.addon_modules_dir)
+        if self.config.get('addon_scripts_support', '0') == '1':
             self.load_scripts(self.scripts_dir)
         self.dependency_graph = OrderedDict({})
 
@@ -767,9 +768,10 @@ class ifupdownMain(ifupdownBase):
             nifaces.subscribe('iface_found', self._save_iface_squash)
         else:
             nifaces.subscribe('iface_found', self._save_iface)
-        nifaces.subscribe('validateifaceattr',
-                          self._iface_configattr_syntax_checker)
-        nifaces.subscribe('validateifaceobj', self._ifaceobj_syntax_checker)
+        if self.config.get('addon_syntax_check', '1') == '1':
+            nifaces.subscribe('validateifaceattr',
+                              self._iface_configattr_syntax_checker)
+            nifaces.subscribe('validateifaceobj', self._ifaceobj_syntax_checker)
         nifaces.load()
         if nifaces.errors or nifaces.warns:
             ret = False
@@ -1018,9 +1020,9 @@ class ifupdownMain(ifupdownBase):
 
     def _compat_conv_op_to_mode(self, op):
         """ Returns old op name to work with existing scripts """
-        if op == 'pre-up':
+        if 'up' in op:
             return 'start'
-        elif op == 'pre-down':
+        elif 'down' in op:
             return 'stop'
         else:
             return op
@@ -1031,14 +1033,18 @@ class ifupdownMain(ifupdownBase):
         """
 
         cenv = None
-        iface_env = ifaceobj.env
+        iface_env = ifaceobj.get_env()
         if iface_env:
             cenv = os.environ
             if cenv:
                 cenv.update(iface_env)
             else:
                 cenv = iface_env
-            cenv['MODE'] = self._compat_conv_op_to_mode(op)
+        else:
+            cenv = {}
+        cenv['MODE'] = self._compat_conv_op_to_mode(op)
+        cenv['PHASE'] = op
+
         return cenv
 
     def _save_state(self):