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

Initial import of ifupdown2 sources

This commit is contained in:
Roopa Prabhu
2014-07-20 00:45:04 -07:00
parent de3b811808
commit 2c8c4ce74d
83 changed files with 13320 additions and 0 deletions

153
ifupdown2/docs/Makefile Normal file
View File

@@ -0,0 +1,153 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ifupdown2.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ifupdown2.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/ifupdown2"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ifupdown2"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

View File

@@ -0,0 +1,150 @@
#!/usr/bin/python
import argparse
import sys
import subprocess
""" This script prints to stdout /etc/network/interfaces entries for
requested interfaces.
Currently it supports generation of interfaces(5) section for all
swp interfaces on the system. And also an interface section
for a bridge with all swp ports.
Example use of this script:
generate the swp_defaults file:
(bkup existing /etc/network/interfaces.d/swp_defaults file if one exists)
#generate_interfaces.py -s > /etc/network/interfaces.d/swp_defaults
User -m option if you want the new swp_defaults to be auto merged
with the contents from the old file, use -m option
#generate_interfaces.py -s -m /etc/network/interfaces.d/swp_defaults > /etc/network/interfaces.d/swp_defaults.new
Include the swp_defaults file in /etc/network/interfaces file
(if not already there) using the source command as shown below:
source /etc/network/interfaces.d/swp_defaults
"""
def get_swp_interfaces():
porttab_path = '/var/lib/cumulus/porttab'
ports = []
ptfile = open(porttab_path, 'r')
for line in ptfile.readlines():
line = line.strip()
if '#' in line:
continue
try:
ports.append(line.split()[0])
except ValueError:
continue
return ports
def print_swp_defaults_header():
print '''
# ** This file is autogenerated by /usr/share/doc/python-ifupdown2/generate_interfaces.py **
#
# This is /etc/network/interfaces section for all available swp
# ports on the system.
#
# To include this file in the main /etc/network/interfaces file,
# copy this file under /etc/network/interfaces.d/ and use the
# source line in the /etc/network/interfaces file.
#
# example entry in /etc/network/interfaces:
# source /etc/network/interfaces.d/<filename>
#
# See manpage interfaces(5) for details.
'''
def print_bridge_untagged_defaults_header():
print '''
# ** This file is autogenerated by /usr/share/doc/python-ifupdown2/generate_interfaces.py **
#
# This is /etc/network/interfaces section for a bridge device with all swp
# ports in the system.
#
# To include this file in the main /etc/network/interfaces file,
# copy this file under /etc/network/interfaces.d/ and use the
# source line in the /etc/network/interfaces file as shown below.
# details.
#
# example entry in /etc/network/interfaces:
# source /etc/network/interfaces.d/filename
#
# See manpage interfaces(5) for details
'''
def interfaces_print_swp_default(swp_intf):
outbuf = None
if args.mergefile:
try:
cmd = ['/sbin/ifquery', '%s' %swp_intf, '-i', '%s' %args.mergefile]
outbuf = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except Exception, e:
# no interface found gen latest
pass
if not outbuf:
outbuf = 'auto %s\niface %s\n\n' %(swp_intf, swp_intf)
return outbuf
def interfaces_print_swp_defaults(swp_intfs):
print_swp_defaults_header()
outbuf = ''
for i in swp_intfs:
outbuf += interfaces_print_swp_default(i)
print outbuf
def interfaces_print_bridge_default(swp_intfs):
print_bridge_untagged_defaults_header()
outbuf = 'auto bridge-untagged\n'
outbuf += 'iface bridge-untagged\n'
outbuf += ' bridge-ports \\\n'
linen = 5
ports = ''
for i in range(0, len(swp_intfs), linen):
if ports:
ports += ' \\\n'
ports += ' %s' %(' '.join(swp_intfs[i:i+linen]))
outbuf += ports
print outbuf
def populate_argparser(argparser):
group = argparser.add_mutually_exclusive_group(required=False)
group.add_argument('-s', '--swp-defaults', action='store_true',
dest='swpdefaults', help='generate swp defaults file')
group.add_argument('-b', '--bridge-default', action='store_true',
dest='bridgedefault',
help='generate default untagged bridge')
argparser.add_argument('-m', '--merge', dest='mergefile', help='merge ' +
'new generated iface content with the old one')
argparser = argparse.ArgumentParser(description='ifupdown interfaces file gen helper')
populate_argparser(argparser)
args = argparser.parse_args(sys.argv[1:])
if not args.swpdefaults and not args.bridgedefault:
argparser.print_help()
exit(1)
if args.bridgedefault and args.mergefile:
print 'error: mergefile option currently only supported with -s'
argparser.print_help()
exit(1)
swp_intfs = get_swp_interfaces()
if not swp_intfs:
print 'error: no ports found'
exit(1)
if args.swpdefaults:
interfaces_print_swp_defaults(swp_intfs)
elif args.bridgedefault:
interfaces_print_bridge_default(swp_intfs)
else:
argparser.print_help()

