4.10. Mapping between ValueMap and Values qualifiers

The ValueMapping class supports translating the values of an integer-typed CIM element (e.g. property, method, or parameter) that is qualified with the ValueMap and Values qualifiers, to the corresponding value of the Values qualifier.

This class supports value ranges (e.g. "4..6") and the unclaimed marker ("..").

class pywbem.ValueMapping[source]

New in pywbem 0.9 as experimental and finalized in 0.10.

A utility class that supports translating the values of an integer-typed CIM element (property, method, parameter) that is qualified with the ValueMap and Values qualifiers, to the corresponding value of the Values qualifier.

This is done by retrieving the CIM class definition defining the CIM element in question, and by inspecting its ValueMap and Values qualifiers.

The translation of the values is performed by the tovalues() method.

Instances of this class must be created through one of the factory class methods: for_property(), for_method(), or for_parameter().

Value ranges ("2..4") and the indicator for unclaimed values ("..") in the ValueMap qualifier are supported.

Example

Given the following definition of a property in MOF:

class CIM_Foo {

      [ValueMap{ "0", "2..4", "..6", "7..", "9", ".." },
       Values{ "zero", "two-four", "five-six", "seven-eight", "nine",
       "unclaimed"}]
   uint16 MyProp;

};

Assuming this class exists in a WBEM server, the following code will create a value mapping for this property and will print a few property values and their corresponding Values strings:

namespace = 'root/cimv2'
conn = pywbem.WBEMConnection(...)  # WBEM server

myprop_vm = pywbem.ValueMapping.for_property(
    conn, namespace, 'CIM_Foo', 'MyProp')

print("value: Values")
for value in range(0, 12):
    print("%5s: %r" % (value, myprop_vm.tovalues(value))

Resulting output:

value: Values
    0: 'zero'
    1: 'unclaimed'
    2: 'two-four'
    3: 'two-four'
    4: 'two-four'
    5: 'five-six'
    6: 'five-six'
    7: 'seven-eight'
    8: 'seven-eight'
    9: 'nine'
   10: 'unclaimed'
   11: 'unclaimed'
classmethod for_property(server, namespace, classname, propname)[source]

Factory method that returns a new ValueMapping instance that maps CIM property values to the Values qualifier defined on that property.

If a Values qualifier is defined but no ValueMap qualifier, a default of 0-based consecutive numbers is applied (that is the default defined in DSP0004).

Parameters:
  • server (WBEMConnection or WBEMServer) – The connection to the WBEM server containing the namespace.
  • namespace (string) – Name of the CIM namespace containing the class. If None, the default namespace of the connection will be used.
  • classname (string) – Name of the CIM class exposing the property. The property can be defined in that class or inherited into that class.
  • propname (string) – Name of the CIM property that defines the Values / ValueMap qualifiers.
Returns:

The new ValueMapping instance.

Raises:
classmethod for_method(server, namespace, classname, methodname)[source]

Factory method that returns a new ValueMapping instance that maps CIM method return values to the Values qualifier of that method.

If a Values qualifier is defined but no ValueMap qualifier, a default of 0-based consecutive numbers is applied (that is the default defined in DSP0004).

Parameters:
  • server (WBEMConnection or WBEMServer) – The connection to the WBEM server containing the namespace.
  • namespace (string) – Name of the CIM namespace containing the class.
  • classname (string) – Name of the CIM class exposing the method. The method can be defined in that class or inherited into that class.
  • methodname (string) – Name of the CIM method that defines the Values / ValueMap qualifiers.
Returns:

The new ValueMapping instance.

Raises:
classmethod for_parameter(server, namespace, classname, methodname, parametername)[source]

Factory method that returns a new ValueMapping instance that maps CIM parameter values to the Values qualifier defined on that parameter.

If a Values qualifier is defined but no ValueMap qualifier, a default of 0-based consecutive numbers is applied (that is the default defined in DSP0004).

Parameters:
  • server (WBEMConnection or WBEMServer) – The connection to the WBEM server containing the namespace.
  • namespace (string) – Name of the CIM namespace containing the class.
  • classname (string) – Name of the CIM class exposing the method. The method can be defined in that class or inherited into that class.
  • methodname (string) – Name of the CIM method that has the parameter.
  • parametername (string) – Name of the CIM parameter that defines the Values / ValueMap qualifiers.
Returns:

The new ValueMapping instance.

Raises:
  • Exceptions raised by WBEMConnection.
  • ValueError – No Values qualifier defined.
  • TypeError – The parameter is not integer-typed.
  • KeyError – The method does not exist in the class, or the parameter does not exist in the method.
__repr__()[source]

Return a representation of the ValueMapping object with all attributes, that is suitable for debugging.

conn

WBEMConnection – Connection to the WBEM server containing the CIM namespace (that contains the mapped CIM element).

namespace

string – Name of the CIM namespace containing the class that defines the mapped CIM element.

classname

string – Name of the CIM class defining the mapped CIM element.

propname

string – Name of the CIM property that is mapped. None, if no property is mapped.

methodname

string – Name of the CIM method, that either is mapped itself, or that has the parameter that is mapped. None, if no method or parameter is mapped.

parametername

string – Name of the CIM parameter that is mapped. None, if no parameter is mapped.

element

CIMProperty, CIMMethod, or CIMParameter – The mapped CIM element.

tovalues(element_value)[source]

Return the Values string for an element value, based upon this value mapping.

Parameters:

element_value (integer or CIMInt) – The value of the CIM element (property, method, parameter).

Returns:

The Values string for the element value.

Return type:

string

Raises:
  • ValueError – Element value outside of the set defined by ValueMap.
  • TypeError – Element value is not an integer type.