mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
attempt to support python3
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
#
|
||||
|
||||
try:
|
||||
from ipaddr import IPNetwork
|
||||
from sets import Set
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
@@ -14,6 +12,11 @@ try:
|
||||
except ImportError, e:
|
||||
raise ImportError (str(e) + "- required module not found")
|
||||
|
||||
try:
|
||||
import ipaddress
|
||||
except ImportError:
|
||||
import ipaddr as ipaddress
|
||||
|
||||
class address(moduleBase):
|
||||
""" ifupdown2 addon module to configure address, mtu, hwaddress, alias
|
||||
(description) on an interface """
|
||||
@@ -117,8 +120,12 @@ class address(moduleBase):
|
||||
continue
|
||||
netmask = ifaceobj.get_attr_value_n('netmask', addr_index)
|
||||
if netmask:
|
||||
prefixlen = IPNetwork('%s' %addr +
|
||||
'/%s' %netmask).prefixlen
|
||||
try:
|
||||
prefixlen = ipaddress.ip_network('%s' %addr +
|
||||
'/%s' %netmask).prefixlen
|
||||
except AttributeError:
|
||||
prefixlen = ipaddress.IPNetwork('%s' %addr +
|
||||
'/%s' %netmask).prefixlen
|
||||
newaddrs.append(addr + '/%s' %prefixlen)
|
||||
else:
|
||||
newaddrs.append(addr)
|
||||
@@ -230,8 +237,12 @@ class address(moduleBase):
|
||||
addr = addrlist[addrindex]
|
||||
netmask = ifaceobj.get_attr_value_n('netmask', addrindex)
|
||||
if netmask:
|
||||
prefixlen = IPNetwork('%s' %addr +
|
||||
'/%s' %netmask).prefixlen
|
||||
try:
|
||||
prefixlen = ipaddress.ip_network('%s' %addr +
|
||||
'/%s' %netmask).prefixlen
|
||||
except AttributeError:
|
||||
prefixlen = ipaddress.IPNetwork('%s' %addr +
|
||||
'/%s' %netmask).prefixlen
|
||||
addr = addr + '/%s' %prefixlen
|
||||
outaddrlist.append(addr)
|
||||
return outaddrlist
|
||||
|
@@ -8,7 +8,6 @@ from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
from ipaddr import IPNetwork
|
||||
import logging
|
||||
import os
|
||||
import glob
|
||||
|
@@ -4,7 +4,6 @@
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
#
|
||||
|
||||
from sets import Set
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.bridgeutils import brctl
|
||||
@@ -15,6 +14,11 @@ import itertools
|
||||
import re
|
||||
import time
|
||||
|
||||
try:
|
||||
from sets import Set as set
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
class bridgeFlags:
|
||||
PORT_PROCESSED = 0x1
|
||||
|
||||
@@ -308,7 +312,7 @@ class bridge(moduleBase):
|
||||
self.ipcmd.batch_commit()
|
||||
return
|
||||
err = 0
|
||||
for bridgeport in Set(bridgeports).difference(Set(runningbridgeports)):
|
||||
for bridgeport in set(bridgeports).difference(set(runningbridgeports)):
|
||||
try:
|
||||
if not self.DRYRUN and not self.ipcmd.link_exists(bridgeport):
|
||||
self.log_warn('%s: bridge port %s does not exist'
|
||||
@@ -389,8 +393,8 @@ class bridge(moduleBase):
|
||||
|
||||
vids1_ints = self._ranges_to_ints(vids1)
|
||||
vids2_ints = self._ranges_to_ints(vids2)
|
||||
vids1_diff = Set(vids1_ints).difference(vids2_ints)
|
||||
vids2_diff = Set(vids2_ints).difference(vids1_ints)
|
||||
vids1_diff = set(vids1_ints).difference(vids2_ints)
|
||||
vids2_diff = set(vids2_ints).difference(vids1_ints)
|
||||
if vids1_diff:
|
||||
vids_to_add = ['%d' %start if start == end else '%d-%d' %(start, end)
|
||||
for start, end in self._ints_to_ranges(vids1_diff)]
|
||||
@@ -404,7 +408,7 @@ class bridge(moduleBase):
|
||||
|
||||
vids1_ints = self._ranges_to_ints(vids1)
|
||||
vids2_ints = self._ranges_to_ints(vids2)
|
||||
if Set(vids1_ints).symmetric_difference(vids2_ints):
|
||||
if set(vids1_ints).symmetric_difference(vids2_ints):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
@@ -1258,7 +1262,7 @@ class bridge(moduleBase):
|
||||
runningattrs = {}
|
||||
filterattrs = ['bridge-vids', 'bridge-port-vids',
|
||||
'bridge-port-pvids']
|
||||
for k in Set(ifaceattrs).difference(filterattrs):
|
||||
for k in set(ifaceattrs).difference(filterattrs):
|
||||
# get the corresponding ifaceobj attr
|
||||
v = ifaceobj.get_attr_value_first(k)
|
||||
if not v:
|
||||
|
@@ -5,8 +5,6 @@
|
||||
#
|
||||
|
||||
try:
|
||||
from ipaddr import IPNetwork
|
||||
from sets import Set
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.dhclient import dhclient
|
||||
|
@@ -7,8 +7,6 @@ import json
|
||||
import ifupdown.policymanager as policymanager
|
||||
|
||||
try:
|
||||
from ipaddr import IPNetwork
|
||||
from sets import Set
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.utilsbase import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
|
@@ -4,7 +4,6 @@
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
#
|
||||
|
||||
from sets import Set
|
||||
from ifupdown.iface import *
|
||||
import ifupdownaddons
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
@@ -12,6 +11,11 @@ from ifupdownaddons.ifenslaveutil import ifenslaveutil
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
|
||||
try:
|
||||
from sets import Set as set
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
class ifenslave(moduleBase):
|
||||
""" ifupdown2 addon module to configure bond interfaces """
|
||||
_modinfo = { 'mhelp' : 'bond configuration module',
|
||||
@@ -223,7 +227,7 @@ class ifenslave(moduleBase):
|
||||
if not self.PERFMODE:
|
||||
runningslaves = self.ifenslavecmd.get_slaves(ifaceobj.name);
|
||||
|
||||
for slave in Set(slaves).difference(Set(runningslaves)):
|
||||
for slave in set(slaves).difference(set(runningslaves)):
|
||||
if not self.PERFMODE and not self.ipcmd.link_exists(slave):
|
||||
self.log_warn('%s: skipping slave %s, does not exist'
|
||||
%(ifaceobj.name, slave))
|
||||
|
@@ -4,7 +4,6 @@
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
#
|
||||
|
||||
from sets import Set
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.bridgeutils import brctl
|
||||
@@ -12,6 +11,11 @@ from ifupdownaddons.iproute2 import iproute2
|
||||
from ifupdownaddons.mstpctlutil import mstpctlutil
|
||||
import traceback
|
||||
|
||||
try:
|
||||
from sets import Set as set
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
class mstpctlFlags:
|
||||
PORT_PROCESSED = 0x1
|
||||
|
||||
@@ -234,7 +238,7 @@ class mstpctl(moduleBase):
|
||||
if not bridgeports:
|
||||
return
|
||||
err = 0
|
||||
for bridgeport in Set(bridgeports).difference(Set(runningbridgeports)):
|
||||
for bridgeport in set(bridgeports).difference(set(runningbridgeports)):
|
||||
try:
|
||||
if not self.DRYRUN and not self.ipcmd.link_exists(bridgeport):
|
||||
self.log_warn('%s: bridge port %s does not exist'
|
||||
@@ -554,8 +558,8 @@ class mstpctl(moduleBase):
|
||||
continue
|
||||
portliststatus = 1
|
||||
if running_port_list and bridge_port_list:
|
||||
difference = Set(running_port_list).symmetric_difference(
|
||||
Set(bridge_port_list))
|
||||
difference = set(running_port_list).symmetric_difference(
|
||||
set(bridge_port_list))
|
||||
if not difference:
|
||||
portliststatus = 0
|
||||
ifaceobjcurr.update_config_with_status('mstpctl-ports',
|
||||
|
@@ -5,8 +5,6 @@
|
||||
#
|
||||
|
||||
try:
|
||||
from ipaddr import IPNetwork
|
||||
from sets import Set
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
|
@@ -5,7 +5,10 @@ from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
import logging
|
||||
from sets import Set
|
||||
try:
|
||||
from sets import Set as set
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
class vxlan(moduleBase):
|
||||
_modinfo = {'mhelp' : 'vxlan module configures vxlan interfaces.',
|
||||
@@ -77,8 +80,8 @@ class vxlan(moduleBase):
|
||||
ifaceobjcurr.update_config_with_status(attrname, a, 0)
|
||||
else:
|
||||
ifaceobjcurr.update_config_with_status(attrname, a, 1)
|
||||
running_addresses = Set(running_addresses).difference(
|
||||
Set(addresses))
|
||||
running_addresses = set(running_addresses).difference(
|
||||
set(addresses))
|
||||
[ifaceobjcurr.update_config_with_status(attrname, a, 1)
|
||||
for a in running_addresses]
|
||||
|
||||
|
21
ifupdown2/debian/control
Normal file
21
ifupdown2/debian/control
Normal file
@@ -0,0 +1,21 @@
|
||||
Source: ifupdown2
|
||||
Section: admin
|
||||
Priority: optional
|
||||
Maintainer: Roopa Prabhu <roopa@cumulusnetworks.com>
|
||||
Standards-Version: 3.9.4
|
||||
Build-Depends: python-setuptools, dh-python, debhelper (>= 9~), python3-all, python3-setuptools
|
||||
Homepage: https://github.com/CumulusNetworks/ifupdown2
|
||||
X-Python-Version: >= 2.6
|
||||
X-Python3-Version: >= 3.2
|
||||
|
||||
Package: ifupdown2
|
||||
Architecture: all
|
||||
Section: admin
|
||||
Priority: optional
|
||||
Suggests: python-gvgen, python3-mako
|
||||
Replaces: ifupdown
|
||||
Conflicts: ifupdown
|
||||
Depends: ${python3:Depends}, ${misc:Depends}, python3-argcomplete, python-ipaddr
|
||||
Description: ifupdown2 is a network interface management tool similar to ifupdown. ifupdown2 is essentially ifupdown re-written in python. ifupdown2 replaces ifupdown and provides the same binaries and files as ifupdown for interface configuration. Like ifupdown, ifupdown2 is a high level tool to configure (or, respectively deconfigure) network interfaces based on interface definitions in the file /etc/network/interfaces. ifupdown2 comes with a new command ifreload and new features with new command line options to existing commands ifup/ifdown/ifquery. New command line options to ifquery can help with querying and validating running state of interfaces. ifupdown2 supports interface templates for large scale interface deployments with python-mako. mako templates can be included or sourced into /etc/network/interfaces file. See /usr/share/doc/ifupdown2/README.rst for details about ifupdown2. see examples under /usr/share/doc/ifupdown2/examples.
|
||||
|
||||
|
15
ifupdown2/debian/rules
Executable file
15
ifupdown2/debian/rules
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
export DH_VERBOSE=1
|
||||
export PYBUILD_NAME=ifupdown2
|
||||
export PYBUILD_INSTALL_ARGS=--install-lib=/usr/share/ifupdown2 --install-scripts=/usr/share/ifupdown2
|
||||
|
||||
%:
|
||||
dh $@ --with python3 --buildsystem=pybuild
|
||||
|
||||
override_dh_python3:
|
||||
dh_python3 --shebang=/usr/bin/python3
|
||||
|
||||
override_dh_installman:
|
||||
./scripts/genmanpages.sh ./man.rst ./man
|
||||
dh_installman
|
@@ -11,8 +11,8 @@ import logging
|
||||
import subprocess
|
||||
import re
|
||||
import os
|
||||
from iface import *
|
||||
import rtnetlink_api as rtnetlink_api
|
||||
from .iface import *
|
||||
from .rtnetlink_api import *
|
||||
|
||||
class ifupdownBase(object):
|
||||
|
||||
|
@@ -15,14 +15,17 @@ import logging
|
||||
import sys, traceback
|
||||
import copy
|
||||
import json
|
||||
from statemanager import *
|
||||
from networkinterfaces import *
|
||||
from iface import *
|
||||
from scheduler import *
|
||||
from .statemanager import *
|
||||
from .networkinterfaces import *
|
||||
from .iface import *
|
||||
from .scheduler import *
|
||||
from collections import deque
|
||||
from collections import OrderedDict
|
||||
from graph import *
|
||||
from sets import Set
|
||||
from .graph import *
|
||||
try:
|
||||
from sets import Set as set
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
"""
|
||||
.. module:: ifupdownmain
|
||||
@@ -389,7 +392,7 @@ class ifupdownMain(ifupdownBase):
|
||||
interface with slave dependents.
|
||||
example: bond and bridges.
|
||||
This function logs such errors """
|
||||
setdlist = Set(dlist)
|
||||
setdlist = set(dlist)
|
||||
for ifacename, ifacedlist in self.dependency_graph.items():
|
||||
if not ifacedlist:
|
||||
continue
|
||||
@@ -399,7 +402,7 @@ class ifupdownMain(ifupdownBase):
|
||||
if (i.dependency_type == ifaceDependencyType.MASTER_SLAVE):
|
||||
check_depends = True
|
||||
if check_depends:
|
||||
common = Set(ifacedlist).intersection(setdlist)
|
||||
common = set(ifacedlist).intersection(setdlist)
|
||||
if common:
|
||||
self.logger.error('misconfig..?. iface %s and %s '
|
||||
%(ifaceobj.name, ifacename) +
|
||||
@@ -790,8 +793,8 @@ class ifupdownMain(ifupdownBase):
|
||||
if allow_classes:
|
||||
for i in ifaceobjs:
|
||||
if i.classes:
|
||||
common = Set([allow_classes]).intersection(
|
||||
Set(i.classes))
|
||||
common = set([allow_classes]).intersection(
|
||||
set(i.classes))
|
||||
if common:
|
||||
return True
|
||||
return False
|
||||
@@ -1088,12 +1091,12 @@ class ifupdownMain(ifupdownBase):
|
||||
excludepats, i)]
|
||||
|
||||
# Get already up interfaces that still exist in the interfaces file
|
||||
already_up_ifacenames_not_present = Set(
|
||||
already_up_ifacenames_not_present = set(
|
||||
already_up_ifacenames).difference(ifacenames)
|
||||
already_up_ifacenames_still_present = Set(
|
||||
already_up_ifacenames_still_present = set(
|
||||
already_up_ifacenames).difference(
|
||||
already_up_ifacenames_not_present)
|
||||
interfaces_to_up = Set(already_up_ifacenames_still_present).union(
|
||||
interfaces_to_up = set(already_up_ifacenames_still_present).union(
|
||||
filtered_ifacenames)
|
||||
|
||||
if (already_up_ifacenames_not_present and
|
||||
|
@@ -13,9 +13,9 @@ import glob
|
||||
import re
|
||||
import os
|
||||
import copy
|
||||
from utils import utils
|
||||
from iface import *
|
||||
from template import templateEngine
|
||||
from .utils import utils
|
||||
from .iface import *
|
||||
from .template import templateEngine
|
||||
|
||||
whitespaces = '\n\t\r '
|
||||
|
||||
|
@@ -8,9 +8,12 @@
|
||||
#
|
||||
from socket import NETLINK_ROUTE, AF_INET, AF_INET6
|
||||
from string import printable
|
||||
from ipaddr import *
|
||||
try:
|
||||
import ipaddress
|
||||
except ImportError:
|
||||
import ipaddr as ipaddress
|
||||
from ctypes import *
|
||||
from netlink import *
|
||||
from .netlink import *
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@@ -6,13 +6,13 @@
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
from os import getpid
|
||||
from socket import AF_UNSPEC
|
||||
from socket import AF_BRIDGE
|
||||
from iff import IFF_UP
|
||||
from rtnetlink import *
|
||||
import os
|
||||
import ifupdownmain
|
||||
from .iff import IFF_UP
|
||||
from .rtnetlink import *
|
||||
from .ifupdownmain import *
|
||||
|
||||
class rtnetlinkApi(RtNetlink):
|
||||
|
||||
|
@@ -7,19 +7,21 @@
|
||||
# interface scheduler
|
||||
#
|
||||
|
||||
from statemanager import *
|
||||
from iface import *
|
||||
from graph import *
|
||||
from .statemanager import *
|
||||
from .iface import *
|
||||
from .graph import *
|
||||
from collections import deque
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
import traceback
|
||||
import sys
|
||||
from graph import *
|
||||
from collections import deque
|
||||
from threading import *
|
||||
from ifupdownbase import *
|
||||
from sets import Set
|
||||
from .ifupdownbase import *
|
||||
try:
|
||||
from sets import Set as set
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
class ifaceSchedulerFlags():
|
||||
""" Enumerates scheduler flags """
|
||||
@@ -352,7 +354,7 @@ class ifaceScheduler():
|
||||
ifaceobj = ifupdownobj.get_ifaceobj_first(ifacename)
|
||||
if not ifaceobj:
|
||||
continue
|
||||
ulist = Set(ifaceobj.upperifaces).difference(upperifacenames)
|
||||
ulist = set(ifaceobj.upperifaces).difference(upperifacenames)
|
||||
nulist = []
|
||||
for u in ulist:
|
||||
uifaceobj = ifupdownobj.get_ifaceobj_first(u)
|
||||
|
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright 2014 Cumulus Networks, Inc. All rights reserved.
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
@@ -6,11 +5,14 @@
|
||||
# stateManager --
|
||||
# interface state manager
|
||||
#
|
||||
import cPickle
|
||||
try:
|
||||
import pickle
|
||||
except ImportError:
|
||||
import cPickle as pickle
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
import os
|
||||
from iface import *
|
||||
from .iface import *
|
||||
|
||||
class pickling():
|
||||
""" class with helper methods for pickling/unpickling iface objects """
|
||||
@@ -21,7 +23,7 @@ class pickling():
|
||||
try:
|
||||
with open(filename, 'w') as f:
|
||||
for obj in list_of_objects:
|
||||
cPickle.dump(obj, f, cPickle.HIGHEST_PROTOCOL)
|
||||
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
|
||||
except:
|
||||
raise
|
||||
|
||||
@@ -29,7 +31,7 @@ class pickling():
|
||||
def save_obj(cls, f, obj):
|
||||
""" pickle iface object """
|
||||
try:
|
||||
cPickle.dump(obj, f, cPickle.HIGHEST_PROTOCOL)
|
||||
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
|
||||
except:
|
||||
raise
|
||||
|
||||
@@ -38,7 +40,7 @@ class pickling():
|
||||
""" load picked iface object """
|
||||
with open(filename, 'r') as f:
|
||||
while True:
|
||||
try: yield cPickle.load(f)
|
||||
try: yield pickle.load(f)
|
||||
except EOFError: break
|
||||
except: raise
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
from utils import *
|
||||
from .utils import *
|
||||
|
||||
class templateEngine():
|
||||
""" provides template rendering methods """
|
||||
|
@@ -5,11 +5,11 @@
|
||||
#
|
||||
|
||||
from ifupdown.iface import *
|
||||
from utilsbase import *
|
||||
from .utilsbase import *
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
from cache import *
|
||||
from .cache import *
|
||||
|
||||
class brctl(utilsBase):
|
||||
""" This class contains helper functions to interact with the bridgeutils
|
||||
|
@@ -4,7 +4,7 @@
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
#
|
||||
|
||||
from utilsbase import *
|
||||
from .utilsbase import *
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
|
@@ -7,9 +7,9 @@
|
||||
import os
|
||||
import re
|
||||
from ifupdown.iface import *
|
||||
from utilsbase import *
|
||||
from iproute2 import *
|
||||
from cache import *
|
||||
from .utilsbase import *
|
||||
from .iproute2 import *
|
||||
from .cache import *
|
||||
|
||||
class ifenslaveutil(utilsBase):
|
||||
""" This class contains methods to interact with linux kernel bond
|
||||
|
@@ -6,8 +6,8 @@
|
||||
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
from utilsbase import *
|
||||
from cache import *
|
||||
from .utilsbase import *
|
||||
from .cache import *
|
||||
|
||||
VXLAN_UDP_PORT = 4789
|
||||
|
||||
|
@@ -11,11 +11,6 @@ import logging
|
||||
import subprocess
|
||||
import traceback
|
||||
from ifupdown.iface import *
|
||||
#from ifupdownaddons.iproute2 import *
|
||||
#from ifupdownaddons.dhclient import *
|
||||
#from ifupdownaddons.bridgeutils import *
|
||||
#from ifupdownaddons.mstpctlutil import *
|
||||
#from ifupdownaddons.ifenslaveutil import *
|
||||
|
||||
class moduleBase(object):
|
||||
""" Base class for ifupdown addon modules
|
||||
|
@@ -4,9 +4,9 @@
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
#
|
||||
|
||||
from utilsbase import *
|
||||
from .utilsbase import *
|
||||
from ifupdown.iface import *
|
||||
from cache import *
|
||||
from .cache import *
|
||||
import re
|
||||
|
||||
class mstpctlutil(utilsBase):
|
||||
|
@@ -9,9 +9,8 @@ import subprocess
|
||||
import re
|
||||
import io
|
||||
from ifupdown.iface import *
|
||||
from cache import *
|
||||
from .cache import *
|
||||
|
||||
#import timeit
|
||||
import time
|
||||
import logging
|
||||
|
||||
|
@@ -1,207 +0,0 @@
|
||||
.\" Man page generated from reStructeredText.
|
||||
.
|
||||
.TH INTERFACES 5 "2014-02-05" "0.1" ""
|
||||
.SH NAME
|
||||
interfaces \- network interface configuration for ifupdown
|
||||
.
|
||||
.nr rst2man-indent-level 0
|
||||
.
|
||||
.de1 rstReportMargin
|
||||
\\$1 \\n[an-margin]
|
||||
level \\n[rst2man-indent-level]
|
||||
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
-
|
||||
\\n[rst2man-indent0]
|
||||
\\n[rst2man-indent1]
|
||||
\\n[rst2man-indent2]
|
||||
..
|
||||
.de1 INDENT
|
||||
.\" .rstReportMargin pre:
|
||||
. RS \\$1
|
||||
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
|
||||
. nr rst2man-indent-level +1
|
||||
.\" .rstReportMargin post:
|
||||
..
|
||||
.de UNINDENT
|
||||
. RE
|
||||
.\" indent \\n[an-margin]
|
||||
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
.nr rst2man-indent-level -1
|
||||
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
|
||||
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
|
||||
..
|
||||
.SH DESCRIPTION
|
||||
.INDENT 0.0
|
||||
.INDENT 3.5
|
||||
\fB/etc/network/interfaces\fP contains network interface configuration
|
||||
information for the \fBifup(8)\fP, \fBifdown(8)\fP and \fBifquery(8)\fP commands.
|
||||
.sp
|
||||
This is where you configure how your system is connected to the network.
|
||||
.sp
|
||||
Lines starting with # are ignored. Note that end\-of\-line comments are
|
||||
NOT supported, comments must be on a line of their own.
|
||||
.sp
|
||||
A line may be extended across multiple lines by making the last character
|
||||
a backslash.
|
||||
.sp
|
||||
The file consists of zero or more "iface", "auto", "allow\-"
|
||||
and "source" stanzas. Here is an example:
|
||||
.sp
|
||||
.nf
|
||||
.ft C
|
||||
auto lo eth0
|
||||
allow\-hotplug eth1
|
||||
|
||||
iface lo inet loopback
|
||||
|
||||
source /etc/network/interfaces.d/bridges
|
||||
|
||||
iface eth0 inet static
|
||||
address 192.168.1.1/24
|
||||
up flush\-mail
|
||||
|
||||
iface eth1 inet dhcp
|
||||
.ft P
|
||||
.fi
|
||||
.sp
|
||||
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.
|
||||
(This option is used by the system boot scripts.) Physical interface names
|
||||
should follow the word "auto" on the same line. There can be multiple
|
||||
"auto" stanzas.
|
||||
.sp
|
||||
Lines beginning with "allow\-" are used to identify interfaces that
|
||||
should be brought up automatically by various subsytems. This may be
|
||||
done using a command such as "ifup \-\-allow=hotplug eth0 eth1", which
|
||||
will only bring up eth0 or eth1 if it is listed in an "allow\-hotplug"
|
||||
line. Note that "allow\-auto" and "auto" are synonyms.
|
||||
.sp
|
||||
Lines beginning with "source" are used to include stanzas from other
|
||||
files, so configuration can be split into many files. The word "source"
|
||||
is followed by the path of file to be sourced. Shell wildcards can be
|
||||
used. Currently only supports absolute
|
||||
path names.
|
||||
.sp
|
||||
iface is normally given a interface name as its first non\-option
|
||||
argument.
|
||||
.sp
|
||||
The interface name is followed by the name of the address family that the
|
||||
interface uses. This will be "inet" for TCP/IP networking and inet6 for
|
||||
ipv6. Following that is the name of the method used to configure the
|
||||
interface.
|
||||
.sp
|
||||
ifupdown supports iface stanzas without a family or a method. This enables
|
||||
using the same stanza for inet and inet6 family addresses. And the method
|
||||
defaults to "static"
|
||||
.sp
|
||||
Additional interface options/attributes can be given on subsequent lines
|
||||
in the iface stanza. These options come from addon modules. see
|
||||
\fBifupdown\-addons\-interfaces(5)\fP for these options.
|
||||
.sp
|
||||
example bridge interface with additional attributes listed in the
|
||||
\fBifupdown\-addons\-interfaces(5)\fP man page:
|
||||
.sp
|
||||
.nf
|
||||
.ft C
|
||||
auto br0
|
||||
iface br0
|
||||
address 12.0.0.4/24
|
||||
address 2000:1000:1000:1000:3::5/128
|
||||
bridge\-ports swp1 swp2 swp3
|
||||
bridge\-stp on
|
||||
.ft P
|
||||
.fi
|
||||
.sp
|
||||
ifupdown supports python\-mako style templates in the interfaces file.
|
||||
See examples section for details.
|
||||
.sp
|
||||
See \fB/usr/share/doc/python\-ifupdown2/examples/\fP for \fBinterfaces(5)\fP
|
||||
file examples and interfaces file generation scripts.
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.SH METHODS
|
||||
.INDENT 0.0
|
||||
.INDENT 3.5
|
||||
Both \fBinet\fP and \fBinet6\fP address family interfaces can use the following
|
||||
methods (However they are not required):
|
||||
.INDENT 0.0
|
||||
.TP
|
||||
.B The loopback Method
|
||||
This method may be used to define the loopback interface.
|
||||
.TP
|
||||
.B The static Method
|
||||
This method may be used to define ethernet interfaces with
|
||||
statically allocated addresses.
|
||||
.TP
|
||||
.B The dhcp Method
|
||||
This method may be used to obtain an address via DHCP.
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.SH BUILTIN INTERFACES
|
||||
.INDENT 0.0
|
||||
.INDENT 3.5
|
||||
\fBiface\fP sections for some interfaces like physical interfaces or vlan
|
||||
interfaces in dot notation (like eth1.100) are understood by ifupdown.
|
||||
These interfaces do not need an entry in the interfaces file if
|
||||
they are dependents of other interfaces and dont need any specific
|
||||
configurations like addresses etc.
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.SH EXAMPLES
|
||||
.INDENT 0.0
|
||||
.INDENT 3.5
|
||||
Sample /etc/network/interfaces file:
|
||||
.sp
|
||||
.nf
|
||||
.ft C
|
||||
auto lo
|
||||
iface lo
|
||||
address 192.168.2.0/24
|
||||
address 2001:dee:eeee:1::4/128
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
|
||||
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
|
||||
.ft P
|
||||
.fi
|
||||
.sp
|
||||
For additional syntax and examples see \fBifupdown\-addons\-interfaces(5)\fP
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.SH FILES
|
||||
.INDENT 0.0
|
||||
.INDENT 3.5
|
||||
/etc/network/interfaces
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.SH SEE ALSO
|
||||
.INDENT 0.0
|
||||
.INDENT 3.5
|
||||
ifupdown\-addons\-interfaces(5),
|
||||
ifup(8),
|
||||
ifquery(8),
|
||||
ifreload(8)
|
||||
.UNINDENT
|
||||
.UNINDENT
|
||||
.SH AUTHOR
|
||||
Roopa Prabhu <roopa@cumulusnetworks.com>
|
||||
.SH COPYRIGHT
|
||||
Copyright 2014 Cumulus Networks, Inc. All rights reserved.
|
||||
.\" Generated by docutils manpage writer.
|
||||
.\"
|
||||
.
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#! /usr/bin/python3
|
||||
#
|
||||
# Copyright 2014 Cumulus Networks, Inc. All rights reserved.
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
@@ -10,8 +10,14 @@ import sys
|
||||
import os
|
||||
import argcomplete
|
||||
import argparse
|
||||
import ConfigParser
|
||||
import StringIO
|
||||
try:
|
||||
import configparser as ConfigParser
|
||||
except ImportError:
|
||||
import ConfigParser as ConfigParser
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
import logging
|
||||
import logging.handlers
|
||||
import resource
|
||||
@@ -394,14 +400,14 @@ def validate_args(op, args):
|
||||
return True
|
||||
if op == 'reload':
|
||||
if not args.all and not args.currentlyup:
|
||||
print '\'-a\' or \'-c\' option is required'
|
||||
print ('\'-a\' or \'-c\' option is required')
|
||||
return False
|
||||
elif (not args.iflist and
|
||||
not args.all and not args.CLASS):
|
||||
print '\'-a\' option or interface list are required'
|
||||
print ('\'-a\' option or interface list are required')
|
||||
return False
|
||||
if args.iflist and args.all:
|
||||
print '\'-a\' option and interface list are mutually exclusive'
|
||||
print ('\'-a\' option and interface list are mutually exclusive')
|
||||
return False
|
||||
if op != 'reload' and args.CLASS and (args.all or args.iflist):
|
||||
print ('\'--allow\' option is mutually exclusive ' +
|
||||
@@ -414,7 +420,7 @@ def read_config(args):
|
||||
|
||||
config = open(configfile, 'r').read()
|
||||
configStr = '[ifupdown2]\n' + config
|
||||
configFP = StringIO.StringIO(configStr)
|
||||
configFP = StringIO(configStr)
|
||||
parser = ConfigParser.RawConfigParser()
|
||||
parser.readfp(configFP)
|
||||
configmap_g = dict(parser.items('ifupdown2'))
|
||||
@@ -462,17 +468,17 @@ def main(argv):
|
||||
exit(1)
|
||||
|
||||
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)
|
||||
|
||||
if not sys.argv[0].endswith('ifquery') and not utils.lockFile(lockfile):
|
||||
print 'Another instance of this program is already running.'
|
||||
print ('Another instance of this program is already running.')
|
||||
exit(0)
|
||||
|
||||
read_config(args)
|
||||
init(args)
|
||||
handlers.get(op)(args)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
if not str(e):
|
||||
exit(1)
|
||||
if args and args.debug:
|
||||
@@ -481,7 +487,7 @@ def main(argv):
|
||||
if logger:
|
||||
logger.error(str(e))
|
||||
else:
|
||||
print str(e)
|
||||
print (str(e))
|
||||
#if args and not args.debug:
|
||||
# print '\nrerun the command with \'-d\' for a detailed errormsg'
|
||||
exit(1)
|
||||
|
Reference in New Issue
Block a user