View File

@@ -0,0 +1,74 @@
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
#source /etc/network/interfaces.d/template.bridges
# swp interface
auto swp30
iface swp30
address 12.0.0.4/24
address 12.0.0.6/24
address 2000:1000:1000:1000:3::5/128
mtu 1600
alias "test network"
link-duplex full
link-speed 1000
link-autoneg off
# bond interface
auto bond3
iface bond3 inet static
address 100.0.0.4/16
bond-slaves swp1 swp2
bond-mode 802.3ad
bond-miimon 100
bond-use-carrier 1
bond-lacp-rate 1
bond-min-links 1
bond-xmit_hash_policy layer3+4
# bond interface
auto bond4
iface bond4 inet static
address 100.0.0.6/16
bond-slaves swp3 swp4
bond-mode 802.3ad
bond-miimon 100
bond-use-carrier 1
bond-lacp-rate 1
bond-min-links 1
bond-xmit_hash_policy layer3+4
# bond interface
auto br0
iface br0
address 12.0.0.4/24
address 12.0.0.6/24
address 2000:1000:1000:1000:3::5/128
bridge-ports bond3 bond4 swp5 swp8
bridge-stp on
# vlan interface on bond
auto bond3.2000
iface bond3.2000 inet static
address 100.1.0.4/16
auto bond4.2000
iface bond4.2000 inet static
address 100.1.0.6/16
auto br2000
iface br2000 inet6 static
address 2001:dad:beef::4/64
bridge-ports bond3.2000 bond4.2000 swp5.2000
bridge-stp on
mstpctl-treeprio 61440
mstpctl-portp2p bond3.2000=yes bond4.2000=yes

View File

@@ -0,0 +1,45 @@
#
# This example lists all attributes for bridge configuration.
# The attributes with mstpctl- prefix indicate mstp settings on a bridge.
# The attributes with bridge- prefix indicate bridge stp and igmp attributes.
# Except bridge-ports, none of the other attributes are required. Default
# values are documented in the ifupdown-addons-interfaces(5) man page.
#
auto br-300
iface br-300 inet static
address 12.0.0.3/24
bridge-ports swp13.300 swp14.300
bridge-stp on
mstpctl-maxage 20
mstpctl-fdelay 15
mstpctl-maxhops 20
mstpctl-txholdcount 6
mstpctl-forcevers rstp
mstpctl-portpathcost swp13.300=0 swp14.300=0
mstpctl-portadminedge swp13.300=no swp14.300=no
mstpctl-portautoedge swp13.300=yes swp14.300=yes
mstpctl-portp2p swp13.300=no swp13.300=no
mstpctl-portrestrrole swp13.300=no swp14.300=no
mstpctl-bpduguard swp13.300=no swp14.300=no
mstpctl-portrestrtcn swp13.300=no swp14.300=no
mstpctl-treeprio 32768
mstpctl-treeportprio swp13.300=128
mstpctl-hello 2
mstpctl-portnetwork swp13.300=no
bridge-mclmc 3
bridge-mcrouter 0
bridge-mcsnoop 1
bridge-mcsqc 3
bridge-mcqifaddr 1
bridge-mcquerier 1
bridge-hashel 3
bridge-hashmax 4
bridge-mclmi 3
bridge-mcmi 200
bridge-mcqpi 200
bridge-mcqi 100
bridge-mcqri 20
bridge-mcsqi 50
bridge-portmcrouter swp13.300=0
bridge-portmcfl swp13.300=1

