GetInstance

The GetInstance() method returns a pywbem.CIMInstance object, given a pywbem.CIMInstanceName object that references the desired CIM instance.

The following code extends the EnumerateInstanceNames example by the use of GetInstance on each of the returned instance paths.


In [ ]:
from __future__ import print_function
import sys
import pywbem

username = 'user'
password = 'password'
classname = 'CIM_ComputerSystem'
namespace = 'root/cimv2'
server = 'http://localhost'

conn = pywbem.WBEMConnection(server, (username, password),
                             default_namespace=namespace,
                             no_verification=True)
try:
    cs_paths = conn.EnumerateInstanceNames(classname, namespace)
except pywbem.Error as exc:
    print('EnumerateInstanceNames failed: %s' % exc)
    sys.exit(1)

for cs_path in cs_paths:

    print('Instance at: %s' % cs_path)

    try:
        cs_inst = conn.GetInstance(cs_path)
    except pywbem.Error as exc:
        print('GetInstance failed: %s' % exc)
        sys.exit(1)

    for prop_name, prop_value in cs_inst.items():
        print('  %s: %r' % (prop_name, prop_value))