mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
ifupdown: add new ifupdownflags class to carry ifupdown flags
Ticket: cleanup Reviewed By: Testing Done: Tested ifupdown sanity This gets rid of some ugly previous flag handling which was passed through modules. This creates a global instance of flags that all addon modules and helper modules can use. Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
This commit is contained in:
@ -15,6 +15,7 @@ try:
|
||||
from ifupdownaddons.dhclient import dhclient
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
import ifupdown.ifupdownconfig as ifupdownConfig
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
except ImportError, e:
|
||||
raise ImportError (str(e) + "- required module not found")
|
||||
|
||||
@ -192,7 +193,7 @@ class address(moduleBase):
|
||||
'iface stanzas, skip purging existing addresses')
|
||||
purge_addresses = 'no'
|
||||
|
||||
if not self.PERFMODE and purge_addresses == 'yes':
|
||||
if not ifupdownflags.flags.PERFMODE and purge_addresses == 'yes':
|
||||
# if perfmode is not set and purge addresses is not set to 'no'
|
||||
# lets purge addresses not in the config
|
||||
runningaddrs = self.ipcmd.addr_get(ifaceobj.name, details=False)
|
||||
@ -240,7 +241,7 @@ class address(moduleBase):
|
||||
addr_method = ifaceobj.addr_method
|
||||
try:
|
||||
# release any stale dhcp addresses if present
|
||||
if (addr_method != "dhcp" and not self.PERFMODE and
|
||||
if (addr_method != "dhcp" and not ifupdownflags.flags.PERFMODE and
|
||||
not (ifaceobj.flags & iface.HAS_SIBLINGS)):
|
||||
# if not running in perf mode and ifaceobj does not have
|
||||
# any sibling iface objects, kill any stale dhclient
|
||||
@ -268,7 +269,7 @@ class address(moduleBase):
|
||||
hwaddress = self._get_hwaddress(ifaceobj)
|
||||
if hwaddress:
|
||||
running_hwaddress = None
|
||||
if not self.PERFMODE: # system is clean
|
||||
if not ifupdownflags.flags.PERFMODE: # system is clean
|
||||
running_hwaddress = self.ipcmd.link_get_hwaddress(ifaceobj.name)
|
||||
if hwaddress != running_hwaddress:
|
||||
slave_down = False
|
||||
@ -478,7 +479,7 @@ class address(moduleBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, ifaceobj_getfunc=None):
|
||||
""" run address configuration on the interface object passed as argument
|
||||
|
@ -9,6 +9,8 @@ from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.statemanager as statemanager
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
|
||||
from ipaddr import IPNetwork
|
||||
import logging
|
||||
import os
|
||||
@ -142,7 +144,7 @@ class addressvirtual(moduleBase):
|
||||
return maclist
|
||||
|
||||
def _apply_address_config(self, ifaceobj, address_virtual_list):
|
||||
purge_existing = False if self.PERFMODE else True
|
||||
purge_existing = False if ifupdownflags.flags.PERFMODE else True
|
||||
|
||||
hwaddress = []
|
||||
self.ipcmd.batch_start()
|
||||
@ -338,7 +340,7 @@ class addressvirtual(moduleBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
""" run vlan configuration on the interface object passed as argument
|
||||
|
@ -12,6 +12,7 @@ from ifupdownaddons.bondutil import bondutil
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
import ifupdown.policymanager as policymanager
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
|
||||
class bond(moduleBase):
|
||||
""" ifupdown2 addon module to configure bond interfaces """
|
||||
@ -219,13 +220,14 @@ class bond(moduleBase):
|
||||
self.logger.debug('%s: no slaves found' %ifaceobj.name)
|
||||
return
|
||||
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
runningslaves = self.bondcmd.get_slaves(ifaceobj.name);
|
||||
|
||||
clag_bond = self._is_clag_bond(ifaceobj)
|
||||
|
||||
for slave in Set(slaves).difference(Set(runningslaves)):
|
||||
if not self.PERFMODE and not self.ipcmd.link_exists(slave):
|
||||
if (not ifupdownflags.flags.PERFMODE and
|
||||
not self.ipcmd.link_exists(slave)):
|
||||
self.log_warn('%s: skipping slave %s, does not exist'
|
||||
%(ifaceobj.name, slave))
|
||||
continue
|
||||
@ -365,11 +367,10 @@ class bond(moduleBase):
|
||||
return self._run_ops.keys()
|
||||
|
||||
def _init_command_handlers(self):
|
||||
flags = self.get_flags()
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**flags)
|
||||
self.ipcmd = iproute2()
|
||||
if not self.bondcmd:
|
||||
self.bondcmd = bondutil(**flags)
|
||||
self.bondcmd = bondutil()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
""" run bond configuration on the interface object passed as argument
|
||||
|
@ -12,6 +12,7 @@ from ifupdownaddons.bridgeutils import brctl
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
from collections import Counter
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
import itertools
|
||||
import re
|
||||
import time
|
||||
@ -347,7 +348,7 @@ class bridge(moduleBase):
|
||||
self._process_bridge_waitport(ifaceobj, bridgeports)
|
||||
self.ipcmd.batch_start()
|
||||
# Delete active ports not in the new port list
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
runningbridgeports = self.brctlcmd.get_bridge_ports(ifaceobj.name)
|
||||
if runningbridgeports:
|
||||
for bport in runningbridgeports:
|
||||
@ -364,7 +365,8 @@ class bridge(moduleBase):
|
||||
newbridgeports = Set(bridgeports).difference(Set(runningbridgeports))
|
||||
for bridgeport in newbridgeports:
|
||||
try:
|
||||
if not self.DRYRUN and not self.ipcmd.link_exists(bridgeport):
|
||||
if (not ifupdownflags.flags.DRYRUN and
|
||||
not self.ipcmd.link_exists(bridgeport)):
|
||||
self.log_warn('%s: bridge port %s does not exist'
|
||||
%(ifaceobj.name, bridgeport))
|
||||
err += 1
|
||||
@ -476,7 +478,7 @@ class bridge(moduleBase):
|
||||
attrval = ifaceobj.get_attr_value_first('bridge-mcqv4src')
|
||||
if attrval:
|
||||
running_mcqv4src = {}
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
running_mcqv4src = self.brctlcmd.get_mcqv4src(ifaceobj.name)
|
||||
mcqs = {}
|
||||
srclist = attrval.split()
|
||||
@ -1015,7 +1017,7 @@ class bridge(moduleBase):
|
||||
running_ports = ''
|
||||
bridge_just_created = False
|
||||
try:
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
if not self.ipcmd.link_exists(ifaceobj.name):
|
||||
self.ipcmd.link_create(ifaceobj.name, 'bridge')
|
||||
bridge_just_created = True
|
||||
@ -1685,11 +1687,10 @@ class bridge(moduleBase):
|
||||
return self._run_ops.keys()
|
||||
|
||||
def _init_command_handlers(self):
|
||||
flags = self.get_flags()
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**flags)
|
||||
self.ipcmd = iproute2()
|
||||
if not self.brctlcmd:
|
||||
self.brctlcmd = brctl(**flags)
|
||||
self.brctlcmd = brctl()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None,
|
||||
ifaceobj_getfunc=None):
|
||||
|
@ -8,6 +8,7 @@ from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
from ifupdownaddons.bridgeutils import brctl
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
import logging
|
||||
|
||||
class bridgevlan(moduleBase):
|
||||
@ -67,7 +68,7 @@ class bridgevlan(moduleBase):
|
||||
return
|
||||
|
||||
running_mcqv4src = {}
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
running_mcqv4src = self.brctlcmd.get_mcqv4src(bridgename)
|
||||
if running_mcqv4src:
|
||||
r_mcqv4src = running_mcqv4src.get(vlan)
|
||||
@ -137,9 +138,9 @@ class bridgevlan(moduleBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
if not self.brctlcmd:
|
||||
self.brctlcmd = brctl(**self.get_flags())
|
||||
self.brctlcmd = brctl()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
""" run vlan configuration on the interface object passed as argument
|
||||
|
@ -12,6 +12,7 @@ try:
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.dhclient import dhclient
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
except ImportError, e:
|
||||
raise ImportError (str(e) + "- required module not found")
|
||||
|
||||
@ -42,7 +43,7 @@ class dhcp(moduleBase):
|
||||
if ifaceobj.addr_family == 'inet':
|
||||
# First release any existing dhclient processes
|
||||
try:
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
self.dhclientcmd.stop(ifaceobj.name)
|
||||
except:
|
||||
pass
|
||||
@ -114,7 +115,7 @@ class dhcp(moduleBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
""" run dhcp configuration on the interface object passed as argument
|
||||
|
@ -241,7 +241,7 @@ class ethtool(moduleBase,utilsBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
""" run ethtool configuration on the interface object passed as
|
||||
|
@ -9,6 +9,7 @@
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
import logging
|
||||
|
||||
class link(moduleBase):
|
||||
@ -32,7 +33,8 @@ class link(moduleBase):
|
||||
ifaceobj.get_attr_value_first('link-type'))
|
||||
|
||||
def _down(self, ifaceobj):
|
||||
if not self.PERFMODE and not self.ipcmd.link_exists(ifaceobj.name):
|
||||
if (not ifupdownflags.flags.PERFMODE and
|
||||
not self.ipcmd.link_exists(ifaceobj.name)):
|
||||
return
|
||||
try:
|
||||
self.ipcmd.link_delete(ifaceobj.name)
|
||||
@ -60,7 +62,7 @@ class link(moduleBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
op_handler = self._run_ops.get(operation)
|
||||
|
@ -12,6 +12,7 @@ from ifupdownaddons.bridgeutils import brctl
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
from ifupdownaddons.mstpctlutil import mstpctlutil
|
||||
from ifupdownaddons.systemutils import systemUtils
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
|
||||
class mstpctlFlags:
|
||||
PORT_PROCESSED = 0x1
|
||||
@ -236,7 +237,7 @@ class mstpctl(moduleBase):
|
||||
|
||||
runningbridgeports = []
|
||||
# Delete active ports not in the new port list
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
runningbridgeports = self.brctlcmd.get_bridge_ports(ifaceobj.name)
|
||||
if runningbridgeports:
|
||||
[self.ipcmd.link_set(bport, 'nomaster')
|
||||
@ -249,7 +250,8 @@ class mstpctl(moduleBase):
|
||||
err = 0
|
||||
for bridgeport in Set(bridgeports).difference(Set(runningbridgeports)):
|
||||
try:
|
||||
if not self.DRYRUN and not self.ipcmd.link_exists(bridgeport):
|
||||
if (not ifupdownflags.flags.DRYRUN and
|
||||
not self.ipcmd.link_exists(bridgeport)):
|
||||
self.log_warn('%s: bridge port %s does not exist'
|
||||
%(ifaceobj.name, bridgeport))
|
||||
err += 1
|
||||
@ -263,7 +265,7 @@ class mstpctl(moduleBase):
|
||||
self.log_error('error configuring bridge (missing ports)')
|
||||
|
||||
def _apply_bridge_settings(self, ifaceobj):
|
||||
check = False if self.PERFMODE else True
|
||||
check = False if ifupdownflags.flags.PERFMODE else True
|
||||
try:
|
||||
# set bridge attributes
|
||||
for attrname, dstattrname in self._attrs_map.items():
|
||||
@ -331,7 +333,7 @@ class mstpctl(moduleBase):
|
||||
bridgeifaceobj=None,
|
||||
stp_running_on=True,
|
||||
mstpd_running=True):
|
||||
check = False if self.PERFMODE else True
|
||||
check = False if ifupdownflags.flags.PERFMODE else True
|
||||
applied = False
|
||||
if not bridgename and bridgeifaceobj:
|
||||
bridgename = bridgeifaceobj.name
|
||||
@ -446,7 +448,7 @@ class mstpctl(moduleBase):
|
||||
# If bridge ports specified with mstpctl attr, create the
|
||||
# bridge and also add its ports
|
||||
self.ipcmd.batch_start()
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
if not self.ipcmd.link_exists(ifaceobj.name):
|
||||
self.ipcmd.link_create(ifaceobj.name, 'bridge')
|
||||
else:
|
||||
@ -809,13 +811,12 @@ class mstpctl(moduleBase):
|
||||
return self._run_ops.keys()
|
||||
|
||||
def _init_command_handlers(self):
|
||||
flags = self.get_flags()
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**flags)
|
||||
self.ipcmd = iproute2()
|
||||
if not self.brctlcmd:
|
||||
self.brctlcmd = brctl(**flags)
|
||||
self.brctlcmd = brctl()
|
||||
if not self.mstpctlcmd:
|
||||
self.mstpctlcmd = mstpctlutil(**flags)
|
||||
self.mstpctlcmd = mstpctlutil()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None,
|
||||
ifaceobj_getfunc=None, **extra_args):
|
||||
|
@ -9,6 +9,7 @@ import ifupdownaddons
|
||||
import signal
|
||||
|
||||
from ifupdown.utils import utils
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
|
||||
class usercmds(ifupdownaddons.modulebase.moduleBase):
|
||||
""" ifupdown2 addon module to configure user specified commands """
|
||||
@ -38,7 +39,7 @@ class usercmds(ifupdownaddons.modulebase.moduleBase):
|
||||
cmd_returncode = 0
|
||||
try:
|
||||
self.logger.info('executing %s' %cmd)
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
ch = subprocess.Popen(cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
|
@ -8,6 +8,7 @@ from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
import logging
|
||||
import re
|
||||
|
||||
@ -132,7 +133,7 @@ class vlan(moduleBase):
|
||||
vlanrawdevice = self._get_vlan_raw_device(ifaceobj)
|
||||
if not vlanrawdevice:
|
||||
raise Exception('could not determine vlan raw device')
|
||||
if not self.PERFMODE:
|
||||
if not ifupdownflags.flags.PERFMODE:
|
||||
if not self.ipcmd.link_exists(vlanrawdevice):
|
||||
raise Exception('rawdevice %s not present' %vlanrawdevice)
|
||||
if self.ipcmd.link_exists(ifaceobj.name):
|
||||
@ -151,7 +152,8 @@ class vlan(moduleBase):
|
||||
vlanrawdevice = self._get_vlan_raw_device(ifaceobj)
|
||||
if not vlanrawdevice:
|
||||
raise Exception('could not determine vlan raw device')
|
||||
if not self.PERFMODE and not self.ipcmd.link_exists(ifaceobj.name):
|
||||
if (not ifupdownflags.flags.PERFMODE and
|
||||
not self.ipcmd.link_exists(ifaceobj.name)):
|
||||
return
|
||||
try:
|
||||
self.ipcmd.link_delete(ifaceobj.name)
|
||||
@ -203,9 +205,8 @@ class vlan(moduleBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
""" run vlan configuration on the interface object passed as argument
|
||||
|
||||
|
@ -13,6 +13,7 @@ from ifupdown.iface import *
|
||||
import ifupdown.policymanager as policymanager
|
||||
import ifupdownaddons
|
||||
import ifupdown.rtnetlink_api as rtnetlink_api
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.bondutil import bondutil
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
@ -50,7 +51,7 @@ class vrf(moduleBase):
|
||||
self.bondcmd = None
|
||||
self.dhclientcmd = None
|
||||
self.name = self.__class__.__name__
|
||||
if self.PERFMODE:
|
||||
if ifupdownflags.flags.PERFMODE:
|
||||
# if perf mode is set, remove vrf map file.
|
||||
# start afresh. PERFMODE is set at boot
|
||||
if os.path.exists(self.iproute2_vrf_filename):
|
||||
@ -325,7 +326,7 @@ class vrf(moduleBase):
|
||||
pass
|
||||
|
||||
def _handle_existing_connections(self, ifaceobj, vrfname):
|
||||
if not ifaceobj or self.PERFMODE:
|
||||
if not ifaceobj or ifupdownflags.flags.PERFMODE:
|
||||
return
|
||||
if (self.vrf_mgmt_devname and
|
||||
self.vrf_mgmt_devname == vrfname):
|
||||
@ -843,13 +844,12 @@ class vrf(moduleBase):
|
||||
return self._run_ops.keys()
|
||||
|
||||
def _init_command_handlers(self):
|
||||
flags = self.get_flags()
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**flags)
|
||||
self.ipcmd = iproute2()
|
||||
if not self.bondcmd:
|
||||
self.bondcmd = bondutil(**flags)
|
||||
self.bondcmd = bondutil()
|
||||
if not self.dhclientcmd:
|
||||
self.dhclientcmd = dhclient(**flags)
|
||||
self.dhclientcmd = dhclient()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None,
|
||||
ifaceobj_getfunc=None, **extra_args):
|
||||
|
@ -10,6 +10,7 @@ try:
|
||||
from ifupdown.iface import *
|
||||
from ifupdownaddons.modulebase import moduleBase
|
||||
from ifupdownaddons.iproute2 import iproute2
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
import os
|
||||
import glob
|
||||
import logging
|
||||
@ -70,7 +71,7 @@ class vrrpd(moduleBase):
|
||||
""" up vrrpd -n -D -i $IFACE -v 1 -p 20 10.0.1.254
|
||||
up ifplugd -i $IFACE -b -f -u0 -d1 -I -p -q """
|
||||
|
||||
if (not self.DRYRUN and
|
||||
if (not ifupdownflags.flags.DRYRUN and
|
||||
not os.path.exists('/sys/class/net/%s' %ifaceobj.name)):
|
||||
return
|
||||
|
||||
|
@ -181,7 +181,7 @@ class vxlan(moduleBase):
|
||||
|
||||
def _init_command_handlers(self):
|
||||
if not self.ipcmd:
|
||||
self.ipcmd = iproute2(**self.get_flags())
|
||||
self.ipcmd = iproute2()
|
||||
|
||||
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
||||
op_handler = self._run_ops.get(operation)
|
||||
|
@ -17,7 +17,7 @@ import shlex
|
||||
|
||||
from iface import *
|
||||
from ifupdown.utils import utils
|
||||
|
||||
import ifupdownflags as ifupdownflags
|
||||
|
||||
class ifupdownBase(object):
|
||||
|
||||
@ -30,7 +30,7 @@ class ifupdownBase(object):
|
||||
cmdout = ''
|
||||
try:
|
||||
self.logger.info('executing ' + cmd)
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return cmdout
|
||||
ch = subprocess.Popen(shlex.split(cmd),
|
||||
stdout=subprocess.PIPE,
|
||||
@ -51,7 +51,7 @@ class ifupdownBase(object):
|
||||
return cmdout
|
||||
|
||||
def ignore_error(self, errmsg):
|
||||
if (self.FORCE == True or re.search(r'exists', errmsg,
|
||||
if (ifupdownflags.flags.FORCE == True or re.search(r'exists', errmsg,
|
||||
re.IGNORECASE | re.MULTILINE) is not None):
|
||||
return True
|
||||
return False
|
||||
|
21
ifupdown/ifupdownflags.py
Normal file
21
ifupdown/ifupdownflags.py
Normal file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2015 Cumulus Networks, Inc. All rights reserved.
|
||||
#
|
||||
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
||||
#
|
||||
#
|
||||
|
||||
class ifupdownFlags():
|
||||
|
||||
def __init__(self):
|
||||
self.FORCE = False
|
||||
self.DRYRUN = False
|
||||
self.NOWAIT = False
|
||||
self.PERFMODE = False
|
||||
self.CACHE = False
|
||||
|
||||
# Flags
|
||||
self.CACHE_FLAGS = 0x0
|
||||
|
||||
flags = ifupdownFlags()
|
@ -17,6 +17,7 @@ import copy
|
||||
import json
|
||||
import ifupdown.statemanager as statemanager
|
||||
import ifupdown.ifupdownconfig as ifupdownConfig
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
from networkinterfaces import *
|
||||
from iface import *
|
||||
from scheduler import *
|
||||
@ -38,16 +39,6 @@ _crossmark = u'\u2717'
|
||||
_success_sym = '(%s)' %_tickmark
|
||||
_error_sym = '(%s)' %_crossmark
|
||||
|
||||
class ifupdownFlags():
|
||||
FORCE = False
|
||||
DRYRUN = False
|
||||
NOWAIT = False
|
||||
PERFMODE = False
|
||||
CACHE = False
|
||||
|
||||
# Flags
|
||||
CACHE_FLAGS = 0x0
|
||||
|
||||
class ifupdownMainFlags():
|
||||
WITH_DEPENDS = False
|
||||
ALL = False
|
||||
@ -195,13 +186,14 @@ class ifupdownMain(ifupdownBase):
|
||||
AttributeError, KeyError """
|
||||
|
||||
self.logger = logging.getLogger('ifupdown')
|
||||
self.FORCE = force
|
||||
self.DRYRUN = dryrun
|
||||
self.NOWAIT = nowait
|
||||
self.PERFMODE = perfmode
|
||||
self.CACHE = cache
|
||||
ifupdownflags.flags.FORCE = force
|
||||
ifupdownflags.flags.DRYRUN = dryrun
|
||||
ifupdownflags.flags.NOWAIT = nowait
|
||||
ifupdownflags.flags.PERFMODE = perfmode
|
||||
ifupdownflags.flags.CACHE = cache
|
||||
|
||||
# Can be used to provide hints for caching
|
||||
self.CACHE_FLAGS = 0x0
|
||||
ifupdownflags.flags.CACHE_FLAGS = 0x0
|
||||
|
||||
self.flags = ifupdownMainFlags()
|
||||
|
||||
@ -219,14 +211,6 @@ class ifupdownMain(ifupdownBase):
|
||||
self.flags.DELETE_DEPENDENT_IFACES_WITH_NOCONFIG = False
|
||||
self.flags.ADDONS_ENABLE = addons_enable
|
||||
|
||||
# Copy flags into ifupdownFlags
|
||||
# XXX: before we transition fully to ifupdownFlags
|
||||
ifupdownFlags.FORCE = force
|
||||
ifupdownFlags.DRYRUN = dryrun
|
||||
ifupdownFlags.NOWAIT = nowait
|
||||
ifupdownFlags.PERFMODE = perfmode
|
||||
ifupdownFlags.CACHE = cache
|
||||
|
||||
self.ifaces = OrderedDict()
|
||||
self.njobs = njobs
|
||||
self.pp = pprint.PrettyPrinter(indent=4)
|
||||
@ -826,12 +810,7 @@ class ifupdownMain(ifupdownBase):
|
||||
mclass = getattr(m, mname)
|
||||
except:
|
||||
raise
|
||||
minstance = mclass(force=self.FORCE,
|
||||
dryrun=self.DRYRUN,
|
||||
nowait=self.NOWAIT,
|
||||
perfmode=self.PERFMODE,
|
||||
cache=self.CACHE,
|
||||
cacheflags=self.CACHE_FLAGS)
|
||||
minstance = mclass()
|
||||
self.modules[mname] = minstance
|
||||
try:
|
||||
self.module_attrs[mname] = minstance.get_modinfo()
|
||||
@ -1157,7 +1136,7 @@ class ifupdownMain(ifupdownBase):
|
||||
if self.flags.WITH_DEPENDS else False)
|
||||
finally:
|
||||
self._process_delay_admin_state_queue('up')
|
||||
if not self.DRYRUN and self.flags.ADDONS_ENABLE:
|
||||
if not ifupdownflags.flags.DRYRUN and self.flags.ADDONS_ENABLE:
|
||||
self._save_state()
|
||||
|
||||
if not iface_read_ret or not ret:
|
||||
@ -1224,7 +1203,7 @@ class ifupdownMain(ifupdownBase):
|
||||
if self.flags.WITH_DEPENDS else False)
|
||||
finally:
|
||||
self._process_delay_admin_state_queue('down')
|
||||
if not self.DRYRUN and self.flags.ADDONS_ENABLE:
|
||||
if not ifupdownflags.flags.DRYRUN and self.flags.ADDONS_ENABLE:
|
||||
self._save_state()
|
||||
|
||||
def query(self, ops, auto=False, allow_classes=None, ifacenames=None,
|
||||
@ -1390,7 +1369,7 @@ class ifupdownMain(ifupdownBase):
|
||||
ret = self._sched_ifaces(interfaces_to_up, upops,
|
||||
followdependents=True
|
||||
if self.flags.WITH_DEPENDS else False)
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
self._save_state()
|
||||
|
||||
@ -1579,7 +1558,7 @@ class ifupdownMain(ifupdownBase):
|
||||
pass
|
||||
finally:
|
||||
self._process_delay_admin_state_queue('up')
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
self._save_state()
|
||||
|
||||
|
@ -12,7 +12,7 @@ from socket import AF_BRIDGE
|
||||
from iff import IFF_UP
|
||||
from rtnetlink import *
|
||||
import os
|
||||
import ifupdownmain
|
||||
import ifupdownflags as ifupdownflags
|
||||
|
||||
class rtnetlinkApi(RtNetlink):
|
||||
|
||||
@ -42,7 +42,7 @@ class rtnetlinkApi(RtNetlink):
|
||||
|
||||
def create_vlan(self, link, ifname, vlanid):
|
||||
self.logger.info('rtnetlink: ip link add link %s name %s type vlan id %s' %(link, ifname, vlanid))
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
try:
|
||||
ifindex = self.get_ifindex(link)
|
||||
@ -66,7 +66,7 @@ class rtnetlinkApi(RtNetlink):
|
||||
|
||||
def create_macvlan(self, ifname, link, mode='private'):
|
||||
self.logger.info('rtnetlink: ip link add link %s name %s type macvlan mode private' %(link, ifname))
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
try:
|
||||
ifindex = self.get_ifindex(link)
|
||||
@ -91,7 +91,7 @@ class rtnetlinkApi(RtNetlink):
|
||||
def link_set(self, ifname, state):
|
||||
flags = 0
|
||||
self.logger.info('rtnetlink: ip link set dev %s %s' %(ifname, state))
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
|
||||
if state == "up":
|
||||
@ -106,9 +106,8 @@ class rtnetlinkApi(RtNetlink):
|
||||
self.process_wait([token])
|
||||
|
||||
def link_set_protodown(self, ifname, state):
|
||||
flags = 0
|
||||
self.logger.info('rtnetlink: setting link %s protodown %s' %(ifname, state))
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
|
||||
protodown = 1 if state == "on" else 0
|
||||
@ -123,7 +122,7 @@ class rtnetlinkApi(RtNetlink):
|
||||
def link_set_hwaddress(self, ifname, hwaddress):
|
||||
flags = 0
|
||||
self.logger.info('rtnetlink: ip link set dev %s address %s' %(ifname, hwaddress))
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
|
||||
flags &= ~IFF_UP
|
||||
@ -139,7 +138,7 @@ class rtnetlinkApi(RtNetlink):
|
||||
def addr_add(self, ifname, address, broadcast=None, peer=None, scope=None,
|
||||
preferred_lifetime=None):
|
||||
self.logger.info('rtnetlink: setting address')
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
|
||||
try:
|
||||
@ -176,7 +175,7 @@ class rtnetlinkApi(RtNetlink):
|
||||
ifi_change = IFF_UP
|
||||
rtas = {}
|
||||
self.logger.info('rtnetlink: setting link %s %s' %(ifname, state))
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
if not ifattrs:
|
||||
return
|
||||
@ -214,7 +213,7 @@ class rtnetlinkApi(RtNetlink):
|
||||
%(vid, 'untagged' if untagged else '',
|
||||
'pvid' if pvid else '', dev,
|
||||
'self' if not master else ''))
|
||||
if ifupdownmain.ifupdownFlags.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
try:
|
||||
ifindex = self.get_ifindex(dev)
|
||||
|
@ -8,6 +8,7 @@
|
||||
#
|
||||
|
||||
from statemanager import *
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
from iface import *
|
||||
from graph import *
|
||||
from collections import deque
|
||||
@ -179,7 +180,7 @@ class ifaceScheduler():
|
||||
if (ifupdownobj.flags.SCHED_SKIP_CHECK_UPPERIFACES):
|
||||
return True
|
||||
|
||||
if (ifupdownobj.FORCE or
|
||||
if (ifupdownflags.flags.FORCE or
|
||||
not ifupdownobj.flags.ADDONS_ENABLE or
|
||||
(not ifupdownobj.is_ifaceobj_noconfig(ifaceobj) and
|
||||
ifupdownobj.config.get('warn_on_ifdown', '0') == '0' and
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
from ifupdown.iface import *
|
||||
from utilsbase import *
|
||||
from iproute2 import *
|
||||
@ -19,7 +20,7 @@ class bondutil(utilsBase):
|
||||
|
||||
def __init__(self, *args, **kargs):
|
||||
utilsBase.__init__(self, *args, **kargs)
|
||||
if self.CACHE and not self._cache_fill_done:
|
||||
if ifupdownflags.flags.CACHE and not self._cache_fill_done:
|
||||
self._bond_linkinfo_fill_all()
|
||||
self._cache_fill_done = True
|
||||
|
||||
@ -79,9 +80,9 @@ class bondutil(utilsBase):
|
||||
|
||||
def _cache_get(self, attrlist, refresh=False):
|
||||
try:
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return None
|
||||
if self.CACHE:
|
||||
if ifupdownflags.flags.CACHE:
|
||||
if not bondutil._cache_fill_done:
|
||||
self._bond_linkinfo_fill_all()
|
||||
bondutil._cache_fill_done = True
|
||||
@ -108,7 +109,7 @@ class bondutil(utilsBase):
|
||||
return False
|
||||
|
||||
def _cache_update(self, attrlist, value):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
try:
|
||||
if attrlist[-1] == 'slaves':
|
||||
linkCache.add_to_attrlist(attrlist, value)
|
||||
@ -118,7 +119,7 @@ class bondutil(utilsBase):
|
||||
pass
|
||||
|
||||
def _cache_delete(self, attrlist, value=None):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
try:
|
||||
if attrlist[-1] == 'slaves':
|
||||
linkCache.remove_from_attrlist(attrlist, value)
|
||||
@ -128,7 +129,7 @@ class bondutil(utilsBase):
|
||||
pass
|
||||
|
||||
def _cache_invalidate(self):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
linkCache.invalidate()
|
||||
|
||||
def set_attrs(self, bondname, attrdict, prehook):
|
||||
@ -147,7 +148,7 @@ class bondutil(utilsBase):
|
||||
self.write_file('/sys/class/net/%s/bonding/%s'
|
||||
%(bondname, attrname), attrval)
|
||||
except Exception, e:
|
||||
if self.FORCE:
|
||||
if ifupdownflags.flags.FORCE:
|
||||
self.logger.warn(str(e))
|
||||
pass
|
||||
else:
|
||||
@ -323,7 +324,7 @@ class bondutil(utilsBase):
|
||||
try:
|
||||
self.remove_slave(bondname, slave)
|
||||
except Exception, e:
|
||||
if not self.FORCE:
|
||||
if not ifupdownflags.flags.FORCE:
|
||||
raise Exception('error removing slave %s'
|
||||
%slave + ' from bond %s' %bondname +
|
||||
'(%s)' %str(e))
|
||||
|
@ -9,6 +9,7 @@ from utilsbase import *
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
from cache import *
|
||||
|
||||
class brctl(utilsBase):
|
||||
@ -19,7 +20,7 @@ class brctl(utilsBase):
|
||||
|
||||
def __init__(self, *args, **kargs):
|
||||
utilsBase.__init__(self, *args, **kargs)
|
||||
if self.CACHE and not brctl._cache_fill_done:
|
||||
if ifupdownflags.flags.CACHE and not brctl._cache_fill_done:
|
||||
self._bridge_fill()
|
||||
brctl._cache_fill_done = True
|
||||
|
||||
@ -147,9 +148,9 @@ class brctl(utilsBase):
|
||||
|
||||
def _cache_get(self, attrlist, refresh=False):
|
||||
try:
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return None
|
||||
if self.CACHE:
|
||||
if ifupdownflags.flags.CACHE:
|
||||
if not self._cache_fill_done:
|
||||
self._bridge_fill()
|
||||
self._cache_fill_done = True
|
||||
@ -176,21 +177,21 @@ class brctl(utilsBase):
|
||||
return False
|
||||
|
||||
def _cache_update(self, attrlist, value):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
try:
|
||||
linkCache.add_attr(attrlist, value)
|
||||
except:
|
||||
pass
|
||||
|
||||
def _cache_delete(self, attrlist):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
try:
|
||||
linkCache.del_attr(attrlist)
|
||||
except:
|
||||
pass
|
||||
|
||||
def _cache_invalidate(self):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
linkCache.invalidate()
|
||||
|
||||
def create_bridge(self, bridgename):
|
||||
@ -230,7 +231,7 @@ class brctl(utilsBase):
|
||||
'ports', bridgeportname])
|
||||
if portattrs == None: portattrs = {}
|
||||
for k, v in attrdict.iteritems():
|
||||
if self.CACHE:
|
||||
if ifupdownflags.flags.CACHE:
|
||||
curval = portattrs.get(k)
|
||||
if curval and curval == v:
|
||||
continue
|
||||
|
@ -14,6 +14,7 @@ from collections import OrderedDict
|
||||
from utilsbase import *
|
||||
from systemutils import *
|
||||
from cache import *
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
|
||||
VXLAN_UDP_PORT = 4789
|
||||
|
||||
@ -28,7 +29,7 @@ class iproute2(utilsBase):
|
||||
|
||||
def __init__(self, *args, **kargs):
|
||||
utilsBase.__init__(self, *args, **kargs)
|
||||
if self.CACHE:
|
||||
if ifupdownflags.flags.CACHE:
|
||||
self._fill_cache()
|
||||
|
||||
def _fill_cache(self):
|
||||
@ -181,9 +182,9 @@ class iproute2(utilsBase):
|
||||
|
||||
def _cache_get(self, type, attrlist, refresh=False):
|
||||
try:
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return False
|
||||
if self.CACHE:
|
||||
if ifupdownflags.flags.CACHE:
|
||||
if self._fill_cache():
|
||||
# if we filled the cache, return new data
|
||||
return linkCache.get_attr(attrlist)
|
||||
@ -215,14 +216,14 @@ class iproute2(utilsBase):
|
||||
return False
|
||||
|
||||
def _cache_update(self, attrlist, value):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
try:
|
||||
linkCache.add_attr(attrlist, value)
|
||||
except:
|
||||
pass
|
||||
|
||||
def _cache_delete(self, attrlist):
|
||||
if self.DRYRUN: return
|
||||
if ifupdownflags.flags.DRYRUN: return
|
||||
try:
|
||||
linkCache.del_attr(attrlist)
|
||||
except:
|
||||
@ -590,7 +591,7 @@ class iproute2(utilsBase):
|
||||
self._cache_update([name], {})
|
||||
|
||||
def link_exists(self, ifacename):
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return True
|
||||
return os.path.exists('/sys/class/net/%s' %ifacename)
|
||||
|
||||
|
@ -16,11 +16,7 @@ import shlex
|
||||
from ifupdown.utils import utils
|
||||
from ifupdown.iface import *
|
||||
import ifupdown.policymanager as policymanager
|
||||
#from ifupdownaddons.iproute2 import *
|
||||
#from ifupdownaddons.dhclient import *
|
||||
#from ifupdownaddons.bridgeutils import *
|
||||
#from ifupdownaddons.mstpctlutil import *
|
||||
#from ifupdownaddons.bondutil import *
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
|
||||
class moduleBase(object):
|
||||
""" Base class for ifupdown addon modules
|
||||
@ -30,14 +26,6 @@ class moduleBase(object):
|
||||
def __init__(self, *args, **kargs):
|
||||
modulename = self.__class__.__name__
|
||||
self.logger = logging.getLogger('ifupdown.' + modulename)
|
||||
self.FORCE = kargs.get('force', False)
|
||||
"""force interface configuration"""
|
||||
self.DRYRUN = kargs.get('dryrun', False)
|
||||
"""only predend you are applying configuration, dont really do it"""
|
||||
self.NOWAIT = kargs.get('nowait', False)
|
||||
self.PERFMODE = kargs.get('perfmode', False)
|
||||
self.CACHE = kargs.get('cache', False)
|
||||
self.CACHE_FLAGS = kargs.get('cacheflags', 0x0)
|
||||
|
||||
# vrfs are a global concept and a vrf context can be applicable
|
||||
# to all global vrf commands. Get the default vrf-exec-cmd-prefix
|
||||
@ -87,7 +75,7 @@ class moduleBase(object):
|
||||
|
||||
try:
|
||||
self.logger.info('Executing ' + cmd)
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return cmdout
|
||||
ch = subprocess.Popen(shlex.split(cmd),
|
||||
stdout=subprocess.PIPE,
|
||||
@ -120,7 +108,7 @@ class moduleBase(object):
|
||||
|
||||
try:
|
||||
self.logger.info('Executing %s (stdin=%s)' %(cmd, stdinbuf))
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return cmdout
|
||||
ch = subprocess.Popen(shlex.split(cmd),
|
||||
stdout=subprocess.PIPE,
|
||||
@ -270,7 +258,7 @@ class moduleBase(object):
|
||||
return portlist
|
||||
|
||||
def ignore_error(self, errmsg):
|
||||
if (self.FORCE or re.search(r'exists', errmsg,
|
||||
if (ifupdownflags.flags.FORCE or re.search(r'exists', errmsg,
|
||||
re.IGNORECASE | re.MULTILINE)):
|
||||
return True
|
||||
return False
|
||||
@ -280,7 +268,7 @@ class moduleBase(object):
|
||||
try:
|
||||
self.logger.info('writing \'%s\'' %strexpr +
|
||||
' to file %s' %filename)
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return 0
|
||||
with open(filename, 'w') as f:
|
||||
f.write(strexpr)
|
||||
@ -390,11 +378,6 @@ class moduleBase(object):
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_flags(self):
|
||||
return dict(force=self.FORCE, dryrun=self.DRYRUN, nowait=self.NOWAIT,
|
||||
perfmode=self.PERFMODE, cache=self.CACHE,
|
||||
cacheflags=self.CACHE_FLAGS)
|
||||
|
||||
def _get_reserved_vlan_range(self):
|
||||
start = end = 0
|
||||
get_resvvlan = '/usr/share/python-ifupdown2/get_reserved_vlan_range.sh'
|
||||
|
@ -12,10 +12,9 @@ import signal
|
||||
import shlex
|
||||
|
||||
from ifupdown.utils import utils
|
||||
import ifupdown.ifupdownflags as ifupdownflags
|
||||
from ifupdown.iface import *
|
||||
from cache import *
|
||||
|
||||
#import timeit
|
||||
import time
|
||||
import logging
|
||||
|
||||
@ -34,11 +33,6 @@ class utilsBase(object):
|
||||
def __init__(self, *args, **kargs):
|
||||
modulename = self.__class__.__name__
|
||||
self.logger = logging.getLogger('ifupdown.' + modulename)
|
||||
self.FORCE = kargs.get('force', False)
|
||||
self.DRYRUN = kargs.get('dryrun', False)
|
||||
self.NOWAIT = kargs.get('nowait', False)
|
||||
self.PERFMODE = kargs.get('perfmode', False)
|
||||
self.CACHE = kargs.get('cache', False)
|
||||
|
||||
def exec_commandl(self, cmdl, cmdenv=None):
|
||||
""" Executes command """
|
||||
@ -47,7 +41,7 @@ class utilsBase(object):
|
||||
cmdout = ''
|
||||
try:
|
||||
self.logger.info('executing ' + ' '.join(cmdl))
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return cmdout
|
||||
ch = subprocess.Popen(cmdl,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -78,7 +72,7 @@ class utilsBase(object):
|
||||
cmdout = ''
|
||||
try:
|
||||
self.logger.info('executing %s [%s]' %(cmd, stdinbuf))
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return cmdout
|
||||
ch = subprocess.Popen(shlex.split(cmd),
|
||||
stdout=subprocess.PIPE,
|
||||
@ -101,7 +95,7 @@ class utilsBase(object):
|
||||
|
||||
def subprocess_check_output(self, cmdl):
|
||||
self.logger.info('executing ' + ' '.join(cmdl))
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
try:
|
||||
return subprocess.check_output(cmdl, stderr=subprocess.STDOUT)
|
||||
@ -118,7 +112,7 @@ class utilsBase(object):
|
||||
cmd_returncode = 0
|
||||
try:
|
||||
self.logger.info('executing ' + ' '.join(cmdl))
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return
|
||||
ch = subprocess.Popen(cmdl,
|
||||
stdout=None,
|
||||
@ -141,7 +135,7 @@ class utilsBase(object):
|
||||
try:
|
||||
self.logger.info('writing \'%s\'' %strexpr +
|
||||
' to file %s' %filename)
|
||||
if self.DRYRUN:
|
||||
if ifupdownflags.flags.DRYRUN:
|
||||
return 0
|
||||
with open(filename, 'w') as f:
|
||||
f.write(strexpr)
|
||||
|
Reference in New Issue
Block a user