View File

@@ -0,0 +1,33 @@
#
# mako template function to create a bridge
#
# mako defs provide the advantage of declaring predefined functions in
# separate files.
#
# Below is an example that illustrates how to define such functions and use
# them in the /etc/network/interfaces file to create bridges
#
# This file defines a function makebr to create a bridge. The arguments to the
# function are vlan and ip address of the bridge.
#
# The default directory for template functions is
# /etc/network/ifupdown2/templates/. Copy this file under the template
# dir (create the directory if does not exist)
#
# To use this template function in /etc/network/interfaces, add the following
# to the /etc/network/interfaces file:
#
# <%namespace name="bridge" file="/bridge_template"/>
#
# ${bridge.makebr(1096, "10.0.23.2/24")}
# ${bridge.makebr(1097, "10.0.23.3/24")}
#
#
<%def name="makebr(vlan, addr)">
auto br${vlan}
iface br${vlan} inet static
address ${addr}
bridge-ports swp1.${vlan} swp2.${vlan}
bridge-stp on
</%def>

View File

@@ -0,0 +1,24 @@
#
# Example interfaces file using mako templates
#
# The below section can be copied into
# /etc/network/interfaces file
# or
# to a file under /etc/network/interfaces.d/
# and include in the interfaces file using the
# 'source' command.
#
# see manpage interfaces(5) for details
#
#
%for v in range(1000,1100):
auto vlan-${v}
iface vlan-${v} inet static
bridge-ports glob swp1-6.${v}
bridge-stp on
bridge-ageing 200
bridge-maxage 10
bridge-fd 10
%endfor

View File

@@ -0,0 +1,65 @@
Documentation for the Code
**************************
ifupdownmain
============
ifupdownmain is the main ifupdown module.
.. automodule:: ifupdownmain
.. autoclass:: ifupdownMain
:members: up, down, reload, query
iface
=====
.. automodule:: iface
.. autoclass:: iface
:members: state, status, flags, priv_flags, refcnt, lowerifaces, upperifaces, add_to_upperifaces, get_attr_value, get_attr_value_first, get_attr_value_n, update_config, update_config_with_status, get_config_attr_status, compare, dump_raw, dump, dump_pretty
.. autoclass:: ifaceState
.. autoclass:: ifaceStatus
.. autoclass:: ifaceJsonEncoder
scheduler
=========
.. automodule:: scheduler
.. autoclass:: ifaceScheduler
:members: sched_ifaces
.. autoclass:: ifaceSchedulerFlags
networkinterfaces
=================
.. automodule:: networkinterfaces
.. autoclass:: networkInterfaces
:members: load, subscribe
statemanager
============
.. automodule:: statemanager
.. autoclass:: pickling
:members: save, save_obj, load
.. autoclass:: stateManager
:members: read_saved_state, save_state
graph
=====
.. automodule:: graph
.. autoclass:: graph
:members: topological_sort_graphs_all, generate_dots

View File

