Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit e8c48409c10ec589fffb242282965389a52dd50e
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Sep 2 16:58:17 2013 +0200
move optional parameters into kwargs
Affected classes: LMIBaseClient, LMIConnection, LMIConsole, LMIShellClient. Afftected functions: connect()
>---------------------------------------------------------------
cli/lmi/shell/LMIBaseClient.py | 13 ++++++--
cli/lmi/shell/LMIConnection.py | 59 +++++++++++++++++++++++++++-----------
cli/lmi/shell/LMIConsole.py | 8 ++--
cli/lmi/shell/LMIShellClient.py | 19 +++++++++---
4 files changed, 70 insertions(+), 29 deletions(-)
diff --git a/cli/lmi/shell/LMIBaseClient.py b/cli/lmi/shell/LMIBaseClient.py
index 85fe161..9e99094 100644
--- a/cli/lmi/shell/LMIBaseClient.py
+++ b/cli/lmi/shell/LMIBaseClient.py
@@ -31,8 +31,7 @@ class LMIBaseClient(object):
CONN_TYPE_WBEM, \
CONN_TYPE_PEGASUS_UDS = range(2)
- def __init__(self, hostname, username="", password="", conn_type=CONN_TYPE_WBEM, \
- verify_server_cert=True):
+ def __init__(self, hostname, username="", password="", **kwargs):
"""
Constructs a LMIBaseClient object.
@@ -40,13 +39,15 @@ class LMIBaseClient(object):
hostname -- uri of the CIMOM
username -- account, under which, the CIM calls will be performed
password -- user's password
+
+ Keyword Arguments:
conn_type -- type of connection; can be of 2 values:
LMIBaseClient.CONN_TYPE_WBEM -- WBEM connection,
LMIBaseClient.CONN_TYPE_PEGASUS_UDS -- applicable only for Tog-Pegasus
CIMOM, it uses unix socket for the connection; default value is
CONN_TYPE_WBEM
verify_server_cert -- flag indicating, whether a server side certificate
- needs to be verified, if SSL used
+ needs to be verified, if SSL used; default value is True
"""
def verify_callback(conn, cert, errno, errdepth, rcode):
"""
@@ -63,6 +64,12 @@ class LMIBaseClient(object):
"""
return bool(rcode)
+ # Set remaining arguments
+ conn_type = kwargs.pop("conn_type", LMIBaseClient.CONN_TYPE_WBEM)
+ verify_server_cert = kwargs.pop("verify_server_cert", True)
+ if kwargs:
+ raise TypeError("__init__() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
+
self._hostname = hostname
self._username = username
if not self._hostname.startswith("http://") and not self._hostname.startswith("https://"):
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index cd8b9a2..b79ea4c 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -80,8 +80,7 @@ def __lmi_raw_input(prompt, use_echo=True):
return result
-def connect(hostname, username="", password="", interactive=False, use_cache=True,
- verify_server_cert=True, prompt_prefix=''):
+def connect(hostname, username="", password="", **kwargs):
"""
Returns a LMIConnection object with provided hostname and credentials.
@@ -89,25 +88,36 @@ def connect(hostname, username="", password="", interactive=False, use_cache=Tru
hostname -- uri of the CIMOM
username -- account, under which, the CIM calls will be performed
password -- user's password
+
+ Keyword Arguments:
interactive -- flag indicating, if the LMIShell client is running in the
- interactive mode
+ interactive mode; default value is False.
use_cache -- flag indicationg, if the LMIShell client should use cache for
CIMClass objects. This saves a lot's of communication, if there is
often the LMIShellClient._get_class_names() or ._get_class() call
- issued.
+ issued. Default value is True.
verify_server_cert -- flag indicating, whether a server side certificate
- needs to be verified, if SSL used
+ needs to be verified, if SSL used; default value is True.
prompt_prefix -- string prefixing username and password prompts in case
- the user is asked for credentials
+ the user is asked for credentials. Default value is empty string.
"""
+ # Set remaining arguments
+ interactive = kwargs.pop("interactive", False)
+ use_cache = kwargs.pop("use_cache", True)
+ verify_server_cert = kwargs.pop("verify_server_cert", True)
+ prompt_prefix = kwargs.pop("prompt_prefix", "")
+ if kwargs:
+ raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
+
connection = None
netloc = urlparse.urlparse(hostname).netloc
destination = netloc if netloc else hostname
if os.getuid() == 0 and destination in ("localhost", "127.0.0.1", "::1") and \
os.path.exists("/var/run/tog-pegasus/cimxml.socket") and \
not username and not password:
- connection = LMIConnection(hostname, None, None, interactive,
- use_cache, LMIBaseClient.CONN_TYPE_PEGASUS_UDS, verify_server_cert)
+ connection = LMIConnection(hostname, None, None, interactive=interactive,
+ use_cache=use_cache, conn_type=LMIBaseClient.CONN_TYPE_PEGASUS_UDS,
+ verify_server_cert=verify_server_cert)
if not connection.verify_credentials():
connection = None
if connection is None:
@@ -120,8 +130,9 @@ def connect(hostname, username="", password="", interactive=False, use_cache=Tru
except KeyboardInterrupt, e:
sys.stdout.write("\n")
return None
- connection = LMIConnection(hostname, username, password, interactive,
- use_cache, LMIBaseClient.CONN_TYPE_WBEM, verify_server_cert)
+ connection = LMIConnection(hostname, username, password, interactive=interactive,
+ use_cache=use_cache, conn_type=LMIBaseClient.CONN_TYPE_WBEM,
+ verify_server_cert=verify_server_cert)
if not connection.verify_credentials():
return None
return connection
@@ -132,8 +143,7 @@ class LMIConnection(object):
should have its own connection object created. This class provides an entry point to
the namespace/classes/instances/methods hierarchy present in the LMIShell.
"""
- def __init__(self, hostname, username="", password="", interactive=False, use_cache=True, \
- conn_type=LMIBaseClient.CONN_TYPE_WBEM, verify_server_cert=True):
+ def __init__(self, hostname, username="", password="", **kwargs):
"""
Constructs a LMIConnection object.
@@ -141,17 +151,32 @@ class LMIConnection(object):
hostname -- uri of the CIMOM
username -- account, under which, the CIM calls will be performed
password -- user's password
+
+ Keyword Arguments:
interactive -- flag indicating, if the LMIShell client is running in the
- interactive mode
+ interactive mode; default value is False
use_cache -- flag indicationg, if the LMIShell client should use cache for
CIMClass objects. This saves a lot's of communication, if there is
often the LMIShellClient._get_class_names() or ._get_class() call
- issued.
+ issued. Default value is True.
+ conn_type -- type of connection; can be of 2 values:
+ LMIBaseClient.CONN_TYPE_WBEM -- WBEM connection,
+ LMIBaseClient.CONN_TYPE_PEGASUS_UDS -- applicable only for Tog-Pegasus
+ CIMOM, it uses unix socket for the connection; default value is
+ CONN_TYPE_WBEM
verify_server_cert -- flag indicating, whether a server side certificate
- needs to be verified, if SSL used
+ needs to be verified, if SSL used; default value is True
"""
- self._client = LMIShellClient(hostname, username, password, interactive, use_cache,
- conn_type, verify_server_cert)
+ # Set remaining arguments
+ interactive = kwargs.pop("interactive", False)
+ use_cache = kwargs.pop("use_cache", True)
+ conn_type = kwargs.pop("conn_type", LMIBaseClient.CONN_TYPE_WBEM)
+ verify_server_cert = kwargs.pop("verify_server_cert", True)
+ if kwargs:
+ raise TypeError("__init__() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
+
+ self._client = LMIShellClient(hostname, username, password, interactive=interactive,
+ use_cache=use_cache, conn_type=conn_type, verify_server_cert=verify_server_cert)
self._indications = {}
# Register LMIConnection.__unsubscribe_all_indications() to be called at LMIShell's exit.
atexit.register(lambda: self.__unsubscribe_all_indications())
diff --git a/cli/lmi/shell/LMIConsole.py b/cli/lmi/shell/LMIConsole.py
index c0ffe3a..226eeac 100644
--- a/cli/lmi/shell/LMIConsole.py
+++ b/cli/lmi/shell/LMIConsole.py
@@ -115,8 +115,8 @@ class LMIConsole(code.InteractiveConsole):
username -- account, under which, the CIM calls will be performed
password -- user's password
"""
- return connect_internal(hostname, username, password, True,
- self._use_cache, self._verify_server_cert)
+ return connect_internal(hostname, username, password, interactive=True,
+ use_cache=self._use_cache, verify_server_cert=self._verify_server_cert)
# Initialize the interpreter
if locals is None:
@@ -193,8 +193,8 @@ class LMIConsole(code.InteractiveConsole):
username -- account, under which, the CIM calls will be performed
password -- user's password
"""
- return connect_internal(hostname, username, password, False,
- self._use_cache, self._verify_server_cert)
+ return connect_internal(hostname, username, password, interactive=False,
+ use_cache=self._use_cache, verify_server_cert=self._verify_server_cert)
# Initialize locals
if locals is None:
locals = {}
diff --git a/cli/lmi/shell/LMIShellClient.py b/cli/lmi/shell/LMIShellClient.py
index 59e28ad..857bec0 100644
--- a/cli/lmi/shell/LMIShellClient.py
+++ b/cli/lmi/shell/LMIShellClient.py
@@ -23,8 +23,7 @@ class LMIShellClient(LMIBaseClient):
This class overrides few methods due to caching.
"""
- def __init__(self, hostname, username="", password="", interactive=False, use_cache=True, \
- conn_type=LMIBaseClient.CONN_TYPE_WBEM, verify_server_cert=True):
+ def __init__(self, hostname, username="", password="", **kwargs):
"""
Constructs a LMIShellClient object.
@@ -32,6 +31,8 @@ class LMIShellClient(LMIBaseClient):
hostname -- uri of the CIMOM
username -- account, under which, the CIM calls will be performed
password -- user's password
+
+ Keyword Arguments:
interactive -- flag indicating, if the LMIShell client is running in the
interactive mode
use_cache -- flag indicationg, if the LMIShell client should use cache for
@@ -44,10 +45,18 @@ class LMIShellClient(LMIBaseClient):
CIMOM, it uses unix socket for the connection; default value is
CONN_TYPE_WBEM
verify_server_cert -- flag indicating, whether a server side certificate
- needs to be verified, if SSL used
- """
- super(LMIShellClient, self).__init__(hostname, username, password, conn_type,
- verify_server_cert)
+ needs to be verified, if SSL used; default value is True
+ """
+ # Set remaining arguments
+ interactive = kwargs.pop("interactive", False)
+ use_cache = kwargs.pop("use_cache", True)
+ conn_type = kwargs.pop("conn_type", LMIBaseClient.CONN_TYPE_WBEM)
+ verify_server_cert = kwargs.pop("verify_server_cert", True)
+ if kwargs:
+ raise TypeError("__init__() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
+
+ super(LMIShellClient, self).__init__(hostname, username, password, conn_type=conn_type,
+ verify_server_cert=verify_server_cert)
self._interactive = interactive
self._cache = LMIShellCache(use_cache)
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit b1d5284feb0636a05a6070c46c4fde7641eb6d4e
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Sep 2 16:35:22 2013 +0200
rename verify_certificate
Preparation for naming exactness, when introducing client certificate authentication.
>---------------------------------------------------------------
cli/lmi/shell/LMIBaseClient.py | 6 +++---
cli/lmi/shell/LMIConnection.py | 14 +++++++-------
cli/lmi/shell/LMIConsole.py | 12 ++++++------
cli/lmi/shell/LMIShellClient.py | 6 +++---
cli/lmi/shell/LMIShellOptions.py | 2 +-
cli/lmishell | 2 +-
6 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/cli/lmi/shell/LMIBaseClient.py b/cli/lmi/shell/LMIBaseClient.py
index 8ccb079..85fe161 100644
--- a/cli/lmi/shell/LMIBaseClient.py
+++ b/cli/lmi/shell/LMIBaseClient.py
@@ -32,7 +32,7 @@ class LMIBaseClient(object):
CONN_TYPE_PEGASUS_UDS = range(2)
def __init__(self, hostname, username="", password="", conn_type=CONN_TYPE_WBEM, \
- verify_certificate=True):
+ verify_server_cert=True):
"""
Constructs a LMIBaseClient object.
@@ -45,7 +45,7 @@ class LMIBaseClient(object):
LMIBaseClient.CONN_TYPE_PEGASUS_UDS -- applicable only for Tog-Pegasus
CIMOM, it uses unix socket for the connection; default value is
CONN_TYPE_WBEM
- verify_certificate -- flag indicating, whether a server side certificate
+ verify_server_cert -- flag indicating, whether a server side certificate
needs to be verified, if SSL used
"""
def verify_callback(conn, cert, errno, errdepth, rcode):
@@ -72,7 +72,7 @@ class LMIBaseClient(object):
else:
self._cliconn = pywbem.WBEMConnection(self._hostname,
(self._username, password),
- verify_callback=verify_callback if verify_certificate else None
+ verify_callback=verify_callback if verify_server_cert else None
)
# NOTE: usage with Key=something, Value=something is deprecated
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index 5dfa5fe..27191d3 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -82,7 +82,7 @@ def __lmi_raw_input(prompt, use_echo=True):
return result
def connect(hostname, username="", password="", interactive=False, use_cache=True,
- verify_certificate=True, prompt_prefix=''):
+ verify_server_cert=True, prompt_prefix=''):
"""
Returns a LMIConnection object with provided hostname and credentials.
@@ -96,7 +96,7 @@ def connect(hostname, username="", password="", interactive=False, use_cache=Tru
CIMClass objects. This saves a lot's of communication, if there is
often the LMIShellClient._get_class_names() or ._get_class() call
issued.
- verify_certificate -- flag indicating, whether a server side certificate
+ verify_server_cert -- flag indicating, whether a server side certificate
needs to be verified, if SSL used
prompt_prefix -- string prefixing username and password prompts in case
the user is asked for credentials
@@ -108,7 +108,7 @@ def connect(hostname, username="", password="", interactive=False, use_cache=Tru
os.path.exists("/var/run/tog-pegasus/cimxml.socket") and \
not username and not password:
connection = LMIConnection(hostname, None, None, interactive,
- use_cache, LMIBaseClient.CONN_TYPE_PEGASUS_UDS, verify_certificate)
+ use_cache, LMIBaseClient.CONN_TYPE_PEGASUS_UDS, verify_server_cert)
if not connection.verify_credentials():
connection = None
if connection is None:
@@ -122,7 +122,7 @@ def connect(hostname, username="", password="", interactive=False, use_cache=Tru
sys.stdout.write("\n")
return None
connection = LMIConnection(hostname, username, password, interactive,
- use_cache, LMIBaseClient.CONN_TYPE_WBEM, verify_certificate)
+ use_cache, LMIBaseClient.CONN_TYPE_WBEM, verify_server_cert)
if not connection.verify_credentials():
return None
return connection
@@ -134,7 +134,7 @@ class LMIConnection(object):
the namespace/classes/instances/methods hierarchy present in the LMIShell.
"""
def __init__(self, hostname, username="", password="", interactive=False, use_cache=True, \
- conn_type=LMIBaseClient.CONN_TYPE_WBEM, verify_certificate=True):
+ conn_type=LMIBaseClient.CONN_TYPE_WBEM, verify_server_cert=True):
"""
Constructs a LMIConnection object.
@@ -148,11 +148,11 @@ class LMIConnection(object):
CIMClass objects. This saves a lot's of communication, if there is
often the LMIShellClient._get_class_names() or ._get_class() call
issued.
- verify_certificate -- flag indicating, whether a server side certificate
+ verify_server_cert -- flag indicating, whether a server side certificate
needs to be verified, if SSL used
"""
self._client = LMIShellClient(hostname, username, password, interactive, use_cache,
- conn_type, verify_certificate)
+ conn_type, verify_server_cert)
self._indications = {}
# Register LMIConnection.__unsubscribe_all_indications() to be called at LMIShell's exit.
atexit.register(lambda: self.__unsubscribe_all_indications())
diff --git a/cli/lmi/shell/LMIConsole.py b/cli/lmi/shell/LMIConsole.py
index 1a0bd3e..c0ffe3a 100644
--- a/cli/lmi/shell/LMIConsole.py
+++ b/cli/lmi/shell/LMIConsole.py
@@ -85,7 +85,7 @@ class LMIConsole(code.InteractiveConsole):
self._history_length = config.history_length
self._use_cache = config.use_cache
self._use_exceptions = config.use_exceptions
- self._verify_certificate = True
+ self._verify_server_cert = True
# Setup LMIShell-wide option, which defines, whether the LMIShell
# should propagate caught exceptions, or dump them
@@ -116,7 +116,7 @@ class LMIConsole(code.InteractiveConsole):
password -- user's password
"""
return connect_internal(hostname, username, password, True,
- self._use_cache, self._verify_certificate)
+ self._use_cache, self._verify_server_cert)
# Initialize the interpreter
if locals is None:
@@ -194,7 +194,7 @@ class LMIConsole(code.InteractiveConsole):
password -- user's password
"""
return connect_internal(hostname, username, password, False,
- self._use_cache, self._verify_certificate)
+ self._use_cache, self._verify_server_cert)
# Initialize locals
if locals is None:
locals = {}
@@ -248,12 +248,12 @@ class LMIConsole(code.InteractiveConsole):
"""
readline.clear_history()
- def set_verify_certificate(self, verify_certificate=True):
+ def set_verify_server_certificate(self, verify_server_cert=True):
"""
Turns on or off server side certificate verification, if SSL used.
Arguments:
- verify_certificate -- flag indicating, whether a server side certificate
+ verify_server_cert -- flag indicating, whether a server side certificate
needs to be verified, if SSL used
"""
- self._verify_certificate = verify_certificate
+ self._verify_server_cert = verify_server_cert
diff --git a/cli/lmi/shell/LMIShellClient.py b/cli/lmi/shell/LMIShellClient.py
index 3b7b473..59e28ad 100644
--- a/cli/lmi/shell/LMIShellClient.py
+++ b/cli/lmi/shell/LMIShellClient.py
@@ -24,7 +24,7 @@ class LMIShellClient(LMIBaseClient):
This class overrides few methods due to caching.
"""
def __init__(self, hostname, username="", password="", interactive=False, use_cache=True, \
- conn_type=LMIBaseClient.CONN_TYPE_WBEM, verify_certificate=True):
+ conn_type=LMIBaseClient.CONN_TYPE_WBEM, verify_server_cert=True):
"""
Constructs a LMIShellClient object.
@@ -43,11 +43,11 @@ class LMIShellClient(LMIBaseClient):
LMIBaseClient.CONN_TYPE_PEGASUS_UDS -- applicable only for Tog-Pegasus
CIMOM, it uses unix socket for the connection; default value is
CONN_TYPE_WBEM
- verify_certificate -- flag indicating, whether a server side certificate
+ verify_server_cert -- flag indicating, whether a server side certificate
needs to be verified, if SSL used
"""
super(LMIShellClient, self).__init__(hostname, username, password, conn_type,
- verify_certificate)
+ verify_server_cert)
self._interactive = interactive
self._cache = LMIShellCache(use_cache)
diff --git a/cli/lmi/shell/LMIShellOptions.py b/cli/lmi/shell/LMIShellOptions.py
index 4c26839..74d9586 100644
--- a/cli/lmi/shell/LMIShellOptions.py
+++ b/cli/lmi/shell/LMIShellOptions.py
@@ -155,7 +155,7 @@ class LMIShellOptions(object):
return self._log
@property
- def verify_certificate(self):
+ def verify_server_cert(self):
"""
Property returning bool flag, which indicates, if LMIShell should verify
server side certificate, if SSL used.
diff --git a/cli/lmishell b/cli/lmishell
index b9ee4e6..e493af5 100755
--- a/cli/lmishell
+++ b/cli/lmishell
@@ -42,7 +42,7 @@ if __name__ == "__main__":
logger.addHandler(logging.StreamHandler(sys.stderr))
console = LMIConsole()
- console.set_verify_certificate(options.verify_certificate)
+ console.set_verify_server_certificate(options.verify_server_cert)
if options.interactive:
console.interact()
else: