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:
1
debian/python-ifupdown2.postinst
vendored
1
debian/python-ifupdown2.postinst
vendored
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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,7 +26,7 @@ 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
|
||||
@@ -104,6 +104,8 @@ BUILTIN INTERFACES
|
||||
|
||||
EXAMPLES
|
||||
========
|
||||
Sample /etc/network/interfaces file::
|
||||
|
||||
auto lo
|
||||
iface lo
|
||||
address 192.168.2.0/24
|
||||
@@ -118,10 +120,8 @@ EXAMPLES
|
||||
address 2001:dee:eeee:1::4/128
|
||||
|
||||
# source files from a directory /etc/network/interfaces.d
|
||||
# /etc/network/interfaces.d/bridge0 /etc/network/interfaces.d/bridge1
|
||||
source /etc/network/interfaces.d/*
|
||||
|
||||
|
||||
# Using mako style templates
|
||||
% for v in [11,12]:
|
||||
auto vlan${v}
|
||||
@@ -129,7 +129,7 @@ EXAMPLES
|
||||
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)
|
||||
|
@@ -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) +
|
||||
|
13
pkg/utils.py
13
pkg/utils.py
@@ -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
|
||||
|
||||
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user