Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
---------------------------------------------------------------
commit 1b8df51c80e5455c9ca30a6ecf5956074de21e51
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Dec 2 10:14:23 2013 +0100
add missing log messages in connect()
---------------------------------------------------------------
cli/lmi/shell/LMIConnection.py | 7 +++++++
cli/lmishell | 13 ++++++-------
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index 301fa52..da7cef9 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -17,6 +17,7 @@ import os
import sys
import atexit
import pywbem
+import logging
import readline
import urlparse
@@ -126,6 +127,7 @@ def connect(uri, username="", password="",
**kwargs):
if kwargs:
raise TypeError("connect() got an unexpected keyword arguments: %s" %
", ".join(kwargs.keys()))
+ logger = logging.getLogger("")
connection = None
netloc = urlparse.urlparse(uri).netloc
destination = netloc if netloc else uri
@@ -137,6 +139,8 @@ def connect(uri, username="", password="",
**kwargs):
verify_server_cert=verify_server_cert)
if not connection.verify_credentials():
connection = None
+ else:
+ logger.info("Connected via Unix-socket")
if connection is None:
if interactive and not key_file and not cert_file:
try:
@@ -151,7 +155,10 @@ def connect(uri, username="", password="",
**kwargs):
use_cache=use_cache, conn_type=LMIBaseClient.CONN_TYPE_WBEM,
key_file=key_file, cert_file=cert_file,
verify_server_cert=verify_server_cert)
if not connection.verify_credentials():
+ logger.error("Not connected to %s, wrong username/password or
certificate", uri)
return None
+ else:
+ logger.info("Connected to %s", uri)
return connection
class LMIConnection(object):
diff --git a/cli/lmishell b/cli/lmishell
index e493af5..aaa8f7b 100755
--- a/cli/lmishell
+++ b/cli/lmishell
@@ -22,24 +22,23 @@ from lmi.shell import LMIShellOptions
if __name__ == "__main__":
options = LMIShellOptions(sys.argv)
+ logging.basicConfig(format='%(levelname)s: %(message)s')
+ logger = logging.getLogger("")
if options.log == LMIShellOptions._LOG_MORE_VERBOSE:
# Print out all the log messages to stderr stream
- logger = logging.getLogger("")
logger.setLevel(logging.DEBUG)
- logger.addHandler(logging.StreamHandler(sys.stderr))
elif options.log == LMIShellOptions._LOG_VERBOSE:
# Print out only a set of log messages to stderr stream
- logger = logging.getLogger("")
logger.setLevel(logging.INFO)
- logger.addHandler(logging.StreamHandler(sys.stderr))
elif options.log == LMIShellOptions._LOG_QUIET:
# Quiet flag seen, drop all the log messages
- logging.getLogger("").addHandler(logging.NullHandler())
+ handlers = logger.handlers
+ for handler in handlers:
+ logger.removeHandler(handler)
+ logger.addHandler(logging.NullHandler())
else:
# By default, print error messages to stderr stream
- logger = logging.getLogger("")
logger.setLevel(logging.ERROR)
- logger.addHandler(logging.StreamHandler(sys.stderr))
console = LMIConsole()
console.set_verify_server_certificate(options.verify_server_cert)