def test_mi(): import mi with mi.Application() as a: with a.create_session(protocol=mi.PROTOCOL_WMIDCOM) as s: with s.exec_query(u"root\\cimv2", u"select * from win32_process") as q: i = q.get_next_instance() while i is not None: s = i[u'name'] i = q.get_next_instance()
def test_mi(): import mi with mi.Application() as a: with a.create_session(protocol=mi.PROTOCOL_WMIDCOM) as s: with s.exec_query( u"root/virtualization/v2", u"select * from Msvm_VirtualSystemManagementService") as q: svc = q.get_next_instance() c = svc.get_class() p = a.create_method_params(c, u"GetSummaryInformation") with s.exec_query( u"root/virtualization/v2", u"select * from Msvm_ComputerSystem where " "ElementName = '%s'" % VM_NAME) as q1: vm = q1.get_next_instance() with s.get_associators( u"root/virtualization/v2", vm, assoc_class=u"Msvm_SettingsDefineState", result_class=u"Msvm_VirtualSystem" "SettingData") as q2: vssd = q2.get_next_instance() p[u'SettingData'] = (vssd, ) p[u'requestedInformation'] = (4, 100, 103, 105) with s.invoke_method(svc, u"GetSummaryInformation", p) as q3: r = q3.get_next_instance() print("Result: %s" % r[u"ReturnValue"]) summary_info = r[u"SummaryInformation"][0] print("vCPUs: %s" % summary_info[u"NumberOfProcessors"]) print("EnabledState: %s" % summary_info[u"EnabledState"]) print("Memory: %s" % summary_info[u"MemoryUsage"]) print("UpTime: %s" % summary_info[u"UpTime"])
def _get_app(): global _app if not _app: _app = mi.Application() return _app