Classes

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.

Getting a class object

To get a class which is provided by a broker, you can do following:

> cls = c.root.cimv2.ClassName
>

Fetching a class

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.

Class Methods

Following example illustrates, how to work with LMIClass methods:

> cls.print_methods()
...
> cls_method_lst = cls.methods()
>

Class Properties

To get a list of properties of a specific class, run following code:

> cls.print_properties()
...
> cls_property_lst = cls.properties()
>

Instances

Following part described basic work flow with LMIInstance and LMIInstanceName objects.

Get Instances

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()
>

Get Instance Names

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()
>

Filtering

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})
>

New Instance Name

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()
>

Creating a new instance

LMIShell is able to create an object of specific class, if the provider support this operation. The next example shows, how to add a specific user account to the desired group.

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.

ValueMap Properties

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:

  • Values – list of string names of the “constant” values
  • ValueMap – list of values

Get ValueMap properties

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.

Get ValueMap property value

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
>

Get ValueMap property value name

LMIShell can also return string representing constant value. See the following code:

> cls.PropertyValue.value_name(ConstantValue)
'ConstantValueName'
>

Useful Properties

Following part describes few useful LMIClass properties.

Class name

Every class object can return a name of the CIM class, see following:

> cls.classname
'ClassName'

Namespace

Every class belongs to certain namespace, to get a string containing the corresponding namespace for each class, run following:

> cls.namespace
'NamespaceOfClassName'
>

Documentation

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) ...
>