# moo.example.com # 48cf6378-6fd5-4610-0611-63dd4b31cfd6 # 1048576 # 1048576 # 8 # # hvm # # # # # (...) # Convert array to string unset($vm_info_xml); foreach ($vm_info_array as $line) { $vm_info_xml .= $line; } $xml = simplexml_load_string(' ' . $vm_info_xml); if ($debug) { print_r($xml); } $vmwVmDisplayName = $xml->name; $vmwVmGuestOS = ''; # libvirt does not supply this $vmwVmMemSize = $xml->currentMemory / 1024; exec($config['virsh'] . ' -c '.$uri.' domstate ' . $dom_id,$vm_state); $vmwVmState = ucfirst($vm_state[0]); $vmwVmCpus = $xml->vcpu; # Check whether the Virtual Machine is already known for this host. $result = dbFetchRow("SELECT * FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND `vm_type` = 'libvirt'",array($device['device_id'],$dom_id)); if (count($result['device_id']) == 0) { $inserted_id = dbInsert(array('device_id' => $device['device_id'], 'vm_type' => 'libvirt', 'vmwVmVMID' => $dom_id,'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus), 'vmwVmState' => mres($vmwVmState)), 'vminfo'); echo("+"); log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', $inserted_id); } else { if ($result['vmwVmState'] != $vmwVmState || $result['vmwVmDisplayName'] != $vmwVmDisplayName || $result['vmwVmCpus'] != $vmwVmCpus || $result['vmwVmGuestOS'] != $vmwVmGuestOS || $result['vmwVmMemSize'] != $vmwVmMemSize) { dbUpdate(array('vmwVmState' => mres($vmwVmState), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus)), 'vminfo', "device_id=? AND vm_type='libvirt' AND vmwVmVMID=?",array($device['device_id'],$dom_id)); echo("U"); // FIXME eventlog } else { echo("."); } } # Save the discovered Virtual Machine. $libvirt_vmlist[] = $dom_id; } } } # If we found VMs, don't cycle the other protocols anymore. if (count($libvirt_vmlist)) { break; } } # Get a list of all the known Virtual Machines for this host. $sql = "SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='libvirt'"; foreach (dbFetchRows($sql) as $db_vm) { # Delete the Virtual Machines that are removed from the host. if (!in_array($db_vm["vmwVmVMID"], $libvirt_vmlist)) { dbDelete('vminfo', '`id` = ?', array($db_vm['id'])); echo("-"); log_event("Virtual Machine removed: " . $db_vm['vmwVmDisplayName'], $device, 'vm', $db_vm['id']); } } echo("\n"); } ?>