]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
man page cleanup + cleanup + minor fixes
authorroopa <roopa@cumulusnetworks.com>
Fri, 25 Apr 2014 23:09:14 +0000 (16:09 -0700)
committerroopa <roopa@cumulusnetworks.com>
Fri, 25 Apr 2014 23:09:14 +0000 (16:09 -0700)
Ticket: CM-1438
Reviewed By:
Testing Done: Tested ifupdown sanity

debian/python-ifupdown2.postinst
man.rst/ifquery.8.rst
man.rst/ifreload.8.rst
man.rst/interfaces.5.rst
pkg/networkinterfaces.py
pkg/utils.py
sbin/ifupdown

index 5b397c1a2092dfde50ef5a14e32fffd7849c56fd..2ded2b733b4cf576bc46dd9d4e395f202c871bfd 100644 (file)
@@ -55,6 +55,7 @@ case "$1" in
 
         (cd /usr/share/man/man8/ && ln -sf /usr/share/man/man8/ifup.8.gz ifdown.8.gz)
 
+        mkdir -p /etc/network/interfaces.d/
         ;;
 
   purge)
index 6cb71650bfb786bd58f5133ffc561db5189b525b..c5850b88c8ed9e31a0294d6781425e88d613ee24 100644 (file)
@@ -12,28 +12,40 @@ query network interface configuration
 :Version: 0.1
 :Manual section: 8
 
+NAME
+====
+    **ifquery** - query interface configuration
+
 SYNOPSIS
 ========
-    ifquery [-h] [-a] [-v] [-d] [--allow CLASS] [--with-depends]
-            [-X EXCLUDEPATS] [-r | -c | --raw]
-            [--print-dependency {list,dot}] [--syntax-help]
-            [IFACE [IFACE ...]]
+
+    **ifquery [-v] [--allow CLASS] [--with-depends] -a|IFACE...**
+
+    **ifquery [-v] [-r|--running] [--allow CLASS] [--with-depends] -a|IFACE...**
+
+    **ifquery [-v] [-c|--check] [--allow CLASS] [--with-depends] -a|IFACE...**
+
+    **ifquery [-v] [-p|--print-dependency {list,dot}] [--allow CLASS] [--with-depends] -a|IFACE...**
+
+    **ifquery [-v] -s|--syntax-help**
 
 DESCRIPTION
 ===========
-    ifquery can be used to parse interface configuration file, dump
+    **ifquery** can be used to parse interface configuration file, query
     running state or check running state of the interface with configuration
-    in /etc/network/interfaces file.
+    in **/etc/network/interfaces** file.
 
-    ifquery always works on the current interfaces(5) file
-    /etc/network/interfaces.
+    **ifquery** always works on the current **interfaces(5)** file
+    **/etc/network/interfaces**.
 
 OPTIONS
 =======
     positional arguments:
-    IFACE                 interface list separated by spaces. IFACE list and '-a' argument are mutually exclusive.
+
+    **IFACE**   interface list separated by spaces. **IFACE** list and **'-a'** argument are mutually exclusive.
 
     optional arguments:
+
     -h, --help            show this help message and exit
 
     -a, --all             process all interfaces marked "auto"
@@ -42,9 +54,9 @@ OPTIONS
 
     -d, --debug           output debug info
 
-    --allow CLASS         ignore non-"allow-CLASS" interfaces
+    -l, --allow CLASS     ignore non-"allow-CLASS" interfaces
 
-    --with-depends        run with all dependent interfaces. This option
+    -w, --with-depends    run with all dependent interfaces. This option
                           is redundant when -a is specified. When '-a' is
                           specified, interfaces are always executed in
                           dependency order.
@@ -59,9 +71,9 @@ OPTIONS
                           of an interface. Returns exit code 0 on success and
                           1 on error
 
-    --print-dependency {list,dot} print iface dependency in list or dot format.
+    -p, --print-dependency {list,dot} print iface dependency in list or dot format
 
-    --syntax-help         print supported interface config syntax. Scans all
+    -s, --syntax-help     print supported interface config syntax. Scans all
                           addon modules and dumps supported syntax from them
                           if provided by the module.
 
@@ -69,39 +81,54 @@ EXAMPLES
 ========
     # dump all or some interfaces config file entries
     # (pretty prints user provided entries)
-    ifquery -a
-    ifquery br0 
+
+        **ifquery -a**
+
+        **ifquery br0**
 
     # Same as above but dump with dependencies
-    ifquery br0 --with-depends
+
+        **ifquery br0 --with-depends**
 
     # Check running state with the config in /etc/network/interfaces
-    ifquery --check br0
-    ifquery --check --with-depends br0 
-    ifquery --check -a         
+
+        **ifquery --check br0**
+
+        **ifquery --check --with-depends br0**
+
+        **ifquery --check -a** 
 
     # dump running state of all interfaces in /etc/network/interfaces format
