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.
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(f'EnumerateInstanceNames failed: {exc}')
sys.exit(1)
for cs_path in cs_paths:
print(f'Instance at: {cs_path}')
try:
cs_inst = conn.GetInstance(cs_path)
except pywbem.Error as exc:
print(f'GetInstance failed: {exc}')
sys.exit(1)
for prop_name, prop_value in cs_inst.items():
print(f' {prop_name}: {prop_value!r}')