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

man page cleanup + cleanup + minor fixes

Ticket: CM-1438
Reviewed By:
Testing Done: Tested ifupdown sanity
This commit is contained in:
roopa
2014-04-25 16:09:14 -07:00
parent 07a8db37f9
commit d40e96ee4e
7 changed files with 137 additions and 87 deletions

View 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) (cd /usr/share/man/man8/ && ln -sf /usr/share/man/man8/ifup.8.gz ifdown.8.gz)
mkdir -p /etc/network/interfaces.d/
;; ;;
purge) purge)

View File

@@ -12,28 +12,40 @@ query network interface configuration
:Version: 0.1 :Version: 0.1
:Manual section: 8 :Manual section: 8
NAME
====
**ifquery** - query interface configuration
SYNOPSIS SYNOPSIS
======== ========
ifquery [-h] [-a] [-v] [-d] [--allow CLASS] [--with-depends]
[-X EXCLUDEPATS] [-r | -c | --raw] **ifquery [-v] [--allow CLASS] [--with-depends] -a|IFACE...**
[--print-dependency {list,dot}] [--syntax-help]
[IFACE [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 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 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 **ifquery** always works on the current **interfaces(5)** file
/etc/network/interfaces. **/etc/network/interfaces**.
OPTIONS OPTIONS
======= =======
positional arguments: 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: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-a, --all process all interfaces marked "auto" -a, --all process all interfaces marked "auto"
@@ -42,9 +54,9 @@ OPTIONS
-d, --debug output debug info -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 is redundant when -a is specified. When '-a' is
specified, interfaces are always executed in specified, interfaces are always executed in
dependency order. dependency order.
@@ -59,9 +71,9 @@ OPTIONS
of an interface. Returns exit code 0 on success and of an interface. Returns exit code 0 on success and
1 on error 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 addon modules and dumps supported syntax from them
if provided by the module. if provided by the module.
@@ -69,39 +81,54 @@ EXAMPLES
======== ========
# dump all or some interfaces config file entries # dump all or some interfaces config file entries
# (pretty prints user provided entries) # (pretty prints user provided entries)
ifquery -a
ifquery br0 **ifquery -a**
**ifquery br0**
# Same as above but dump with dependencies # 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 # Check running state with the config in /etc/network/interfaces
ifquery --check br0
ifquery --check --with-depends br0 **ifquery --check br0**
ifquery --check -a
**ifquery --check --with-depends br0**
**ifquery --check -a**
# dump running state of all interfaces in /etc/network/interfaces format # dump running state of all interfaces in /etc/network/interfaces format
ifquery --running br0
ifquery --running --with-depends br0 **ifquery --running br0**
ifquery --running -a
**ifquery --running --with-depends br0**
**ifquery --running -a**
# print dependency info in list format # 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 # 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. # 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 SEE ALSO
======== ========
ifup(8) ifup(8),
ifdown(8) ifdown(8),
ifreload(8) ifreload(8),
interfaces(5) interfaces(5),
interfaces-addons(5) ifupdownaddons-interfaces(5)

View File

@@ -18,12 +18,12 @@ SYNOPSIS
DESCRIPTION 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 runs ifdown on interfaces that changed in the interfaces file and
subsequently runs ifup on all interfaces. 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 but it skips ifdown for interfaces that did not change in the config
file. file.
@@ -42,16 +42,18 @@ OPTIONS
EXAMPLES EXAMPLES
======== ========
# reload /etc/network/interfaces file # reload all auto interfaces in **interfaces(5)** file
ifreload -a
**ifreload -a**
# reload all interfaces using service command # reload all interfaces using service command
service networking reload
**service networking reload**
SEE ALSO SEE ALSO
======== ========
ifup(8) ifup(8),
ifdown(8) ifdown(8),
ifquery(8) ifquery(8),
interfaces(5) interfaces(5),
interfaces-addons(5) ifupdownaddons-interfaces(5)

View File

@@ -14,8 +14,8 @@ network interface configuration for ifupdown
DESCRIPTION DESCRIPTION
=========== ===========
/etc/network/interfaces contains network interface configuration **/etc/network/interfaces** contains network interface configuration
information for the ifup(8), ifdown(8) and ifquery(8) commands. information for the **ifup(8)**, **ifdown(8)** and **ifquery(8)** commands.
This is where you configure how your system is connected to the network. This is where you configure how your system is connected to the network.
@@ -26,7 +26,7 @@ DESCRIPTION
a backslash. a backslash.
The file consists of zero or more "iface", "auto", "allow-" 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 auto lo eth0
allow-hotplug eth1 allow-hotplug eth1
@@ -104,6 +104,8 @@ BUILTIN INTERFACES
EXAMPLES EXAMPLES
======== ========
Sample /etc/network/interfaces file::
auto lo auto lo
iface lo iface lo
address 192.168.2.0/24 address 192.168.2.0/24
@@ -118,10 +120,8 @@ EXAMPLES
address 2001:dee:eeee:1::4/128 address 2001:dee:eeee:1::4/128
# source files from a directory /etc/network/interfaces.d # source files from a directory /etc/network/interfaces.d
# /etc/network/interfaces.d/bridge0 /etc/network/interfaces.d/bridge1
source /etc/network/interfaces.d/* source /etc/network/interfaces.d/*
# Using mako style templates # Using mako style templates
% for v in [11,12]: % for v in [11,12]:
auto vlan${v} auto vlan${v}
@@ -129,7 +129,7 @@ EXAMPLES
address 10.20.${v}.3/24 address 10.20.${v}.3/24
% endfor % endfor
For more examples see interfaces-addons(5) For additional syntax and examples see **ifupdownaddons-interfaces(5)**
FILES FILES
===== =====
@@ -137,7 +137,7 @@ FILES
SEE ALSO SEE ALSO
======== ========
interfaces-addons(5) ifupdownaddons-interfaces(5),
ifup(8) ifup(8),
ifquery(8) ifquery(8),
ifreload(8) ifreload(8)

View File

@@ -35,6 +35,7 @@ class networkInterfaces():
self._filestack = [self.interfacesfile] self._filestack = [self.interfacesfile]
self._template_engine = templateEngine(template_engine, self._template_engine = templateEngine(template_engine,
template_lookuppath) template_lookuppath)
self._currentfile_has_template = False
@property @property
def _currentfile(self): def _currentfile(self):
@@ -44,7 +45,7 @@ class networkInterfaces():
return self.interfacesfile return self.interfacesfile
def _parse_error(self, filename, lineno, msg): 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)) self.logger.error('%s: %s' %(filename, msg))
else: else:
self.logger.error('%s: line%d: %s' %(filename, lineno, msg)) self.logger.error('%s: line%d: %s' %(filename, lineno, msg))
@@ -268,11 +269,16 @@ class networkInterfaces():
f = open(interfacesfile) f = open(interfacesfile)
filedata = f.read() filedata = f.read()
f.close() f.close()
self._currentfile_has_template = False
# process line continuations # process line continuations
filedata = ' '.join(d.strip() for d in filedata.split('\\')) filedata = ' '.join(d.strip() for d in filedata.split('\\'))
# run through template engine # run through template engine
try: try:
rendered_filedata = self._template_engine.render(filedata) 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: except Exception, e:
self._parse_error(self._currentfile, -1, self._parse_error(self._currentfile, -1,
'failed to render template (%s). ' %str(e) + 'failed to render template (%s). ' %str(e) +

View File

@@ -1,5 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
import os
import fcntl
class utils(): class utils():
@@ -11,3 +13,14 @@ class utils():
except ImportError: except ImportError:
return None return None
return getattr(module, name) 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

View File

@@ -7,9 +7,9 @@ import argcomplete
import argparse import argparse
import ConfigParser import ConfigParser
import StringIO import StringIO
from ifupdown.ifupdownmain import *
import logging import logging
from ifupdown.ifupdownmain import *
from ifupdown.utils import *
lockfile="/run/network/.lock" lockfile="/run/network/.lock"
configfile="/etc/network/ifupdown2/ifupdown2.conf" configfile="/etc/network/ifupdown2/ifupdown2.conf"
@@ -202,7 +202,7 @@ def update_ifupdown_argparser(argparser):
group.add_argument('-p', '--print-dependency', group.add_argument('-p', '--print-dependency',
dest='printdependency', choices=['list', 'dot'], dest='printdependency', choices=['list', 'dot'],
help='print iface dependency') help='print iface dependency')
group.add_argument('--no-scripts', '--no-addons', group.add_argument('--no-scripts', '--admin-state',
dest='noaddons', action='store_true', dest='noaddons', action='store_true',
help='dont run any addon modules/scripts. Only bring the ' + help='dont run any addon modules/scripts. Only bring the ' +
'interface administratively up/down') 'interface administratively up/down')
@@ -383,16 +383,17 @@ def main(argv):
if __name__ == "__main__": if __name__ == "__main__":
if not os.geteuid() == 0: if not sys.argv[0].endswith('ifquery') and not os.geteuid() == 0:
print 'Error: Must be root to run this command' print 'error: must be root to run this command'
exit(1) exit(1)
""" """
XXX: Cannot use this. A spawned dhclient process can hold the lock #XXX: Cannot use this. A spawned dhclient process can hold the lock
if not utilities.lockFile(lockfile): if not utils.lockFile(lockfile):
print 'Another instance of this program is already running.' print 'Another instance of this program is already running.'
exit(0) exit(0)
""" """
# required during boot # required during boot
os.putenv('PATH', ENVPATH) os.putenv('PATH', ENVPATH)
main(sys.argv) main(sys.argv)