From 6fb43d4ee07b5740f6f8267c3606668c93e421f9 Mon Sep 17 00:00:00 2001 From: Alexander Kratzsch Date: Thu, 29 Sep 2016 13:35:14 +0200 Subject: [PATCH] Make the parser read in the correct values (at least for my setup) --- includes/discovery/libvirt-vminfo.inc.php | 28 +++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/includes/discovery/libvirt-vminfo.inc.php b/includes/discovery/libvirt-vminfo.inc.php index 37b26b0031..f3ff562065 100644 --- a/includes/discovery/libvirt-vminfo.inc.php +++ b/includes/discovery/libvirt-vminfo.inc.php @@ -66,10 +66,34 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') { $vmwVmDisplayName = $xml->name; $vmwVmGuestOS = ''; // libvirt does not supply this - $vmwVmMemSize = ($xml->currentMemory / 1024); exec($config['virsh'].' -rc '.$uri.' domstate '.$dom_id, $vm_state); $vmwVmState = ucfirst($vm_state[0]); - $vmwVmCpus = $xml->vcpu; + + $vmwVmCpus = null; + $vmwVmMemSize = null; + if ($xml->xpath("//sysinfo/system/entry[@name='manufacturer'][.='oVirt']")) { + d_echo("Parsing information for $vmwVmDisplayName with oVirt quirx"); + // oVirt does not fully comply with the example above + switch ($xml->memory['unit']) { + case 'MiB': + $vmwVmMemSize = $xml->memory; + break; + case 'GiB': + $vmwVmMemSize = $xml->memory * 1024; + break; + default: + // includes KiB + $vmwVmMemSize = $xml->memory / 1024; + break; + } + $vmwVmCpus = $xml->vcpu['current']; + if (!isset($vmwVmCpus)) { + $vmwVmCpus = $xml->vcpu; + } + } else { + $vmwVmMemSize = ($xml->currentMemory / 1024); + $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));