This patch replaces local solutions by standard python logging module. Levels
of messages
is not final, it just reflects the previous state. So, debug level is available
only with
-v / verbose option.
---
fence/agents/amt/fence_amt.py | 33 +++--
fence/agents/cisco_ucs/fence_cisco_ucs.py | 6 ++---
fence/agents/dummy/fence_dummy.py | 3 ++-
fence/agents/eps/fence_eps.py | 15
fence/agents/ipmilan/fence_ipmilan.py | 26 ++--
fence/agents/lib/XenAPI.py.py | 4 ++--
fence/agents/lib/fencing.py.py| 40 +--
fence/agents/lib/fencing_snmp.py.py | 4 ++--
fence/agents/ovh/fence_ovh.py | 16 ++---
fence/agents/rhevm/fence_rhevm.py | 6 ++---
fence/agents/sanbox2/fence_sanbox2.py | 3 ++-
fence/agents/vmware/fence_vmware.py | 4 ++--
12 files changed, 84 insertions(+), 76 deletions(-)
diff --git a/fence/agents/amt/fence_amt.py b/fence/agents/amt/fence_amt.py
index 81b8aec..f4dff4b 100644
--- a/fence/agents/amt/fence_amt.py
+++ b/fence/agents/amt/fence_amt.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
import sys, subprocess, re, os, stat
+import logging
from pipes import quote
sys.path.append(@FENCEAGENTSLIBDIR@)
from fencing import *
@@ -15,19 +16,19 @@ def get_power_status(_, options):
cmd = create_command(options, status)
-if options[log] = LOG_MODE_VERBOSE:
-options[debug_fh].write(executing: + cmd + \n)
-
try:
+logging.debug(Running: %s % cmd)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
except OSError:
fail_usage(Amttool not found or not accessible)
process.wait()
-output = process.communicate()
+out = process.communicate()
process.stdout.close()
-options[debug_fh].write(output)
+process.stderr.close()
+logging.debug(%s\n % str(out))
+
match = re.search('Powerstate:[\\s]*(..)', str(output))
status = match.group(1) if match else None
@@ -43,30 +44,36 @@ def set_power_status(_, options):
cmd = create_command(options, options[--action])
-if options[log] = LOG_MODE_VERBOSE:
-options[debug_fh].write(executing: + cmd + \n)
-
try:
-process = subprocess.Popen(cmd, stdout=options[debug_fh],
stderr=options[debug_fh], shell=True)
+logging.debug(Running: %s % cmd)
+process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
except OSError:
fail_usage(Amttool not found or not accessible)
process.wait()
+out = process.communicate()
+process.stdout.close()
+process.stderr.close()
+logging.debug(%s\n % str(out))
+
return
def reboot_cycle(_, options):
cmd = create_command(options, cycle)
-if options[log] = LOG_MODE_VERBOSE:
-options[debug_fh].write(executing: + cmd + \n)
-
try:
-process = subprocess.Popen(cmd, stdout=options[debug_fh],
stderr=options[debug_fh], shell=True)
+logging.debug(Running: %s % cmd)
+process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
except OSError:
fail_usage(Amttool not found or not accessible)
status = process.wait()
+
+out = process.communicate()
+process.stdout.close()
+process.stderr.close()
+logging.debug(%s\n % str(out))
return not bool(status)
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py
b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index 71782cb..dc413d8 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -2,6 +2,7 @@
import sys, re
import pycurl, StringIO
+import logging
sys.path.append(@FENCEAGENTSLIBDIR@)
from fencing import *
@@ -90,9 +91,8 @@ def send_command(opt, command, timeout):
c.perform()
result = b.getvalue()
- if opt[log] = LOG_MODE_VERBOSE:
- opt[debug_fh].write(command + \n)
- opt[debug_fh].write(result + \n)
+ logging.debug(%s\n % command)
+ logging.debug(%s\n % results)
return result
diff --git a/fence/agents/dummy/fence_dummy.py
b/fence/agents/dummy/fence_dummy.py
index d5bb748..95a3579 100644
--- a/fence/agents/dummy/fence_dummy.py
+++ b/fence/agents/dummy/fence_dummy.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
import sys, re, pexpect, exceptions, random
+import logging
sys.path.append(@FENCEAGENTSLIBDIR@)
from fencing import *
@@ -117,7 +118,7 @@ def main():
if options.has_key(--random_sleep_range):
val = int(options[--random_sleep_range])
ran = random.randint(1, val)
- sys.stderr.write(random sleep for %d seconds\n % ran)
+ logging.info(Random sleep for %d seconds\n % ran)
time.sleep(ran)
if options[--type] == fail:
diff --git