Many of the properties defined in CIM contain integer values that represent status or configuration information. The qualifiers for those properties define a mapping to human-readable string values.
This example shows a general-purpose routine for converting an integer value to the corresponding string value. The example assumes that the client library you are using has support for introspecting class property information available in the qualifiers.
The following function expects three parameters:
- A connection object that you have previously created, as described in Make a Connection to the CIMOM
- An instance of the class that you have retrieved from the CIMOM
- A string value containing the name of a property of that instance, to be mapped to its string descriptor
use wbemlib use connection function map_instance_property_to_string( connection, instance, prop ) class_info = connection.GetClass( instance.classname, includeQualifiers=True ) qualifiers = class_info.properties[ prop ].qualifiers if qualifiers.key( ‘ValueMap’ ) and qualifiers.key( ‘Values’ ) strings = qualifiers[ ‘Values’ ] nums = qualifiers[ ‘ValueMap’ ] prop_val = instance[ prop ] for ( i=0; len( nums ) - 1; i++ ) if str( nums[ i ] ) == str( prop_val ) return strings[ i ] return Null