4.12. Support for PUnit and Units qualifiers¶
The pywbem.siunit_obj()
and pywbem.siunit()
functions translate
the PUnit
and Units
qualifier values into human readable SI conformant
unit strings.
Experimental: New in 1.1.0 as experimental
Note: These functions do not perform any class operations; they take the qualifiers as input.
The reason the Units
qualifier is still supported is that the DMTF CIM
Schema (as of its version 2.49) still contains a number of schema elements that
have the Units
qualifier but not the PUnit
qualifier set.
The format and valid base units for the PUnit
qualifier and the
valid values for the Units
qualifier are defined in Annex C of
DSP0004. Pywbem supports the definitions from DSP0004
version 2.8, and the following additional Units
qualifier values that are
used in DMTF CIM Schema version 2.49:
Additional Units values |
---|
-dBm |
Blocks |
Percentage |
Proportion |
Tenths of Revolutions per Minute |
By default, the string value returned from these functions may contain the
following Unicode characters outside of the 7-bit ASCII range. If the
use_ascii
parameter is True, these Unicode characters are replaced with
7-bit ASCII text as follows:
Unicode character code | Unicode | 7-bit ASCII |
---|---|---|
U+00B0: DEGREE SIGN | ° |
deg |
U+00B5: MICRO SIGN | µ |
u |
U+2030: PER MILLE SIGN | ‰ |
1/1000 |
U+2126: OHM SIGN | Ω |
Ohm |
U+00B2: SUPERSCRIPT TWO | ² |
^2 |
U+00B3: SUPERSCRIPT THREE | ³ |
^3 |
Examples:
PUnit("byte / second * 10^3")
->kB/s
PUnit("byte * 2^10")
->KiB
PUnit("hertz * 10^6")
->MHz
PUnit("ampere * 10^-3")
->mA
Units("KiloBits per Second")
->kbit/s
Units("Tenths of Degrees C")
->1/10 °C
Limitations:
- For PUnit qualifiers, vendor-defined base units are not supported
(e.g.
vendor:myunit
). - For PUnit qualifiers, space characters within the parenthesis of
decibel
(e.g.decibel ( A )
) are not supported. - For Units qualifiers, arbitrary numeric values that are part of the Units
value (e.g.
<numeric-value> NanoSeconds
orAmps at <numeric-value> Volts
) are not generally supported, but only for those cases that are used in the DMTF CIM Schema (as of its version 2.49):250 NanoSeconds
Amps at 120 Volts
-
pywbem.
siunit_obj
(cim_obj, use_ascii=False)[source]¶ Returns a human readable SI conformant unit string from the
PUnit
orUnits
qualifiers of the specified CIM object.Experimental: New in 1.1.0 as experimental
If the CIM object has both the
PUnit
andUnits
qualifiers set, thenPUnit
is used andUnits
is ignored.Parameters: - cim_obj (
CIMProperty
orCIMMethod
orCIMParameter
) – CIM object with qualifiers. - use_ascii (
bool
) – Replace any Unicode characters in the returned string with 7-bit ASCII replacements, as describedabove
.
Returns: Human readable SI conformant unit string, or None if the CIM object has neither the
PUnit
nor theUnits
qualifiers set.Return type: Raises: TypeError
– Invalid type for cim_objValueError
– Invalid format in PUnit qualifierValueError
– Unknown base unit in PUnit qualifierValueError
– Unknown unit in Units qualifier
- cim_obj (
-
pywbem.
siunit
(punit=None, units=None, use_ascii=False)[source]¶ Returns a human readable SI conformant unit string from the specified
PUnit
orUnits
qualifier values.Experimental: New in 1.1.0 as experimental
If both
punit
andunits
are specified, thenpunit
is used andunits
is ignored.Parameters: Returns: Human readable SI conformant unit string, or None if both qualifier value input parameters were None.
Return type: Raises: TypeError
– Invalid type for punit or unitValueError
– Invalid format in PUnit qualifierValueError
– Unknown base unit in PUnit qualifierValueError
– Unknown unit in Units qualifier