@@ -0,0 +1,246 @@
# -*- coding: utf-8 -*-
#
# ifupdown2 documentation build configuration file, created by
# sphinx-quickstart on Sun Jul 6 23:49:20 2014.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../../ifupdown'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'ifupdown2'
copyright = u'2014, Roopa Prabhu'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'ifupdown2doc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'ifupdown2.tex', u'ifupdown2 Documentation',
u'Roopa Prabhu', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'ifupdown2', u'ifupdown2 Documentation',
[u'Roopa Prabhu'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'ifupdown2', u'ifupdown2 Documentation',
u'Roopa Prabhu', 'ifupdown2', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'http://docs.python.org/': None}

View File

@@ -0,0 +1,21 @@
Development Corner
==================
getting started
---------------
Unlike original ifupdown, all interface configuration is moved to external
python modules. That includes inet, inet6 and dhcp configurations.
* if you are looking at fixing bugs or adding new features to the ifupdown2
infrastructure package, pls look at the apiref, documentation and code
for python-ifupdown2
* if you are looking at developing a new module, pls look at writing a addon
module in the python-ifupdown2-addons documentation
Apiref
------
.. toctree::
:maxdepth: 2
apiref.rst

View File

@@ -0,0 +1,22 @@
Getting Started
===============
Prerequisites
-------------
* python-ifupdown2 is current only tested on a debian release wheezy or greater
* python-ifupdown2 needs python version 2.6 or greater
* build depends on: python-stdeb (for deb builds), python-docutils (for rst2man)
* depends on python-gvgen package for printing interface graphs (this will be made optional soon)
* optional dependency for template engine: python-mako
Building
--------
git clone <ifupdown2 git url>
cd ifupdown2
./build.sh
Installing
----------
install generated python-ifupdown2-<ver>.deb

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

View File

@@ -0,0 +1,25 @@
.. ifupdown2 documentation master file, created by
sphinx-quickstart on Sun Jul 6 23:49:20 2014.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to ifupdown2's documentation!
=====================================
Contents:
.. toctree::
:maxdepth: 2
intro.rst
gettingstarted.rst
userguide.rst
developmentcorner.rst
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@@ -0,0 +1,20 @@
python-ifupdown2
----------------
The python-ifupdown2 package provides the infrastructure for
parsing /etc/network/interfaces file, loading, scheduling, template parsing,
state management and interface dependency generation of interfaces.
It dynamically loads python modules from /usr/share/ifupdownmodules (provided
by the python-ifupdown2-addons package). To remain compatible with other
packages that depend on ifupdown, it also executes scripts under /etc/network/.
To make the transition smoother, a python module under
/usr/share/ifupdownmodules will override a script by the same name under
/etc/network/.
It publishes an interface object which is passed to all loadble python
modules. For more details on adding a addon module, see the section on
adding python modules.
ifupdown2 module calls all modules for every interface declared in the
/etc/network/interfaces file.

View File

