LMIUtil

class lmi.shell.LMIUtil.LMIPassByRef(val)

Helper class used for passing a value by reference. It uses the advantage of python, where all the dictionaries are passed by reference.

Parameters:val – value, which will be passed by reference

Example of usage:

by_ref = LMIPassByRef(some_value)
by_ref.value == some_value
value
Returns:value passed by reference.
class lmi.shell.LMIUtil.LMIUseExceptionsHelper

Singleton helper class used for storing a bool flag, which defines, if the LMIShell should propagate exceptions or dump them.

use_exceptions
Returns:whether the LMIShell should propagate the exceptions, or throw them away
Return type:bool
lmi.shell.LMIUtil.lmi_associators(assoc_classes)

Helper function to speed up associator traversal. Returns a list of tuples, where each tuple contains LMIInstance objects, which are in association.

Parameters:assoc_classes (list) – list of LMIClass objects, for which the associations will be returned
Returns:list of tuples of LMIInstance objects in association
lmi.shell.LMIUtil.lmi_cast_to_cim(t, value)

Casts the value to CIM type.

Parameters:
  • t (string) – string of CIM type
  • value – variable to cast
Returns:

cast value in wbem type

lmi.shell.LMIUtil.lmi_cast_to_lmi(t, value)

Casts the value to LMI (python) type.

Parameters:
  • t (string) – string of CIM type
  • value – variable to cast
Returns:

cast value in python native type

lmi.shell.LMIUtil.lmi_get_use_exceptions()
Returns:whether the LMIShell should use the exceptions, or throw them away
Return type:bool
lmi.shell.LMIUtil.lmi_instance_to_path(instance)

Helper function, which returns wbem.CIMInstanceName extracted out of input instance.

Parameters:instance

object, which can be instance of following classes:

Returns:extracteed wbem.CIMInstanceName object
Raises:TypeError
lmi.shell.LMIUtil.lmi_is_localhost(uri)

Helper function, which returns True, if URI points to localhost.

Parameters:uri (str) – URI to check
lmi.shell.LMIUtil.lmi_isinstance(lmi_obj, lmi_class)

Function returns True if lmi_obj is an instance of a lmi_class, False otherwise. When passed LMIInstance, LMIInstanceName as lmi_obj and lmi_class is of LMIClass type, function can tell, if such lmi_obj is direct instance of LMIClass, or it’s super class.

If lmi_obj and lmi_class is not instance of mentioned classes, an exception will be raised.

Parameters:
  • lmi_obj – instance of LMIInstance or LMIInstanceName which is checked, if such instance is instance of the lmi_class
  • lmi_class (LMIClass) – instance of LMIClass object
Returns:

whether lmi_obj is instance of lmi_class

Return type:

bool

Raises:

TypeError

lmi.shell.LMIUtil.lmi_parse_uri(uri)

Parses URI into scheme, hostname, port, username and password.

lmi.shell.LMIUtil.lmi_raise_or_dump_exception(e=None)

Function which either raises an exception, or throws it away.

Parameters:e (Exception) – exception, which will be either raised or thrown away
lmi.shell.LMIUtil.lmi_set_use_exceptions(use=True)

Sets a global flag indicating, if the LMIShell should use the exceptions, or throw them away.

Parameters:use (bool) – specifies, whether the LMIShell should use the exceptions
lmi.shell.LMIUtil.lmi_transform_to_cim_param(t, value)

Helper function for method calls, which transforms input object into wbem.CIMInstanceName object. Members if lists, dictionaries and tuples are transformed as well. The function does not cast numeric types.

Parameters:
  • t (string) – string of CIM type
  • value – object to be transformed to wbem type.
Returns:

transformed LMIShell’s object into wbem one

lmi.shell.LMIUtil.lmi_transform_to_lmi(conn, value)

Transforms returned values from a method call into LMI wrapped objects. Returns transformed input, where wbem.CIMInstance and wbem.CIMInstanceName are wrapped into LMI wrapper classes and primitive types are cast to python native types.

Parameters:
  • conn (LMIConnection) – connection object
  • value – object to be transformed into python type from wbem one
Returns:

transformed py:wbem object into LMIShell one

lmi.shell.LMIUtil.lmi_wrap_cim_class(conn, cim_class_name, cim_namespace_name)

Helper function, which returns wrapped wbem.CIMClass into LMIClass.

Parameters:
  • conn (LMIConnection) – connection object
  • cim_class_name (string) – string containing wbem.CIMClass name
  • cim_namespace_name (string) – string containing wbem.CIMNamespace name, or None, if the namespace is not known
Returns:

wrapped wbem.CIMClass into LMIClass

lmi.shell.LMIUtil.lmi_wrap_cim_instance(conn, cim_instance, cim_class_name, cim_namespace_name)

Helper function, which returns wrapped wbem.CIMInstance into LMIInstance.

Parameters:
  • conn (LMIConnection) – connection object
  • cim_instance (CIMInstance) – wbem.CIMInstance object to be wrapped
  • cim_class_name (string) – wbem.CIMClass name
  • cim_namespace_name (string) – wbem.CIMNamespace name, or None, if the namespace is not known
Returns:

wrapped wbem.CIMInstance into LMIInstance

lmi.shell.LMIUtil.lmi_wrap_cim_instance_name(conn, cim_instance_name)

Helper function, which returns wrapped wbem.CIMInstanceName into LMIInstanceName.

Parameters:
  • conn (LMIConnection) – connection object
  • cim_instance_name (CIMInstanceName) – wbem.CIMInstanceName object to be wrapped
Returns:

wrapped wbem.CIMInstanceName into LMIInstanceName

lmi.shell.LMIUtil.lmi_wrap_cim_method(conn, cim_method_name, lmi_instance)

Helper function, which returns wrapped wbem.CIMMethod into LMIMethod.

Parameters:
  • conn (LMIConnection) – connection object
  • cim_method_name (string) – method name
  • lmi_instance (LMIInstance) – object, on which the method call will be issued
Returns:

wrapped wbem.CIMMethod into LMIMethod

lmi.shell.LMIUtil.lmi_wrap_cim_namespace(conn, cim_namespace_name)

Helper function, which returns wrapped CIM namespace in LMINamespace.

Parameters:
  • conn (LMIConnection) – connection object
  • cim_namespace_name (string) – CIM namespace name
Returns:

wrapped CIM namespace into LMINamespace