Merge pull request #1047 from bcoca/use_common_logging
switched to use module loggigng
This commit is contained in:
commit
9f5420e459
5 changed files with 16 additions and 48 deletions
|
@ -379,7 +379,6 @@ tenant_ip: "192.168.200.21/23"
|
|||
'''
|
||||
# import ansible.module_utils.basic
|
||||
import os
|
||||
import syslog
|
||||
import sys
|
||||
import dbus
|
||||
from gi.repository import NetworkManager, NMClient
|
||||
|
@ -466,14 +465,8 @@ class Nmcli(object):
|
|||
self.flags=module.params['flags']
|
||||
self.ingress=module.params['ingress']
|
||||
self.egress=module.params['egress']
|
||||
# select whether we dump additional debug info through syslog
|
||||
self.syslogging=True
|
||||
|
||||
def execute_command(self, cmd, use_unsafe_shell=False, data=None):
|
||||
if self.syslogging:
|
||||
syslog.openlog('ansible-%s' % os.path.basename(__file__))
|
||||
syslog.syslog(syslog.LOG_NOTICE, 'Command %s' % '|'.join(cmd))
|
||||
|
||||
return self.module.run_command(cmd, use_unsafe_shell=use_unsafe_shell, data=data)
|
||||
|
||||
def merge_secrets(self, proxy, config, setting_name):
|
||||
|
|
|
@ -167,9 +167,7 @@ class OVSBridge(object):
|
|||
|
||||
current_fail_mode = self.get_fail_mode()
|
||||
if self.fail_mode and (self.fail_mode != current_fail_mode):
|
||||
syslog.syslog(syslog.LOG_NOTICE,
|
||||
"changing fail mode %s to %s" %
|
||||
(current_fail_mode, self.fail_mode))
|
||||
self.module.log( "changing fail mode %s to %s" % (current_fail_mode, self.fail_mode))
|
||||
self.set_fail_mode()
|
||||
changed = True
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import syslog
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: openvswitch_port
|
||||
|
@ -99,7 +97,7 @@ def truncate_before(value, srch):
|
|||
return value
|
||||
|
||||
|
||||
def _set_to_get(set_cmd):
|
||||
def _set_to_get(set_cmd, module):
|
||||
""" Convert set command to get command and set value.
|
||||
return tuple (get command, set value)
|
||||
"""
|
||||
|
@ -109,7 +107,7 @@ def _set_to_get(set_cmd):
|
|||
set_cmd = truncate_before(set_cmd, " option:")
|
||||
get_cmd = set_cmd.split(" ")
|
||||
(key, value) = get_cmd[-1].split("=")
|
||||
syslog.syslog(syslog.LOG_NOTICE, "get commands %s " % key)
|
||||
module.log("get commands %s " % key)
|
||||
return (["--", "get"] + get_cmd[:-1] + [key], value)
|
||||
|
||||
|
||||
|
@ -128,7 +126,6 @@ class OVSPort(object):
|
|||
'''Run ovs-vsctl command'''
|
||||
|
||||
cmd = ['ovs-vsctl', '-t', str(self.timeout)] + command
|
||||
syslog.syslog(syslog.LOG_NOTICE, " ".join(cmd))
|
||||
return self.module.run_command(cmd, check_rc=check_rc)
|
||||
|
||||
def exists(self):
|
||||
|
@ -143,11 +140,11 @@ class OVSPort(object):
|
|||
|
||||
def set(self, set_opt):
|
||||
""" Set attributes on a port. """
|
||||
syslog.syslog(syslog.LOG_NOTICE, "set called %s" % set_opt)
|
||||
self.module("set called %s" % set_opt)
|
||||
if (not set_opt):
|
||||
return False
|
||||
|
||||
(get_cmd, set_value) = _set_to_get(set_opt)
|
||||
(get_cmd, set_value) = _set_to_get(set_opt, self.module)
|
||||
(rtc, out, err) = self._vsctl(get_cmd, False)
|
||||
if rtc != 0:
|
||||
##
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
import re
|
||||
import shlex
|
||||
import syslog
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -64,13 +63,8 @@ EXAMPLES = '''
|
|||
- openbsd_pkg: name=* state=latest
|
||||
'''
|
||||
|
||||
# Control if we write debug information to syslog.
|
||||
debug = False
|
||||
|
||||
# Function used for executing commands.
|
||||
def execute_command(cmd, module):
|
||||
if debug:
|
||||
syslog.syslog("execute_command(): cmd = %s" % cmd)
|
||||
# Break command line into arguments.
|
||||
# This makes run_command() use shell=False which we need to not cause shell
|
||||
# expansion of special characters like '*'.
|
||||
|
@ -91,12 +85,10 @@ def get_current_name(name, pkg_spec, module):
|
|||
else:
|
||||
pattern = "^%s-" % pkg_spec['stem']
|
||||
|
||||
if debug:
|
||||
syslog.syslog("get_current_name(): pattern = %s" % pattern)
|
||||
module.debug("get_current_name(): pattern = %s" % pattern)
|
||||
|
||||
for line in stdout.splitlines():
|
||||
if debug:
|
||||
syslog.syslog("get_current_name: line = %s" % line)
|
||||
module.debug("get_current_name: line = %s" % line)
|
||||
match = re.search(pattern, line)
|
||||
if match:
|
||||
current_name = line.split()[0]
|
||||
|
@ -144,14 +136,12 @@ def package_present(name, installed_state, pkg_spec, module):
|
|||
# supplied the tool will exit 0 in both cases:
|
||||
if pkg_spec['version']:
|
||||
# Depend on the return code.
|
||||
if debug:
|
||||
syslog.syslog("package_present(): depending on return code")
|
||||
module.debug("package_present(): depending on return code")
|
||||
if rc:
|
||||
changed=False
|
||||
else:
|
||||
# Depend on stderr instead.
|
||||
if debug:
|
||||
syslog.syslog("package_present(): depending on stderr")
|
||||
module.debug("package_present(): depending on stderr")
|
||||
if stderr:
|
||||
# There is a corner case where having an empty directory in
|
||||
# installpath prior to the right location will result in a
|
||||
|
@ -161,18 +151,15 @@ def package_present(name, installed_state, pkg_spec, module):
|
|||
match = re.search("\W%s-[^:]+: ok\W" % name, stdout)
|
||||
if match:
|
||||
# It turns out we were able to install the package.
|
||||
if debug:
|
||||
syslog.syslog("package_present(): we were able to install package")
|
||||
module.debug("package_present(): we were able to install package")
|
||||
pass
|
||||
else:
|
||||
# We really did fail, fake the return code.
|
||||
if debug:
|
||||
syslog.syslog("package_present(): we really did fail")
|
||||
module.debug("package_present(): we really did fail")
|
||||
rc = 1
|
||||
changed=False
|
||||
else:
|
||||
if debug:
|
||||
syslog.syslog("package_present(): stderr was not set")
|
||||
module.debug("package_present(): stderr was not set")
|
||||
|
||||
if rc == 0:
|
||||
if module.check_mode:
|
||||
|
@ -202,8 +189,7 @@ def package_latest(name, installed_state, pkg_spec, module):
|
|||
# Fetch name of currently installed package.
|
||||
pre_upgrade_name = get_current_name(name, pkg_spec, module)
|
||||
|
||||
if debug:
|
||||
syslog.syslog("package_latest(): pre_upgrade_name = %s" % pre_upgrade_name)
|
||||
module.debug("package_latest(): pre_upgrade_name = %s" % pre_upgrade_name)
|
||||
|
||||
# Attempt to upgrade the package.
|
||||
(rc, stdout, stderr) = execute_command("%s %s" % (upgrade_cmd, name), module)
|
||||
|
@ -237,8 +223,7 @@ def package_latest(name, installed_state, pkg_spec, module):
|
|||
|
||||
else:
|
||||
# If package was not installed at all just make it present.
|
||||
if debug:
|
||||
syslog.syslog("package_latest(): package is not installed, calling package_present()")
|
||||
module.debug("package_latest(): package is not installed, calling package_present()")
|
||||
return package_present(name, installed_state, pkg_spec, module)
|
||||
|
||||
# Function used to make sure a package is not installed.
|
||||
|
|
|
@ -124,8 +124,6 @@ class CronVar(object):
|
|||
self.user = 'root'
|
||||
self.lines = None
|
||||
self.wordchars = ''.join(chr(x) for x in range(128) if chr(x) not in ('=', "'", '"', ))
|
||||
# select whether we dump additional debug info through syslog
|
||||
self.syslogging = False
|
||||
|
||||
if cron_file:
|
||||
self.cron_file = '/etc/cron.d/%s' % cron_file
|
||||
|
@ -165,8 +163,7 @@ class CronVar(object):
|
|||
count += 1
|
||||
|
||||
def log_message(self, message):
|
||||
if self.syslogging:
|
||||
syslog.syslog(syslog.LOG_NOTICE, 'ansible: "%s"' % message)
|
||||
self.module.debug('ansible: "%s"' % message)
|
||||
|
||||
def write(self, backup_file=None):
|
||||
"""
|
||||
|
@ -363,9 +360,7 @@ def main():
|
|||
os.umask(022)
|
||||
cronvar = CronVar(module, user, cron_file)
|
||||
|
||||
if cronvar.syslogging:
|
||||
syslog.openlog('ansible-%s' % os.path.basename(__file__))
|
||||
syslog.syslog(syslog.LOG_NOTICE, 'cronvar instantiated - name: "%s"' % name)
|
||||
module.debug('cronvar instantiated - name: "%s"' % name)
|
||||
|
||||
# --- user input validation ---
|
||||
|
||||
|
|
Loading…
Reference in a new issue