@@ -0,0 +1,447 @@
.. index:: ifupdown
.. _ifupdown:
**********
User Guide
**********
Keep the following points in mind before you start configuring interfaces using
``ifupdown2``:
* IPv4 and IPv6 addresses for an interface can be listed in the same ``iface``
section. For examples, see ``/usr/share/doc/python-ifupdown2/examples/``.
* Do not use a legacy interface alias. They are only supported for backward
compatibility with ``ifupdown``. They do get configured, but ``ifquery`` has
problems recognizing them.
* ``ifupdown`` only understands interfaces that were configured using
``ifupdown``. Any interfaces created with a command other than ``ifupdown``
(like ``brctl``) must be de-configured in the same manner.
* Use globs for port lists wherever applicable. Regular expressions work as well,
however regular expressions require all matching interfaces to be present in
the ``interfaces`` file. And declaring all interfaces in the ``interfaces``
file leads to losing all the advantages that built-in interfaces provide.
* Extensions to ``ifquery`` help with validation and debugging.
* By default, ``ifupdown`` is quiet; use the verbose option ``-v`` when you want
to know what is going on when bringing an interface down or up.
Contents
========
* `Commands`_
* `Man Pages`_
* `Configuration Files`_
* `ifupdown Built-in Interfaces`_
* `ifupdown Interface Dependencies`_
* `Configuring IP Addresses`_
* `Specifying User Commands`_
* `Sourcing Interface File Snippets`_
* `Using Globs for Port Lists`_
* `Using Templates`_
* `Using ifquery to Validate and Debug Interface Configurations`_
* `Useful Links`_
Commands
========
* ifdown
* ifquery
* ifreload
* ifup
Man Pages
=========
* man ifdown(8)
* man ifquery(8)
* man ifreload
* man ifup(8)
* man ifupdown-addons-interfaces(5)
* man interfaces(5)
Configuration Files
===================
* /etc/network/interfaces
ifupdown Built-in Interfaces
============================
``ifupdown`` understands VLAN interfaces and physical interfaces that may appear
as dependents. There is no need to list them unless they need the specific
configuration or they need to match a regular expression used in the
``interfaces`` file. Use globs to avoid limitations with regular expressions.
For example, swp1.100 and swp2.100 below do not need an entry in the
``interfaces`` file::
auto br-100
iface br-100
address 10.0.12.2/24
address 2001:dad:beef::3/64
bridge-ports swp1.100 swp2.100
bridge-stp on
ifupdown Interface Dependencies
===============================
``ifupdown`` understands interface dependency relationships. When ``ifup`` and
``ifdown`` are run with all interfaces, they always run with all interfaces
in dependency order. When run with the interface list on the command line, the
default behavior is to not run with dependents. But if there are any built-in
dependents, they will be brought up or down.
To run with dependents when you specify the interface list, use the
``--with-depends`` option. ``--with-depends`` walks through all dependents
in the dependency tree rooted at the interface you specify. Consider the
following example configuration::
auto bond1
iface bond1
address 100.0.0.2/16
bond-slaves swp29 swp30
bond-mode 802.3ad
bond-miimon 100
bond-use-carrier 1
bond-lacp-rate 1
bond-min-links 1
bond-xmit-hash-policy layer3+4
auto bond2
iface bond2
address 100.0.0.5/16
bond-slaves swp31 swp32
bond-mode 802.3ad
bond-miimon 100
bond-use-carrier 1
bond-lacp-rate 1
bond-min-links 1
bond-xmit-hash-policy layer3+4
auto br2001
iface br2001
address 12.0.1.3/24
bridge-ports bond1.2001 bond2.2001
bridge-stp on
Specifying ``ifup --with-depends br2001`` brings up all dependents: bond1.2001,
bond2.2001, bond1, bond2, bond1.2001, bond2.2001, swp29, swp30, swp31, swp32.
Similarly, specifying ``ifdown --with-depends br2001`` brings down all
dependents: bond1.2001, bond2.2001, bond1, bond2, bond1.2001, bond2.2001, swp29,
swp30, swp31, swp32.
.. warning:: ``ifdown`` always deletes logical interfaces after bringing them
down. Use the ``--admin-state`` option if you only want to administratively
bring the interface up or down. In terms of the above example,
``ifdown br2001`` deletes ``br2001``.
To guide you through which interfaces will be brought down and up, use the
``--print-dependency`` option to get the list of dependents.
Use ``ifup --print-dependency=list -a`` to get the dependency list of all
interfaces::
cumulus@switch:~$ sudo ifup --print-dependency=list -a
lo : None
eth0 : None
bond0 : ['swp25', 'swp26']
bond1 : ['swp29', 'swp30']
bond2 : ['swp31', 'swp32']
br0 : ['bond1', 'bond2']
bond1.2000 : ['bond1']
bond2.2000 : ['bond2']
br2000 : ['bond1.2000', 'bond2.2000']
bond1.2001 : ['bond1']
bond2.2001 : ['bond2']
br2001 : ['bond1.2001', 'bond2.2001']
swp40 : None
swp25 : None
swp26 : None
swp29 : None
swp30 : None
swp31 : None
swp32 : None
To print the dependency list of a single interface, use::
cumulus@switch:~$ sudo ifup --print-dependency=list br2001
br2001 : ['bond1.2001', 'bond2.2001']
bond1.2001 : ['bond1']
bond2.2001 : ['bond2']
bond1 : ['swp29', 'swp30']
bond2 : ['swp31', 'swp32']
swp29 : None
swp30 : None
swp31 : None
swp32 : None
To print the dependency information of an interface in ``dot`` format::
cumulus@switch:~$ sudo ifup --print-dependency=dot br2001
/* Generated by GvGen v.0.9 (http://software.inl.fr/trac/wiki/GvGen) */
digraph G {
compound=true;
node1 [label="br2001"];
node2 [label="bond1.2001"];
node3 [label="bond2.2001"];
node4 [label="bond1"];
node5 [label="bond2"];
node6 [label="swp29"];
node7 [label="swp30"];
node8 [label="swp31"];
node9 [label="swp32"];
node1->node2;
node1->node3;
node2->node4;
node3->node5;
node4->node6;
node4->node7;
node5->node8;
node5->node9;
}
You can use ``dot`` to render the graph on an external system where ``dot`` is
installed.
.. image:: images/interfaces.png
To print the dependency information of the entire ``interfaces`` file::
cumulus@switch:~$ sudo ifup --print-dependency=dot -a >interfaces_all.dot
.. image:: images/interfaces_all.png
:width: 800px
.. note: The '--print-dependency' option is available with the ``ifup``,
``ifdown`` and ``ifquery`` commands.
Configuring IP Addresses
========================
In ``/etc/network/interfaces``, list all IP addresses as shown below under the
``iface`` section (see ``man interfaces`` for more information)::
auto swp1
iface swp1
address 12.0.0.1/30
address 12.0.0.2/30
The address method and address family are not mandatory. They default to
``inet``/``inet6`` and ``static`` by default, but ``inet``/``inet6`` **must** be
specified if you need to specify ``dhcp`` or ``loopback``.
You can specify both IPv4 and IPv6 addresses under the same ``iface`` section::
auto swp1
iface swp1
address 12.0.0.1/30
address 12.0.0.2/30
address 2001:dee:eeef:2::1/64
Specifying User Commands
========================
You can specify additional user commands in the ``interfaces`` file. As shown in
the example below, the interface stanzas in ``/etc/network/interfaces`` can have
a command that runs at pre-up, up, post-up, pre-down, down, and post-down::
auto swp1
iface swp1
address 12.0.0.1/30
up /sbin/foo bar
Any valid command can be hooked in the sequencing of bringing an interface up or
down, although commands should be limited in scope to network-related commands
associated with the particular interface.
For example, it wouldn't make sense to install some Debian package on ``ifup``
of swp1, even though that is technically possible. See ``man interfaces`` for
more details.
Sourcing Interface File Snippets
================================
Sourcing interface files helps organize and manage the ``interfaces(5)`` file.
For example::
cumulus@switch:~$ cat /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
source /etc/network/interfaces.d/bond0
The contents of the sourced file used above are::
cumulus@switch:~$ cat /etc/network/interfaces.d/bond0
auto bond0
iface bond0
address 14.0.0.9/30
address 2001:ded:beef:2::1/64
bond-slaves swp25 swp26
bond-mode 802.3ad
bond-miimon 100
bond-use-carrier 1
bond-lacp-rate 1
bond-min-links 1
bond-xmit-hash-policy layer3+4
Using Globs for Port Lists
==========================
Some modules support globs to describe port lists. You can use globs to specify
bridge ports and bond slaves::
auto br0
iface br0
bridge-ports glob swp1-6.100
auto br1
iface br1
bridge-ports glob swp7-9.100 swp11.100 glob swp15-18.100
Using Templates
===============
``ifupdown2`` supports Mako-style templates. For more information see
`www.makotemplates.org <http://www.makotemplates.org/>`_. The Mako template
engine is run over the ``interfaces`` file before parsing.
Use the template to declare cookie-cutter bridges in the ``interfaces`` file::
%for v in [11,12]:
auto vlan${v}
iface vlan${v}
address 10.20.${v}.3/24
bridge-ports glob swp19-20.${v}
bridge-stp on
%endfor
And use it to declare addresses in the ``interfaces`` file::
%for i in [1,12]:
auto swp${i}
iface swp${i}
address 10.20.${i}.3/24
Using ifquery to Validate and Debug Interface Configurations
============================================================
You use ``ifquery`` to print parsed ``interfaces`` file entries.
To use ``ifquery`` to pretty print ``iface`` entries from the ``interfaces``
file, run::
cumulus@switch:~$ sudo ifquery bond0
auto bond0
iface bond0
address 14.0.0.9/30
address 2001:ded:beef:2::1/64
bond-slaves swp25 swp26
bond-mode 802.3ad
bond-miimon 100
bond-use-carrier 1
bond-lacp-rate 1
bond-min-links 1
bond-xmit-hash-policy layer3+4
.. Use ``ifquery -a`` to pretty print all ``iface`` entries from the
``interfaces`` file.
Use ``ifquery --check`` to check the current running state of an interface within
the ``interfaces`` file. It returns exit code ``0`` or ``1`` if the configuration
does not match::
cumulus@switch:~$ sudo ifquery --check bond0
iface bond0
bond-mode 802.3ad (✓)
bond-miimon 100 (✓)
bond-use-carrier 1 (✓)
bond-lacp-rate 1 (✓)
bond-min-links 1 (✓)
bond-xmit-hash-policy layer3+4 (✓)
bond-slaves swp25 swp26 (✓)
address 14.0.0.9/30 (✓)
address 2001:ded:beef:2::1/64 (✓)
.. note:: ``ifquery --check`` is an experimental feature.
.. Use ``ifquery --check -a`` to check all interfaces.
Use ``ifquery --running`` to print the running state of interfaces in the
``interfaces`` file format::
cumulus@switch:~$ sudo ifquery --running bond0
auto bond0
iface bond0
bond-xmit-hash-policy layer3+4
bond-miimon 100
bond-lacp-rate 1
bond-min-links 1
bond-slaves swp25 swp26
bond-mode 802.3ad
address 14.0.0.9/30
address 2001:ded:beef:2::1/64
``ifquery --syntax-help`` provides help on all possible attributes supported in
the ``interfaces`` file. For complete syntax on the ``interfaces`` file, see
``man interfaces`` and ``man ifupdown-addons-interfaces``.
``ifquery`` can dump information in JSON format::
cumulus@switch:~$ sudo ifquery --format=json bond0
{
"auto": true,
"config": {
"bond-use-carrier": "1",
"bond-xmit-hash-policy": "layer3+4",
"bond-miimon": "100",
"bond-lacp-rate": "1",
"bond-min-links": "1",
"bond-slaves": "swp25 swp26",
"bond-mode": "802.3ad",
"address": [
"14.0.0.9/30",
"2001:ded:beef:2::1/64"
]
},
"addr_method": null,
"name": "bond0",
"addr_family": null
}
.. By default ``ifquery`` outputs information in the ``interfaces`` format. Some
options do take the ``--format`` option and can output in JSON format.
Useful Links
============
* `<http://wiki.debian.org/NetworkConfiguration>`_
* `<http://www.linuxfoundation.org/collaborate/workgroups/networking/bonding>`_
* `<http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge>`_
* `<http://www.linuxfoundation.org/collaborate/workgroups/networking/vlan>`_
.. Caveats and Errata
.. ==================