$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// add translations
$_SERVER['REQUEST_URI'] = 'vms';
require_once "$docroot/webGui/include/Translations.php";
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
$user_prefs = '/boot/config/plugins/dynamix.vm.manager/userprefs.cfg';
if (file_exists('/boot/config/plugins/dynamix.vm.manager/vmpreview')) $vmpreview = true ; else $vmpreview = false ;
$vms = $lv->get_domains();
if (empty($vms)) {
echo '
" : "' style='display:none'>");
echo "";
echo "";
echo "| "._('Disk devices')." | "._('Serial')." | "._('Bus')." | "._('Capacity')." | "._('Allocation')." | Boot Order | ";
echo "";
/* Display VM disks */
foreach ($lv->get_disk_stats($res) as $arrDisk) {
$capacity = $lv->format_size($arrDisk['capacity'], 0);
$allocation = $lv->format_size($arrDisk['allocation'], 0);
$disk = $arrDisk['file'] ?? $arrDisk['partition'];
$dev = $arrDisk['device'];
$bus = $arrValidDiskBuses[$arrDisk['bus']] ?? 'VirtIO';
$boot= $arrDisk["boot order"];
$serial = $arrDisk["serial"];
if ($boot < 1) $boot="Not set";
echo "| $disk | $serial | $bus | ";
if ($state == 'shutoff') {
echo "";
echo " | ";
} else {
echo "$capacity | ";
}
echo "$allocation | $boot | ";
}
/* Display VM cdroms */
foreach ($cdroms as $arrCD) {
$capacity = $lv->format_size($arrCD['capacity'], 0);
$allocation = $lv->format_size($arrCD['allocation'], 0);
$disk = $arrCD['file'] ?? $arrCD['partition'] ?? "" ;
$dev = $arrCD['device'];
$bus = $arrValidDiskBuses[$arrCD['bus']] ?? 'VirtIO';
$boot= $arrCD["boot order"] ?? "" ;
if ($boot < 1) $boot="Not set";
if ($disk != "" ) {
$title = _("Eject CD Drive").".";
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\", \"--eject\")";
echo "| $disk | | $bus | $capacity | $allocation | $boot | ";
} else {
$title = _("Insert CD").".";
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\",\"--select\")";
$disk = _("No CD image inserted in to drive");
echo "| $disk | | $bus | $capacity | $allocation | $boot | ";
}
}
echo "";
/* Display VM IP Addresses "execute":"guest-network-get-interfaces" --pretty */
echo "| "._('Interfaces')." | | | "._('Type')." | "._('IP Address')." | "._('Prefix')." | ";
echo "";
$gastate = getgastate($res);
if ($gastate == "connected") {
$ip = $lv->domain_interface_addresses($res, 1);
if ($ip != false) {
$duplicates = []; // hide duplicate interface names
foreach ($ip as $arrIP) {
$ipname = $arrIP["name"];
if (preg_match('/^(lo|Loopback)/',$ipname)) continue; // omit loopback interface
$iphdwadr = $arrIP["hwaddr"] == "" ? _("N/A") : $arrIP["hwaddr"];
$iplist = $arrIP["addrs"];
foreach ($iplist as $arraddr) {
$ipaddrval = $arraddr["addr"];
if (preg_match('/^f[c-f]/',$ipaddrval)) continue; // omit ipv6 private addresses
$iptype = $arraddr["type"] ? "ipv6" : "ipv4";
$ipprefix = $arraddr["prefix"];
$ipnamemac = "$ipname ($iphdwadr)";
if (!in_array($ipnamemac,$duplicates)) $duplicates[] = $ipnamemac; else $ipnamemac = "";
echo "| $ipnamemac | | | $iptype | $ipaddrval | $ipprefix | ";
}
}
}
}
else {
if ($gastate == "disconnected") echo "| "._('Guest agent not installed')." | | | | ";
else echo "| "._('Guest not running')." | | | | | ";
}
echo "";
/* Display VM Snapshots */
if ($snapshots != null) {
$j=0 ;
$steps = array() ;
foreach($snapshots as $snap) {
if ($snap['parent'] == "" || $snap['parent'] == "Base") $j++;
$steps[$j] .= $snap['name'].';' ;
}
echo "| "._('Snapshots')." | | "._('Date/Time')." | "._('Type')." | "._('Parent')." | "._('Memory')." | ";
echo "";
foreach($steps as $stepsline)
{
$snapshotlist = explode(";",$stepsline) ;
$tab = " " ;
foreach($snapshotlist as $snapshotitem) {
if ($snapshotitem == "") continue ;
$snapshot = $snapshots[$snapshotitem] ;
$snapshotstate = _(ucfirst($snapshot["state"])) ;
$snapshotdesc = $snapshot["desc"] ;
$snapshotmemory = _(ucfirst($snapshot["memory"]["@attributes"]["snapshot"])) ;
$snapshotparent = $snapshot["parent"] ? $snapshot["parent"] : "None";
$snapshotdatetime = my_time($snapshot["creationtime"],"Y-m-d" )." ".my_time($snapshot["creationtime"],"H:i:s") ;
$snapmenu = sprintf("onclick=\"addVMSnapContext('%s','%s','%s','%s','%s','%s')\"", addslashes($vm),addslashes($uuid),addslashes($template),$state,$snapshot["name"],$vmpreview);
echo "| $tab|__ ".$snapshot["name"]." | $snapshotdesc | $snapshotdatetime | $snapshotstate | $snapshotparent | $snapshotmemory | ";
$tab .=" " ;
}
echo "";
}
}
echo " ";
}
echo "\0".implode($kvm);
?>
|