2019-12-17 16:40:10 +01:00
|
|
|
#!/usr/bin/env python3
|
2014-10-09 16:02:46 -07:00
|
|
|
#
|
2018-12-13 11:43:32 -08:00
|
|
|
# Copyright 2014-2017 Cumulus Networks, Inc. All rights reserved.
|
2014-10-09 16:02:46 -07:00
|
|
|
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
|
|
|
#
|
|
|
|
|
2018-12-13 11:43:32 -08:00
|
|
|
import re
|
|
|
|
import time
|
2019-12-17 01:04:54 +01:00
|
|
|
import socket
|
2018-12-13 11:43:32 -08:00
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
try:
|
2019-12-17 01:04:54 +01:00
|
|
|
from ifupdown2.lib.addon import Addon
|
2020-05-13 16:58:24 +02:00
|
|
|
from ifupdown2.lib.log import LogManager
|
2019-12-17 01:04:54 +01:00
|
|
|
|
2018-12-13 11:43:32 -08:00
|
|
|
import ifupdown2.ifupdown.policymanager as policymanager
|
|
|
|
import ifupdown2.ifupdown.ifupdownflags as ifupdownflags
|
|
|
|
|
|
|
|
from ifupdown2.ifupdown.iface import *
|
|
|
|
from ifupdown2.ifupdown.utils import utils
|
|
|
|
|
|
|
|
from ifupdown2.ifupdownaddons.dhclient import dhclient
|
|
|
|
from ifupdown2.ifupdownaddons.modulebase import moduleBase
|
2019-12-17 17:25:32 +01:00
|
|
|
except (ImportError, ModuleNotFoundError):
|
2019-12-17 01:04:54 +01:00
|
|
|
from lib.addon import Addon
|
2020-05-13 16:58:24 +02:00
|
|
|
from lib.log import LogManager
|
2019-12-17 01:04:54 +01:00
|
|
|
|
ifupdown2: Add nowait attribute for dhcp addon
Ticket: None
Reviewed By: CCR-4058
Testing Done: ifup'd interface with both nowait=0 and nowait=1 and not specified
at all.
The Mellanox platform, as well as some others probably, has two management
interfaces: eth0 and eth1. The customer may plug a cable into either one of
these interfaces, and very rarely both of them. If only one cable is plugged in
and we don't know which one, then /etc/network/interfaces must be configured
by default to automatically bring up both interfaces using DHCP. But when an
interface does not have link, it stalls the boot process for 60 seconds while
dhclient times out.
This patch changes the default dhclient behavior to not wait for DHCP to
complete, by using the "-nw" option when calling dhclient. This means that
dhclient will immediately return and DHCP will complete in the background.
A module attribute has been added for the DHCP addon called "nowait", which
defaults to 1. If this attribute is set to 0, then dhclient will revert to its
previous behavior and delay up to a minute while DHCP completes. This attribute
can be specified in a policy file, e.g. /etc/network/ifupdown2/policy.d/dhcp.json,
with contents such as:
{
"dhcp" :
{
"nowait" : 0
}
}
2016-02-01 16:42:14 -08:00
|
|
|
import ifupdown.policymanager as policymanager
|
2016-04-14 14:45:47 -07:00
|
|
|
import ifupdown.ifupdownflags as ifupdownflags
|
2018-12-13 11:43:32 -08:00
|
|
|
|
|
|
|
from ifupdown.iface import *
|
2016-07-15 14:21:23 -07:00
|
|
|
from ifupdown.utils import utils
|
2018-12-13 11:43:32 -08:00
|
|
|
|
|
|
|
from ifupdownaddons.dhclient import dhclient
|
|
|
|
from ifupdownaddons.modulebase import moduleBase
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2019-12-17 01:04:54 +01:00
|
|
|
class dhcp(Addon, moduleBase):
|
2014-10-09 16:02:46 -07:00
|
|
|
""" ifupdown2 addon module to configure dhcp on interface """
|
|
|
|
|
2020-05-13 16:58:24 +02:00
|
|
|
# by default we won't perform any dhcp retry
|
|
|
|
# this can be changed by setting the module global
|
|
|
|
# policy: dhclient_retry_on_failure
|
|
|
|
DHCLIENT_RETRY_ON_FAILURE = 0
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
def __init__(self, *args, **kargs):
|
2019-12-17 01:04:54 +01:00
|
|
|
Addon.__init__(self)
|
2014-10-09 16:02:46 -07:00
|
|
|
moduleBase.__init__(self, *args, **kargs)
|
|
|
|
self.dhclientcmd = dhclient(**kargs)
|
|
|
|
|
2020-01-13 11:17:26 -08:00
|
|
|
vrf_id = self._get_vrf_context()
|
|
|
|
if vrf_id and vrf_id == 'mgmt':
|
|
|
|
self.mgmt_vrf_context = True
|
|
|
|
else:
|
|
|
|
self.mgmt_vrf_context = False
|
|
|
|
self.logger.info('mgmt vrf_context = %s' %self.mgmt_vrf_context)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2020-05-13 16:58:24 +02:00
|
|
|
try:
|
|
|
|
self.dhclient_retry_on_failure = int(
|
|
|
|
policymanager.policymanager_api.get_module_globals(
|
|
|
|
module_name=self.__class__.__name__,
|
|
|
|
attr="dhclient_retry_on_failure"
|
|
|
|
)
|
|
|
|
)
|
2020-06-24 01:12:24 +02:00
|
|
|
except Exception:
|
2020-05-13 16:58:24 +02:00
|
|
|
self.dhclient_retry_on_failure = self.DHCLIENT_RETRY_ON_FAILURE
|
|
|
|
|
|
|
|
if self.dhclient_retry_on_failure < 0:
|
|
|
|
self.dhclient_retry_on_failure = 0
|
|
|
|
|
|
|
|
self.logger.info("dhclient: dhclient_retry_on_failure set to %s" % self.dhclient_retry_on_failure)
|
|
|
|
|
2016-11-22 17:06:16 +01:00
|
|
|
def syntax_check(self, ifaceobj, ifaceobj_getfunc):
|
|
|
|
return self.is_dhcp_allowed_on(ifaceobj, syntax_check=True)
|
|
|
|
|
|
|
|
def is_dhcp_allowed_on(self, ifaceobj, syntax_check):
|
|
|
|
if ifaceobj.addr_method and 'dhcp' in ifaceobj.addr_method:
|
|
|
|
return utils.is_addr_ip_allowed_on(ifaceobj, syntax_check=True)
|
|
|
|
return True
|
|
|
|
|
2020-05-13 16:58:24 +02:00
|
|
|
def get_current_ip_configured(self, ifname, family):
|
|
|
|
ips = set()
|
|
|
|
try:
|
|
|
|
a = utils.exec_commandl(["ip", "-o", "addr", "show", ifname]).split("\n")
|
|
|
|
|
|
|
|
for entry in a:
|
|
|
|
family_index = entry.find(family)
|
|
|
|
|
|
|
|
if family_index < 0:
|
|
|
|
continue
|
|
|
|
|
|
|
|
tmp = entry[entry.find(family) + len(family) + 1:]
|
|
|
|
ip = tmp[:tmp.find(" ")]
|
|
|
|
|
|
|
|
if ip:
|
|
|
|
ips.add(ip)
|
2020-06-24 01:12:24 +02:00
|
|
|
except Exception:
|
2020-05-13 16:58:24 +02:00
|
|
|
pass
|
|
|
|
return ips
|
|
|
|
|
|
|
|
def dhclient_start_and_check(self, ifname, family, handler, **handler_kwargs):
|
|
|
|
ip_config_before = self.get_current_ip_configured(ifname, family)
|
|
|
|
retry = self.dhclient_retry_on_failure
|
|
|
|
|
|
|
|
while retry >= 0:
|
|
|
|
handler(ifname, **handler_kwargs)
|
|
|
|
retry = self.dhclient_check(ifname, family, ip_config_before, retry, handler_kwargs.get("cmd_prefix"))
|
|
|
|
|
|
|
|
def dhclient_check(self, ifname, family, ip_config_before, retry, dhclient_cmd_prefix):
|
|
|
|
diff = self.get_current_ip_configured(ifname, family).difference(ip_config_before)
|
|
|
|
|
|
|
|
if diff:
|
|
|
|
self.logger.info(
|
|
|
|
"%s: dhclient: new address%s detected: %s"
|
|
|
|
% (ifname, "es" if len(diff) > 1 else "", ", ".join(diff))
|
|
|
|
)
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
if retry > 0:
|
|
|
|
self.logger.error(
|
|
|
|
"%s: dhclient: couldn't detect new ip address, retrying %s more times..."
|
|
|
|
% (ifname, retry)
|
|
|
|
)
|
2020-10-26 02:15:29 +01:00
|
|
|
self.dhclientcmd.stop(ifname)
|
2020-05-13 16:58:24 +02:00
|
|
|
else:
|
2020-07-06 02:43:26 +02:00
|
|
|
self.logger.error("%s: dhclient: timeout failed to detect new ip addresses" % ifname)
|
|
|
|
return -1
|
2020-10-26 02:15:29 +01:00
|
|
|
retry -= 1
|
2020-05-13 16:58:24 +02:00
|
|
|
return retry
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
def _up(self, ifaceobj):
|
2015-06-30 13:47:08 -04:00
|
|
|
# if dhclient is already running do not stop and start it
|
2016-12-02 00:39:35 +01:00
|
|
|
dhclient4_running = self.dhclientcmd.is_running(ifaceobj.name)
|
|
|
|
dhclient6_running = self.dhclientcmd.is_running6(ifaceobj.name)
|
2016-12-02 07:15:09 +01:00
|
|
|
|
|
|
|
# today if we have an interface with both inet and inet6, if we
|
|
|
|
# remove the inet or inet6 or both then execute ifreload, we need
|
|
|
|
# to release/kill the appropriate dhclient(4/6) if they are running
|
|
|
|
self._down_stale_dhcp_config(ifaceobj, 'inet', dhclient4_running)
|
|
|
|
self._down_stale_dhcp_config(ifaceobj, 'inet6', dhclient6_running)
|
|
|
|
|
2020-07-21 22:05:48 +02:00
|
|
|
if ifaceobj.link_privflags & ifaceLinkPrivFlags.KEEP_LINK_DOWN:
|
|
|
|
self.logger.info("%s: skipping dhcp configuration: link-down yes" % ifaceobj.name)
|
|
|
|
return
|
|
|
|
|
2014-10-09 16:02:46 -07:00
|
|
|
try:
|
2016-04-05 16:11:41 -07:00
|
|
|
dhclient_cmd_prefix = None
|
2016-02-03 16:38:18 -08:00
|
|
|
dhcp_wait = policymanager.policymanager_api.get_attr_default(
|
|
|
|
module_name=self.__class__.__name__, attr='dhcp-wait')
|
|
|
|
wait = not str(dhcp_wait).lower() == "no"
|
2019-06-11 06:29:43 -04:00
|
|
|
dhcp6_ll_wait = policymanager.policymanager_api.get_iface_default(module_name=self.__class__.__name__, \
|
|
|
|
ifname=ifaceobj.name, attr='dhcp6-ll-wait')
|
2019-05-29 10:25:29 -04:00
|
|
|
try:
|
2019-06-11 06:29:43 -04:00
|
|
|
timeout = int(dhcp6_ll_wait)+1
|
2020-06-24 01:12:24 +02:00
|
|
|
except Exception:
|
2019-06-11 06:29:43 -04:00
|
|
|
timeout = 10
|
2019-05-29 10:25:29 -04:00
|
|
|
pass
|
2019-07-06 15:14:38 -07:00
|
|
|
dhcp6_duid = policymanager.policymanager_api.get_iface_default(module_name=self.__class__.__name__, \
|
|
|
|
ifname=ifaceobj.name, attr='dhcp6-duid')
|
2016-04-05 16:11:41 -07:00
|
|
|
vrf = ifaceobj.get_attr_value_first('vrf')
|
2016-04-17 23:45:59 -07:00
|
|
|
if (vrf and self.vrf_exec_cmd_prefix and
|
2019-12-17 01:04:54 +01:00
|
|
|
self.cache.link_exists(vrf)):
|
2016-04-05 16:11:41 -07:00
|
|
|
dhclient_cmd_prefix = '%s %s' %(self.vrf_exec_cmd_prefix, vrf)
|
2020-01-17 12:45:39 -08:00
|
|
|
elif self.mgmt_vrf_context:
|
|
|
|
dhclient_cmd_prefix = '%s %s' %(self.vrf_exec_cmd_prefix, 'default')
|
|
|
|
self.logger.info('detected mgmt vrf context starting dhclient in default vrf context')
|
2016-04-05 16:11:41 -07:00
|
|
|
|
2016-11-15 18:33:07 +01:00
|
|
|
if 'inet' in ifaceobj.addr_family:
|
2016-12-02 00:39:35 +01:00
|
|
|
if dhclient4_running:
|
|
|
|
self.logger.info('dhclient4 already running on %s. '
|
|
|
|
'Not restarting.' % ifaceobj.name)
|
|
|
|
else:
|
|
|
|
# First release any existing dhclient processes
|
2014-10-09 16:02:46 -07:00
|
|
|
try:
|
2016-12-02 00:39:35 +01:00
|
|
|
if not ifupdownflags.flags.PERFMODE:
|
|
|
|
self.dhclientcmd.stop(ifaceobj.name)
|
2020-06-24 01:12:24 +02:00
|
|
|
except Exception:
|
2014-10-09 16:02:46 -07:00
|
|
|
pass
|
2020-05-13 16:58:24 +02:00
|
|
|
|
|
|
|
self.dhclient_start_and_check(
|
|
|
|
ifaceobj.name,
|
|
|
|
"inet",
|
|
|
|
self.dhclientcmd.start,
|
|
|
|
wait=wait,
|
|
|
|
cmd_prefix=dhclient_cmd_prefix
|
|
|
|
)
|
|
|
|
|
2016-12-02 00:39:35 +01:00
|
|
|
if 'inet6' in ifaceobj.addr_family:
|
|
|
|
if dhclient6_running:
|
|
|
|
self.logger.info('dhclient6 already running on %s. '
|
|
|
|
'Not restarting.' % ifaceobj.name)
|
|
|
|
else:
|
|
|
|
accept_ra = ifaceobj.get_attr_value_first('accept_ra')
|
|
|
|
if accept_ra:
|
|
|
|
# XXX: Validate value
|
|
|
|
self.sysctl_set('net.ipv6.conf.%s' %ifaceobj.name +
|
|
|
|
'.accept_ra', accept_ra)
|
|
|
|
autoconf = ifaceobj.get_attr_value_first('autoconf')
|
|
|
|
if autoconf:
|
|
|
|
# XXX: Validate value
|
|
|
|
self.sysctl_set('net.ipv6.conf.%s' %ifaceobj.name +
|
|
|
|
'.autoconf', autoconf)
|
|
|
|
try:
|
2019-07-06 15:14:38 -07:00
|
|
|
self.dhclientcmd.stop6(ifaceobj.name, duid=dhcp6_duid)
|
2020-06-24 01:12:24 +02:00
|
|
|
except Exception:
|
2016-12-02 00:39:35 +01:00
|
|
|
pass
|
|
|
|
#add delay before starting IPv6 dhclient to
|
|
|
|
#make sure the configured interface/link is up.
|
2019-06-11 06:29:43 -04:00
|
|
|
if timeout > 1:
|
2019-12-17 01:04:54 +01:00
|
|
|
time.sleep(1)
|
2016-12-02 00:39:35 +01:00
|
|
|
while timeout:
|
2018-12-13 11:43:32 -08:00
|
|
|
addr_output = utils.exec_command('%s -6 addr show %s'
|
|
|
|
%(utils.ip_cmd, ifaceobj.name))
|
2016-12-02 00:39:35 +01:00
|
|
|
r = re.search('inet6 .* scope link', addr_output)
|
|
|
|
if r:
|
|
|
|
self.dhclientcmd.start6(ifaceobj.name,
|
|
|
|
wait=wait,
|
2019-07-06 15:14:38 -07:00
|
|
|
cmd_prefix=dhclient_cmd_prefix, duid=dhcp6_duid)
|
2016-12-02 00:39:35 +01:00
|
|
|
return
|
2019-05-29 10:25:29 -04:00
|
|
|
timeout -= 1
|
|
|
|
if timeout:
|
|
|
|
time.sleep(1)
|
2019-12-17 16:55:49 +01:00
|
|
|
except Exception as e:
|
2020-05-13 16:58:24 +02:00
|
|
|
self.logger.error("%s: %s" % (ifaceobj.name, str(e)))
|
|
|
|
ifaceobj.set_status(ifaceStatus.ERROR)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2016-12-02 07:15:09 +01:00
|
|
|
def _down_stale_dhcp_config(self, ifaceobj, family, dhclientX_running):
|
|
|
|
addr_family = ifaceobj.addr_family
|
|
|
|
try:
|
|
|
|
if not family in ifaceobj.addr_family and dhclientX_running:
|
|
|
|
ifaceobj.addr_family = [family]
|
|
|
|
self._dhcp_down(ifaceobj)
|
2020-06-24 01:12:24 +02:00
|
|
|
except Exception:
|
2016-12-02 07:15:09 +01:00
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
ifaceobj.addr_family = addr_family
|
|
|
|
|
|
|
|
def _dhcp_down(self, ifaceobj):
|
2016-04-05 16:11:41 -07:00
|
|
|
dhclient_cmd_prefix = None
|
|
|
|
vrf = ifaceobj.get_attr_value_first('vrf')
|
2016-04-17 23:45:59 -07:00
|
|
|
if (vrf and self.vrf_exec_cmd_prefix and
|
2019-12-17 01:04:54 +01:00
|
|
|
self.cache.link_exists(vrf)):
|
2016-04-05 16:11:41 -07:00
|
|
|
dhclient_cmd_prefix = '%s %s' %(self.vrf_exec_cmd_prefix, vrf)
|
2019-07-06 15:14:38 -07:00
|
|
|
dhcp6_duid = policymanager.policymanager_api.get_iface_default(module_name=self.__class__.__name__, \
|
2019-12-17 01:04:54 +01:00
|
|
|
ifname=ifaceobj.name, attr='dhcp6-duid')
|
2016-11-15 18:33:07 +01:00
|
|
|
if 'inet6' in ifaceobj.addr_family:
|
2019-07-06 15:14:38 -07:00
|
|
|
self.dhclientcmd.release6(ifaceobj.name, dhclient_cmd_prefix, duid=dhcp6_duid)
|
2019-12-17 01:04:54 +01:00
|
|
|
self.cache.force_address_flush_family(ifaceobj.name, socket.AF_INET6)
|
2016-11-15 18:33:07 +01:00
|
|
|
if 'inet' in ifaceobj.addr_family:
|
2016-07-15 14:21:23 -07:00
|
|
|
self.dhclientcmd.release(ifaceobj.name, dhclient_cmd_prefix)
|
2019-12-17 01:04:54 +01:00
|
|
|
self.cache.force_address_flush_family(ifaceobj.name, socket.AF_INET)
|
2016-12-02 07:15:09 +01:00
|
|
|
|
|
|
|
def _down(self, ifaceobj):
|
|
|
|
self._dhcp_down(ifaceobj)
|
2019-12-17 01:04:54 +01:00
|
|
|
self.netlink.link_down(ifaceobj.name)
|
2014-10-09 16:02:46 -07:00
|
|
|
|
|
|
|
def _query_check(self, ifaceobj, ifaceobjcurr):
|
2016-11-15 18:33:07 +01:00
|
|
|
status = ifaceStatus.SUCCESS
|
|
|
|
dhcp_running = False
|
|
|
|
|
|
|
|
dhcp_v4 = self.dhclientcmd.is_running(ifaceobjcurr.name)
|
|
|
|
dhcp_v6 = self.dhclientcmd.is_running6(ifaceobjcurr.name)
|
|
|
|
|
|
|
|
if dhcp_v4:
|
|
|
|
dhcp_running = True
|
|
|
|
if 'inet' not in ifaceobj.addr_family and not dhcp_v6:
|
|
|
|
status = ifaceStatus.ERROR
|
2014-10-09 16:02:46 -07:00
|
|
|
ifaceobjcurr.addr_method = 'dhcp'
|
2016-11-15 18:33:07 +01:00
|
|
|
if dhcp_v6:
|
|
|
|
dhcp_running = True
|
|
|
|
if 'inet6' not in ifaceobj.addr_family and not dhcp_v4:
|
|
|
|
status = ifaceStatus.ERROR
|
2014-10-09 16:02:46 -07:00
|
|
|
ifaceobjcurr.addr_method = 'dhcp'
|
2016-11-15 18:33:07 +01:00
|
|
|
ifaceobjcurr.addr_family = ifaceobj.addr_family
|
|
|
|
if not dhcp_running:
|
|
|
|
ifaceobjcurr.addr_family = []
|
|
|
|
status = ifaceStatus.ERROR
|
|
|
|
ifaceobjcurr.status = status
|
2014-10-09 16:02:46 -07:00
|
|
|
|
|
|
|
def _query_running(self, ifaceobjrunning):
|
2019-12-17 01:04:54 +01:00
|
|
|
if not self.cache.link_exists(ifaceobjrunning.name):
|
2014-10-09 16:02:46 -07:00
|
|
|
return
|
|
|
|
if self.dhclientcmd.is_running(ifaceobjrunning.name):
|
2016-11-15 18:33:07 +01:00
|
|
|
ifaceobjrunning.addr_family.append('inet')
|
2014-10-09 16:02:46 -07:00
|
|
|
ifaceobjrunning.addr_method = 'dhcp'
|
2016-11-15 18:33:07 +01:00
|
|
|
if self.dhclientcmd.is_running6(ifaceobjrunning.name):
|
|
|
|
ifaceobjrunning.addr_family.append('inet6')
|
2014-10-09 16:02:46 -07:00
|
|
|
ifaceobjrunning.addr_method = 'dhcp6'
|
|
|
|
|
|
|
|
_run_ops = {'up' : _up,
|
|
|
|
'down' : _down,
|
2016-07-15 14:21:23 -07:00
|
|
|
'pre-down' : _down,
|
2014-10-09 16:02:46 -07:00
|
|
|
'query-checkcurr' : _query_check,
|
|
|
|
'query-running' : _query_running }
|
|
|
|
|
|
|
|
def get_ops(self):
|
|
|
|
""" returns list of ops supported by this module """
|
2019-12-17 16:55:49 +01:00
|
|
|
return list(self._run_ops.keys())
|
2014-10-09 16:02:46 -07:00
|
|
|
|
2014-10-24 10:11:07 -07:00
|
|
|
def run(self, ifaceobj, operation, query_ifaceobj=None, **extra_args):
|
2014-10-09 16:02:46 -07:00
|
|
|
""" run dhcp configuration on the interface object passed as argument
|
|
|
|
|
|
|
|
Args:
|
|
|
|
**ifaceobj** (object): iface object
|
|
|
|
|
|
|
|
**operation** (str): any of 'up', 'down', 'query-checkcurr',
|
|
|
|
'query-running'
|
|
|
|
|
|
|
|
Kwargs:
|
|
|
|
**query_ifaceobj** (object): query check ifaceobject. This is only
|
|
|
|
valid when op is 'query-checkcurr'. It is an object same as
|
|
|
|
ifaceobj, but contains running attribute values and its config
|
|
|
|
status. The modules can use it to return queried running state
|
|
|
|
of interfaces. status is success if the running state is same
|
|
|
|
as user required state in ifaceobj. error otherwise.
|
|
|
|
"""
|
|
|
|
op_handler = self._run_ops.get(operation)
|
|
|
|
if not op_handler:
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
if (operation != 'query-running' and
|
2018-12-13 11:43:32 -08:00
|
|
|
(ifaceobj.addr_method != 'dhcp' and
|
2014-10-09 16:02:46 -07:00
|
|
|
ifaceobj.addr_method != 'dhcp6')):
|
|
|
|
return
|
2020-06-24 01:12:24 +02:00
|
|
|
except Exception:
|
2014-10-09 16:02:46 -07:00
|
|
|
return
|
2016-11-22 17:06:16 +01:00
|
|
|
if not self.is_dhcp_allowed_on(ifaceobj, syntax_check=False):
|
|
|
|
return
|
2020-05-13 16:58:24 +02:00
|
|
|
|
2020-06-04 03:57:14 +02:00
|
|
|
log_manager = LogManager.get_instance()
|
|
|
|
|
|
|
|
syslog_log_level = logging.INFO
|
2020-06-22 18:33:15 +02:00
|
|
|
disable_syslog_on_exit = None
|
|
|
|
|
|
|
|
if operation in ["up", "down"]:
|
2020-06-04 03:57:14 +02:00
|
|
|
# if syslog is already enabled we shouldn't disable it
|
|
|
|
if log_manager.is_syslog_enabled():
|
|
|
|
# save current syslog level
|
|
|
|
syslog_log_level = log_manager.get_syslog_log_level()
|
|
|
|
# prevent syslog from being disabled on exit
|
|
|
|
disable_syslog_on_exit = False
|
|
|
|
else:
|
|
|
|
# enabling syslog
|
|
|
|
log_manager.enable_syslog()
|
|
|
|
# syslog will be disabled once we are done
|
|
|
|
disable_syslog_on_exit = True
|
|
|
|
|
|
|
|
# update the current syslog handler log level if higher than INFO
|
|
|
|
if syslog_log_level >= logging.INFO:
|
|
|
|
log_manager.set_level_syslog(logging.INFO)
|
|
|
|
|
|
|
|
self.logger.info("%s: enabling syslog for dhcp configuration" % ifaceobj.name)
|
2020-05-13 16:58:24 +02:00
|
|
|
|
2020-06-22 18:33:15 +02:00
|
|
|
try:
|
2020-05-13 16:58:24 +02:00
|
|
|
if operation == 'query-checkcurr':
|
|
|
|
op_handler(self, ifaceobj, query_ifaceobj)
|
|
|
|
else:
|
|
|
|
op_handler(self, ifaceobj)
|
|
|
|
finally:
|
2020-06-04 03:57:14 +02:00
|
|
|
# disable syslog handler or re-set the proper log-level
|
2020-06-22 18:33:15 +02:00
|
|
|
if disable_syslog_on_exit is True:
|
2020-06-04 03:57:14 +02:00
|
|
|
log_manager.get_instance().disable_syslog()
|
2020-06-22 18:33:15 +02:00
|
|
|
elif disable_syslog_on_exit is False:
|
2020-06-04 03:57:14 +02:00
|
|
|
log_manager.set_level_syslog(syslog_log_level)
|