-    ifquery --running br0
-    ifquery --running --with-depends br0
-    ifquery --running -a
+
+        **ifquery --running br0**
+
+        **ifquery --running --with-depends br0**
+
+        **ifquery --running -a**
 
     # print dependency info in list format
-    ifquery --print-dependency=list -a
-    ifquery --print-dependency=list  br2000
+
+        **ifquery --print-dependency=list -a**
+
+        **ifquery --print-dependency=list  br2000**
 
     # print dependency info in dot format
-    ifquery --print-dependency=dot -a
-    ifquery --print-dependency=dot br2000
+
+        **ifquery --print-dependency=dot -a**
+
+        **ifquery --print-dependency=dot br2000**
 
     # Create an image (png) from the dot format.
-    ifquery --print-dependency=dot -a > interfaces.dot
-    dot -Tpng interfaces.dot > interfaces.png
+
+        **ifquery --print-dependency=dot -a > interfaces.dot**
+
+        **dot -Tpng interfaces.dot > interfaces.png**
 
 
 SEE ALSO
 ========
-    ifup(8)
-    ifdown(8)
-    ifreload(8)
-    interfaces(5)
-    interfaces-addons(5)
+    ifup(8),
+    ifdown(8),
+    ifreload(8),
+    interfaces(5),
+    ifupdownaddons-interfaces(5)
index 3402eab216a7ab0d3df7562e7f610b002b1260a6..3945f81081af61d459914398bdd308ee9fcd21e9 100644 (file)
@@ -18,12 +18,12 @@ SYNOPSIS
 
 DESCRIPTION
 ===========
-    reloads network interfaces(5) file /etc/network/interfaces.
+    reloads network **interfaces(5)** file **/etc/network/interfaces**.
 
     runs ifdown on interfaces that changed in the interfaces file and
     subsequently runs ifup on all interfaces.
 
-    ifreload is equivalent to ``ifdown -a`` followed by ``ifup -a``
+    ifreload is equivalent to **ifdown -a** followed by **ifup -a**
     but it skips ifdown for interfaces that did not change in the config
     file.
 
@@ -42,16 +42,18 @@ OPTIONS
 
 EXAMPLES
 ========
-    # reload /etc/network/interfaces file
-    ifreload -a
+    # reload all auto interfaces in **interfaces(5)** file
+
+    **ifreload -a**
 
     # reload all interfaces using service command
-    service networking reload
+
+    **service networking reload**
 
 SEE ALSO
 ========
-    ifup(8)
-    ifdown(8)
-    ifquery(8)
-    interfaces(5)
-    interfaces-addons(5)
+    ifup(8),
+    ifdown(8),
+    ifquery(8),
+    interfaces(5),
+    ifupdownaddons-interfaces(5)
index 2317b322055d02f6558e6dfeffd7ec835dc42aa5..f21dcfd3c25cd6acf8c05623cb89560d247f4b47 100644 (file)
@@ -14,8 +14,8 @@ network interface configuration for ifupdown
 
 DESCRIPTION
 ===========
-    /etc/network/interfaces contains network interface configuration
-    information for the ifup(8), ifdown(8) and ifquery(8) commands.
+    **/etc/network/interfaces** contains network interface configuration
+    information for the **ifup(8)**, **ifdown(8)** and **ifquery(8)** commands.
 
     This is where you configure how your system is connected to the network.
 
@@ -26,22 +26,22 @@ DESCRIPTION
     a backslash.
 
     The file consists of zero or more "iface", "auto",  "allow-"
-    and "source" stanzas. Here is an example.
+    and "source" stanzas. Here is an example::
 
-    auto lo eth0
-    allow-hotplug eth1
+        auto lo eth0
+        allow-hotplug eth1
 
-    iface lo inet loopback
+        iface lo inet loopback
 
-    source /etc/network/interfaces.d/machine-dependent
+        source /etc/network/interfaces.d/machine-dependent
 
-    iface eth0-home inet static
-        address 192.168.1.1/24
-        up flush-mail
+        iface eth0-home inet static
+            address 192.168.1.1/24
+            up flush-mail
 
-    iface eth0-work inet dhcp
-
-    iface eth1 inet dhcp
+        iface eth0-work inet dhcp
+    
+        iface eth1 inet dhcp
 
     Lines beginning with the word "auto" are used to identify the physical
     interfaces to be brought up when ifup is run with the -a option.
@@ -104,32 +104,32 @@ BUILTIN INTERFACES
 
 EXAMPLES
 ========
-    auto lo
-    iface lo
-    address 192.168.2.0/24
-    address 2001:dee:eeee:1::4/128
+    Sample /etc/network/interfaces file::
 
-    auto eth0
-    iface eth0 inet dhcp
+        auto lo
+        iface lo
+            address 192.168.2.0/24
+            address 2001:dee:eeee:1::4/128
 
-    auto eth1
-    iface eth1 inet manual
-    address 192.168.2.0/24
-    address 2001:dee:eeee:1::4/128
+        auto eth0
+        iface eth0 inet dhcp
 
