Each class in LMIShell represents a class provided by a CIMOM. You can get a list of its properties, methods, instances, instance names and ValueMap properties. It is also possible to print a documentation string, create a new instance or new instance name.
To get a class which is provided by a broker, you can do following:
> cls = c.root.cimv2.ClassName
>
Objects of LMIClass
use lazy fetching method, because some methods do
not need the CIMClass
object.
To manually fetch the CIMClass
object, call following:
> cls.fetch()
>
The methods, which need the CIMClass
object to be fetched from CIMOM,
do this action automatically, without the need of calling
LMIClass.fetch()
method by hand.
Following example illustrates, how to work with LMIClass
methods:
> cls.print_methods()
...
> cls_method_lst = cls.methods()
>
To get a list of properties of a specific class, run following code:
> cls.print_properties()
...
> cls_property_lst = cls.properties()
>
Following part described basic work flow with LMIInstance
and
LMIInstanceName
objects.
Using a class object, you can access its instances. You can easily get a list of (filtered) instances, or the first one from the list. The filtering is uses input dictionary, if present, where the dictionary keys represent the instance properties and the dictionary values represent your desired instance property values.
To get LMIInstance
object, execute the following example:
> inst = cls.first_instance()
> inst_lst = cls.instances()
>
The CIMInstanceName
objects clearly identify CIMInstance
objects. LMIShell can retrieve LMIInstanceName
objects, by calling following:
> inst_name = cls.first_instance_name()
> inst_names_lst = cls.instance_names()
>
Both methods LMIClass.instances()
or LMIClass.instance_names()
can filter returned objects by their keys/values. The filtering is achieved by
passing a dictionary of {property : value}
to the corresponding method. See
following example:
> inst_lst = cls.instances({"FilterProperty" : FilterValue})
> inst_names_lst = cls.instance_names({"FilterProperty" : FilterValue})
>
LMIShell is able to create a new wrapped CIMInstanceName
, if you know
all the primary keys of a remote object. This instance name object can be then
used to retrieve the whole instance object.
See the next example:
> inst_name = cls({Property1 : Value1, Property2 : Value2, ...})
> inst = inst_name.to_instance()
>
LMIShell is able to create an object of specific class, if the provider support this operation.
See the following example:
> cls.create_instance({"Property1" : Value1, "Property2" : Value2})
>
NOTE: Value
can be a LMIInstance
object, as well. LMIShell
will auto-cast such object.
A CIM class may contain ValueMap properties (aliases for constant values) in its MOF definition. These properties contain constant values, which can be useful, when calling a method, or checking a returned value.
ValueMap properties are formed from 2 MOF properties of a class definition:
To get a list of all available constants, their values, use the following code:
> cls.print_valuemap_properties()
...
> valuemap_properties = cls.valuemap_properties()
...
> cls.PropertyValues.print_values()
...
>
NOTE: The suffix “Values” provides a way, how to access ValueMap properties.
Following example shows, how to retrieve a constant value:
> constant_value_names_lst = cls.PropertyValues.values()
> cls.PropertyValues.ConstantValueName
ConstantValue
> cls.PropertyValues.value("ConstantValueName")
ConstantValue
>
LMIShell can also return string representing constant value. See the following code:
> cls.PropertyValue.value_name(ConstantValue)
'ConstantValueName'
>
Following part describes few useful LMIClass
properties.
Every class object can return a name of the CIM class, see following:
> cls.classname
ClassName
>
Every class belongs to certain namespace, to get a string containing the corresponding namespace for each class, run following:
> cls.namespace
Namespace
>
This property returns a connection object, which was used to retrieve the class (refer to Establish a connection). See next example:
> cls.connection
LMIConnection(URI='uri', user='user'...)
>
This property returns a wrapped pywbem
object. See the example:
> instance.wrapped_object
CIMClass(u'ClassName', ...)
>
To see a class documentation (based on MOF definitions), run:
> cls.doc()
# ... pretty verbose output displayed in a pages (can be modified by
# setting environment variable PAGER) ...
>