-    # source files from a directory /etc/network/interfaces.d
-    # /etc/network/interfaces.d/bridge0  /etc/network/interfaces.d/bridge1
-    source /etc/network/interfaces.d/*
+        auto eth1
+        iface eth1 inet manual
+            address 192.168.2.0/24
+            address 2001:dee:eeee:1::4/128
 
+        # source files from a directory /etc/network/interfaces.d
+        source /etc/network/interfaces.d/*
 
-    # Using mako style templates
-    % for v in [11,12]:
-    auto vlan${v}
-    iface vlan${v} inet static
-    address 10.20.${v}.3/24
-    % endfor
+        # Using mako style templates
+        % for v in [11,12]:
+            auto vlan${v}
+            iface vlan${v} inet static
+                address 10.20.${v}.3/24
+        % endfor
 
-    For more examples see interfaces-addons(5)
+    For additional syntax and examples see **ifupdownaddons-interfaces(5)**
 
 FILES
 =====
@@ -137,7 +137,7 @@ FILES
 
 SEE ALSO
 ========
-    interfaces-addons(5)
-    ifup(8)
-    ifquery(8)
+    ifupdownaddons-interfaces(5),
+    ifup(8),
+    ifquery(8),
     ifreload(8)
index 1ce59cadda076855b7af1fcc5b828f592a9bce93..4e56d1dd8091063d52f4487c493f101870269e36 100644 (file)
@@ -35,6 +35,7 @@ class networkInterfaces():
         self._filestack = [self.interfacesfile]
         self._template_engine = templateEngine(template_engine,
                                     template_lookuppath)
+        self._currentfile_has_template = False
 
     @property
     def _currentfile(self):
@@ -44,7 +45,7 @@ class networkInterfaces():
             return self.interfacesfile
 
     def _parse_error(self, filename, lineno, msg):
-        if lineno == -1:
+        if lineno == -1 or self._currentfile_has_template:
             self.logger.error('%s: %s' %(filename, msg))
         else:
             self.logger.error('%s: line%d: %s' %(filename, lineno, msg))
@@ -268,11 +269,16 @@ class networkInterfaces():
         f = open(interfacesfile)
         filedata = f.read()
         f.close()
+        self._currentfile_has_template = False
         # process line continuations
         filedata = ' '.join(d.strip() for d in filedata.split('\\'))
         # run through template engine
         try:
             rendered_filedata = self._template_engine.render(filedata)
+            if rendered_filedata is filedata:
+                self._currentfile_has_template = True
+            else:
+                self._currentfile_has_template = False
         except Exception, e:
             self._parse_error(self._currentfile, -1,
                     'failed to render template (%s). ' %str(e) +
index 2b2229f7db337a8083f7638328b6afe7f5985f42..74116d3fe9e834169830d2e6d1e6c311125df5b3 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+import os
+import fcntl
 
 class utils():
 
@@ -11,3 +13,14 @@ class utils():
         except ImportError:
             return None
         return getattr(module, name)
+
+    @classmethod
+    def lockFile(cls, lockfile):
+        try:
+            fp = os.open(lockfile, os.O_CREAT | os.O_TRUNC | os.O_WRONLY)
+            fcntl.flock(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
+        except IOError:
+            return False
+        return True
+
+
index a20ce16bc223119efe1504f5b6687fb362379939..b7c33e3f2aa83fe190fe4b735177aff28b0be06d 100755 (executable)
@@ -7,9 +7,9 @@ import argcomplete
 import argparse
 import ConfigParser
 import StringIO
-from ifupdown.ifupdownmain import *
-
 import logging
+from ifupdown.ifupdownmain import *
+from ifupdown.utils import *
 
 lockfile="/run/network/.lock"
 configfile="/etc/network/ifupdown2/ifupdown2.conf"
@@ -202,7 +202,7 @@ def update_ifupdown_argparser(argparser):
     group.add_argument('-p', '--print-dependency',
                 dest='printdependency', choices=['list', 'dot'],
                 help='print iface dependency')
-    group.add_argument('--no-scripts', '--no-addons',
+    group.add_argument('--no-scripts', '--admin-state',
                 dest='noaddons',  action='store_true',
                 help='dont run any addon modules/scripts. Only bring the ' +
                     'interface administratively up/down')
@@ -383,16 +383,17 @@ def main(argv):
 
 if __name__ == "__main__":
 
-    if not os.geteuid() == 0:
-        print 'Error: Must be root to run this command'
+    if  not sys.argv[0].endswith('ifquery') and not os.geteuid() == 0:
+        print 'error: must be root to run this command'
         exit(1)
 
     """
-    XXX: Cannot use this. A spawned dhclient process can hold the lock
-    if not utilities.lockFile(lockfile):
+    #XXX: Cannot use this. A spawned dhclient process can hold the lock
+    if not utils.lockFile(lockfile):
         print 'Another instance of this program is already running.'
         exit(0)
     """
+
     # required during boot
     os.putenv('PATH', ENVPATH)
     main(sys.argv)