mirror of
https://github.com/unraid/webgui.git
synced 2026-04-20 17:02:10 -05:00
vm manager: Only show VM Templates when Adding a VM; clean up vm list code; eliminate extra libvirt file require
This commit is contained in:
@@ -16,434 +16,12 @@ Markdown="false"
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
exec('cat /sys/devices/system/cpu/*/topology/thread_siblings_list|sort -nu', $cpus);
|
||||
|
||||
function showCPUs($uuid) {
|
||||
global $cpus;
|
||||
$arrConfig = domain_to_config($uuid);
|
||||
echo "<div class='four'>";
|
||||
foreach ($cpus as $pair) {
|
||||
unset($cpu1,$cpu2);
|
||||
list($cpu1, $cpu2) = preg_split('/[,-]/',$pair);
|
||||
$check = in_array($cpu1, $arrConfig['domain']['vcpu']) ? 'fa-check-square-o' : 'fa-square-o';
|
||||
if (!$cpu2) {
|
||||
echo "<label><i class='fa $check'></i> cpu $cpu1</label>";
|
||||
} else {
|
||||
echo "<label class='cpu1'><i class='fa $check'></i> cpu $cpu1 / $cpu2</label>";
|
||||
$check = in_array($cpu2, $arrConfig['domain']['vcpu']) ? 'fa-check-square-o' : 'fa-square-o';
|
||||
echo "<label class='cpu2'><i class='fa $check'></i></label>";
|
||||
}
|
||||
}
|
||||
echo "</div>";
|
||||
}
|
||||
$action = array_key_exists('action', $_GET) ? $_GET['action'] : '';
|
||||
$subaction = array_key_exists('subaction', $_GET) ? $_GET['subaction'] : '';
|
||||
$uuid = $_GET['uuid'];
|
||||
if ($_GET['refresh']) {
|
||||
$name = $_GET['name'];
|
||||
if($lv->domain_is_active($name)){
|
||||
echo "<meta http-equiv='refresh' content='5; url=/VMs?name=$name&refresh=true'>";
|
||||
$msg = "Waiting for $name to shutdown...";
|
||||
}else{
|
||||
echo "<script>clearHistory();</script>";
|
||||
$msg = "$name has been shutdown";
|
||||
}
|
||||
}
|
||||
if ($action) {
|
||||
|
||||
}else{
|
||||
if ($subaction) {
|
||||
$domName = $lv->domain_get_name_by_uuid($uuid);
|
||||
if ($subaction == 'domain-diskdev') {
|
||||
$msg = $lv->domain_set_disk_dev($domName, $_GET['olddev'], $_POST['diskdev']) ?
|
||||
$domName.' disk dev has been changed from '.$_GET['olddev'].' to '.$_POST['diskdev']:
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'disk-resize') {
|
||||
$capacity = str_replace(["KB","MB","GB","TB","PB", " ", ","], ["K","M","G","T","P", "", ""], strtoupper($_POST['cap']));
|
||||
$oldcap = str_replace(["KB","MB","GB","TB","PB", " ", ","], ["K","M","G","T","P", "", ""], strtoupper($_GET['oldcap']));
|
||||
if (substr($oldcap,0,-1) < substr($capacity,0,-1)){
|
||||
shell_exec("qemu-img resize -q ".escapeshellarg($_GET['disk'])." ".escapeshellarg($capacity));
|
||||
$msg = $domName." disk capacity has been changed to $capacity";
|
||||
}else {
|
||||
$msg = "Error: disk capacity has to be greater than {$_GET['oldcap']}";
|
||||
}
|
||||
}
|
||||
elseif ($subaction == 'cdrom-change') {
|
||||
$msg = $lv->domain_change_cdrom($domName, $_POST['cdrom'], $_GET['dev'], $_GET['bus']) ?
|
||||
"$domName cdrom has been changed" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'memory-change') {
|
||||
$msg = $lv->domain_set_memory($domName, $_GET['memory']*1024) ?
|
||||
"$domName memory has been changed to ".$_GET['memory']." MiB" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'vcpu-change') {
|
||||
$vcpu = $_GET['vcpu'];
|
||||
$msg = $lv->domain_set_vcpu($domName, $vcpu) ?
|
||||
"$domName vcpu number has been changed to $vcpu" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'bootdev-change') {
|
||||
$bootdev = $_GET['bootdev'];
|
||||
$msg = $lv->domain_set_boot_device($domName, $bootdev) ?
|
||||
"$domName boot device has been changed to $bootdev" :
|
||||
"Error: ".$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'disk-remove') {
|
||||
$msg = $lv->domain_disk_remove($domName, $_GET['dev']) ?
|
||||
"$domName disk has been removed" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-create') {
|
||||
$msg = $lv->domain_snapshot_create($domName) ?
|
||||
"Snapshot for $domName has been created" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-delete') {
|
||||
$msg = $lv->domain_snapshot_delete($domName, $_GET['snap']) ?
|
||||
"Snapshot for $domName has been deleted" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-revert') {
|
||||
$msg = $lv->domain_snapshot_revert($domName, $_GET['snap']) ?
|
||||
"$domName has been reverted" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-desc') {
|
||||
$msg = $lv->snapshot_set_metadata($domName, $_GET['snap'], $_POST['snapdesc']) ?
|
||||
"Snapshot description for $domName has been saved":
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
echo "<script>clearHistory();</script>";
|
||||
}
|
||||
echo "<table class='tablesorter shift kvm' id='kvm_table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='header'><i class='fa fa-th-list'></i></th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>Description</th>
|
||||
<th class='header'>CPUs</th>
|
||||
<th class='header'>Memory</th>
|
||||
<th class='header'>vDisks</th>
|
||||
<th class='header'>Graphics</th>
|
||||
<th class='header'>Autostart</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id='kvm_list'>";
|
||||
//Get domain variables for each domain
|
||||
if ($libvirt_running == "yes")
|
||||
$doms = $lv->get_domains();
|
||||
if(!is_array($doms)){
|
||||
if ($libvirt_running == "yes") {
|
||||
echo "<tr><td></td><td colspan=\"7\">No Virtual Machines Installed</td></tr>";
|
||||
$msg = "No VMs defined. Create from template or add XML.";
|
||||
} else {
|
||||
$msg = "Libvirt is not running. Goto Settings tab then click Start.";
|
||||
}
|
||||
} else {
|
||||
sort($doms);
|
||||
$contextMenus = [];
|
||||
|
||||
for ($i = 0; $i < sizeof($doms); $i++) {
|
||||
$name = $doms[$i];
|
||||
$res = $lv->get_domain_by_name($name);
|
||||
$desc = $lv->domain_get_description($res);
|
||||
$uuid = $lv->domain_get_uuid($res);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$id = $lv->domain_get_id($res);
|
||||
$is_autostart = $lv->domain_get_autostart($res);
|
||||
$state = $lv->domain_state_translate($dom['state']);
|
||||
$arrConfig = domain_to_config($uuid);
|
||||
if ($state == 'running') {
|
||||
$mem = $dom['memory'] / 1024;
|
||||
}else{
|
||||
$mem = $lv->domain_get_memory($res)/1024;
|
||||
}
|
||||
$mem = round($mem).'M';
|
||||
$vcpu = $dom['nrVirtCpu'];
|
||||
$auto = $is_autostart ? 'checked="checked"':"";
|
||||
$template = $lv->_get_single_xpath_result($res, '//domain/metadata/*[local-name()=\'vmtemplate\']/@name');
|
||||
if (empty($template)) {
|
||||
$template = 'Custom';
|
||||
}
|
||||
$log = (is_file('/var/log/libvirt/qemu/' . $name . '.log') ? 'libvirt/qemu/' . $name . '.log' : '');
|
||||
if (($diskcnt = $lv->get_disk_count($res)) > 0) {
|
||||
$disks = $diskcnt.' / '.$lv->get_disk_capacity($res);
|
||||
$diskdesc = 'Current physical size: '.$lv->get_disk_capacity($res, true);
|
||||
}else{
|
||||
$disks = '-';
|
||||
$diskdesc = '';
|
||||
}
|
||||
|
||||
$vncport = $lv->domain_get_vnc_port($res);
|
||||
$arrValidDiskBuses = getValidDiskBuses();
|
||||
|
||||
$vnc = '';
|
||||
$graphics = '';
|
||||
if ($vncport > 0) {
|
||||
$wsport = $lv->domain_get_ws_port($res);
|
||||
$vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host=' . $_SERVER['HTTP_HOST'] . '&port=' . $wsport . '&path=';
|
||||
$graphics = 'VNC:'.$vncport;
|
||||
} else if ($vncport == -1) {
|
||||
$graphics = 'VNC:auto';
|
||||
} else if (!empty($arrConfig['gpu'])) {
|
||||
$arrValidGPUDevices = getValidGPUDevices();
|
||||
foreach($arrConfig['gpu'] as $arrGPU) {
|
||||
foreach($arrValidGPUDevices as $arrDev) {
|
||||
if ($arrGPU['id'] == $arrDev['id']) {
|
||||
$graphics .= $arrDev['name']."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$graphics = str_replace("\n", "<br>", trim($graphics));
|
||||
}
|
||||
|
||||
unset($tmp);
|
||||
if (!$id)
|
||||
$id = '-';
|
||||
unset($dom);
|
||||
|
||||
$contextMenus[] = sprintf("addVMContext('%s', '%s', '%s', '%s', '%s', '%s');", addslashes($name), addslashes($uuid), addslashes($template), $state, addslashes($vnc), addslashes($log));
|
||||
|
||||
$vmicon = $lv->domain_get_icon_url($res);
|
||||
|
||||
//Domain information
|
||||
echo "<tr style='background-color:".bcolor($i)."'>
|
||||
<td style=\"width: 48px; padding: 4px\">".renderVMContentIcon($uuid, $name, $vmicon, $state)."</td>
|
||||
<td><a href='#' onclick=\"return toggle_id('name$i');\" title='click for more VM info'>$name</a></td>
|
||||
<td>$desc</td>
|
||||
<td><a class='vcpu$i' style='cursor:pointer'>$vcpu</a></td>
|
||||
<td>$mem</td>
|
||||
<td title='$diskdesc'>$disks</td>
|
||||
<td>$graphics</td>
|
||||
<td><input class='autostart' type='checkbox' name='auto_$name' title='Toggle VM auostart' $auto uuid='$uuid'></td>";
|
||||
|
||||
echo "</tr>
|
||||
<tr id='name$i' style='display: none'>";
|
||||
/* Disk device information */
|
||||
echo "<td colspan='7' style='overflow: hidden'>
|
||||
<table class='tablesorter domdisk' id='domdisk_table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='header'><i class='fa fa-hdd-o'></i><b> Disk devices </b></th>
|
||||
<th class='header'>Bus</th>
|
||||
<th class='header'>Capacity</th>
|
||||
<th class='header'>Allocation</th>
|
||||
<th class='header'>Actions</th><th class='header'></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id='domdisk_list'>";
|
||||
/* Display domain disks */
|
||||
$tmp = $lv->get_disk_stats($res);
|
||||
if (!empty($tmp)) {
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$capacity = $lv->format_size($tmp[$ii]['capacity'], 0);
|
||||
$allocation = $lv->format_size($tmp[$ii]['allocation'], 0);
|
||||
$disk = (array_key_exists('file', $tmp[$ii])) ? $tmp[$ii]['file'] : $tmp[$ii]['partition'];
|
||||
$dev = $tmp[$ii]['device'];
|
||||
$bus = $tmp[$ii]['bus'];
|
||||
echo "<tr>
|
||||
<td>$disk</td>
|
||||
<td>{$arrValidDiskBuses[$bus]}</td>
|
||||
<td title='Click to increase Disk Size'>
|
||||
<form method='post' action='?subaction=disk-resize&uuid=$uuid&disk=$disk&oldcap=$capacity' /><span class='diskresize' style='width:30px'>
|
||||
<span class='text' ><a href='#'> $capacity </a></span>
|
||||
<input class='input' type='text' style='width:46px' name='cap' value='$capacity' val='diskresize' hidden />
|
||||
</span>
|
||||
</form>
|
||||
</td>
|
||||
<td>$allocation</td>
|
||||
<td>";
|
||||
/* add detach button if shutoff */
|
||||
if ($state == 'shutoff')
|
||||
echo "detach <a href='#' onclick=\"swal({title:'Are you sure?',text:'Detach ".basename($disk)." from VM: ".$name."',type:'warning',showCancelButton:true},function(){ajaxVMDispatch('attached',{action:'disk-remove',uuid:'".$uuid."',dev:'".$dev."'});});return false;\" title='detach disk from VM'>
|
||||
<i class='fa fa-eject blue'></i></a>";
|
||||
else
|
||||
echo "N/A";
|
||||
echo '</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
/*end display disk display*/
|
||||
|
||||
/* Display domain cdroms */
|
||||
$tmp = $lv->get_cdrom_stats($res);
|
||||
if (!empty($tmp)) {
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$capacity = $lv->format_size($tmp[$ii]['capacity'], 0);
|
||||
$allocation = $lv->format_size($tmp[$ii]['allocation'], 0);
|
||||
$disk = (array_key_exists('file', $tmp[$ii])) ? $tmp[$ii]['file'] : $tmp[$ii]['partition'];
|
||||
$dev = $tmp[$ii]['device'];
|
||||
$bus = $tmp[$ii]['bus'];
|
||||
echo "<tr>
|
||||
<td>$disk</td>
|
||||
<td>{$arrValidDiskBuses[$bus]}</td>
|
||||
<td>$capacity</td>
|
||||
<td>$allocation</td>
|
||||
<td>";
|
||||
/* add detach button if shutoff */
|
||||
if ($state == 'shutoff')
|
||||
echo "detach <a href='#' onclick=\"swal({title:'Are you sure?',text:'Detach ".basename($disk)." from VM: ".$name."',type:'warning',showCancelButton:true},function(){ajaxVMDispatch('attached',{action:'disk-remove',uuid:'".$uuid."',dev:'".$dev."'});});return false;\" title='detach disk from VM'>
|
||||
<i class='fa fa-eject blue'></i></a>";
|
||||
else
|
||||
echo "N/A";
|
||||
echo ' </td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
/*end display cdrom display*/
|
||||
echo "</tbody></table>";
|
||||
unset($capacity, $dev, $disk, $type, $vcpu);
|
||||
/* Backup information */
|
||||
/* echo "<table class='tablesorter domsnap' id='backup_table'>
|
||||
<tr>
|
||||
<thead>
|
||||
<th class='header'><i class='fa fa-floppy-o'></i><b> Backups </b>";
|
||||
if ($state == 'shutoff')
|
||||
echo "<a href='?subaction=backup-create&uuid=$uuid' title='create a backup of current domain'><i class='fa fa-plus green'></i></a>";
|
||||
echo "</th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>Date</th>
|
||||
<th class='header'>Time</th>
|
||||
<th class='header'>Description</th>
|
||||
<th class='header'>Actions ";
|
||||
if ($state == 'running')
|
||||
echo " <small>(stop to enable)</small>";
|
||||
echo "</th><th class='header'></th><th class='header'></th>
|
||||
</thead>
|
||||
</tr>";
|
||||
if (false) {
|
||||
sort($tmp);
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$backup = $tmp[$ii];
|
||||
$date = date("D d M Y",$name);
|
||||
$time = date("H:i:s",$backup);
|
||||
$info = $lv->domain_backup_get_info($name, $backup);
|
||||
if(empty($info)){
|
||||
$info = "Click to change description";
|
||||
$val = "";}
|
||||
else
|
||||
$val = $info;
|
||||
echo "<tr style='background-color:".bcolor($ii)."'>
|
||||
<td>".($ii+1)."</td>
|
||||
<td>$backup</td>
|
||||
<td>$date</td>
|
||||
<td>$time</td>
|
||||
<td><form method='post' action='?subaction=backup-desc&uuid=$uuid&backup=$backup' /><span class='backdesc'>
|
||||
<span class='text'><a href='#'> $info </a></span>
|
||||
<input class='input' type='text' name='backdesc' value='$val' val='backdesc' hidden placeholder='Click to change description' title='Click to change description'/>
|
||||
</span></form>
|
||||
</td>
|
||||
<td>
|
||||
revert <a href='?subaction=backup-revert&uuid=$uuid&backup=$backup'><i class='fa fa-refresh lightblue'></i></a>
|
||||
</td>
|
||||
<td>
|
||||
delete <a href='?subaction=backup-delete&uuid=$uuid&backup=$backup'><i class='fa fa-remove red'></i></a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "<tr><td>no backups</td>
|
||||
<td>none</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
</tr>";
|
||||
echo '</table>';*/
|
||||
|
||||
/* End Backup information*/
|
||||
|
||||
/* Snapshot information */
|
||||
/*
|
||||
echo "<table class='tablesorter domsnap' id='domsnap_table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='header'><i class='fa fa-camera-retro'></i><b> Snapshots </b>";
|
||||
if ($state == 'shutoff')
|
||||
echo "<a href='?subaction=snap-create&uuid=$uuid' title='create a snapshot of current domain state'><i class='fa fa-plus green'></i></a>";
|
||||
echo "</th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>Date</th>
|
||||
<th class='header'>Time</th>
|
||||
<th class='header'>Description</th>
|
||||
<th class='header'>Actions ";
|
||||
if ($state == 'running')
|
||||
echo " <small>(stop to enable)</small>";
|
||||
echo "</th><th class='header'></th><th class='header'></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id=''domsnap_list>";
|
||||
$tmp = $lv->domain_snapshots_list($res);
|
||||
if (!empty($tmp)) {
|
||||
sort($tmp);
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$snap = $tmp[$ii];
|
||||
$date = date("D d M Y",$snap);
|
||||
$time = date("H:i:s",$snap);
|
||||
$info = $lv->domain_snapshot_get_info($res, $snap);
|
||||
if(empty($info)){
|
||||
$info = "Click to change description";
|
||||
$val = "";}
|
||||
else
|
||||
$val = $info;
|
||||
echo "<tr style='background-color:".bcolor($ii)."'>
|
||||
<td>".($ii+1)."</td>
|
||||
<td>$snap</td>
|
||||
<td>$date</td>
|
||||
<td>$time</td>
|
||||
<td><form method='post' action='?subaction=snap-desc&uuid=$uuid&snap=$snap' /><span class='snapdesc'>
|
||||
<span class='text'><a href='#'> $info </a></span>
|
||||
<input class='input' type='text' name='snapdesc' value='$val' val='snapdesc' hidden placeholder='Click to change description' title='Click to change description'/>
|
||||
</span></form>
|
||||
</td>
|
||||
<td>
|
||||
revert <a href='?subaction=snap-revert&uuid=$uuid&snap=$snap'><i class='fa fa-refresh lightblue'></i></a>
|
||||
</td>
|
||||
<td>
|
||||
delete <a href='?subaction=snap-delete&uuid=$uuid&snap=$snap'><i class='fa fa-trash red'></i></a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "<tr><td>no snapshots</td>
|
||||
<td>none</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
</tr>";
|
||||
echo '</tbody></table>';
|
||||
*/
|
||||
echo '</td></tr>';
|
||||
}
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
}
|
||||
/* End Snapshot information */
|
||||
unset($name, $val);
|
||||
if($msg){
|
||||
if(strpos($msg, "rror:"))
|
||||
$color = 'red-text';
|
||||
else
|
||||
$color = 'green-text';
|
||||
echo "<script type='text/javascript'>$(function() { $('#countdown').html('<span class=\"".$color."\">".$msg."</span>');}); </script>";
|
||||
}
|
||||
?>
|
||||
|
||||
<? if ($display['tabs']==0): ?>
|
||||
<input type="button" id="btnAddVM" value="Add VM"/>
|
||||
<? endif ?>
|
||||
|
||||
<style>
|
||||
<link type="text/css" rel="stylesheet" href="/plugins/dynamix.vm.manager/styles/dynamix.vm.manager.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||
<style type="text/css">
|
||||
body{-webkit-overflow-scrolling:touch;}
|
||||
.fileTree{width:305px;max-height:150px;overflow:scroll;position:absolute;z-index:100;display:none;}
|
||||
div.four{font-family:arimo;font-size:12px;color:#A0A0A0;width:300px}
|
||||
div.four label{float:left;display:table-cell;width:25%}
|
||||
div.four label:nth-child(4n+4){float:none;clear:both}
|
||||
@@ -453,7 +31,394 @@ div.Panel{float:unset;margin:4px;height:inherit;border:none;}
|
||||
div.Panel:hover{background-color:unset;}
|
||||
div.PanelText{display:none;}
|
||||
</style>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
exec('cat /sys/devices/system/cpu/*/topology/thread_siblings_list|sort -nu', $cpus);
|
||||
|
||||
function showCPUs($uuid) {
|
||||
global $cpus;
|
||||
$arrConfig = domain_to_config($uuid);
|
||||
echo "<div class='four'>";
|
||||
foreach ($cpus as $pair) {
|
||||
unset($cpu1,$cpu2);
|
||||
list($cpu1, $cpu2) = preg_split('/[,-]/',$pair);
|
||||
$check = in_array($cpu1, $arrConfig['domain']['vcpu']) ? 'fa-check-square-o' : 'fa-square-o';
|
||||
if (!$cpu2) {
|
||||
echo "<label><i class='fa $check'></i> cpu $cpu1</label>";
|
||||
} else {
|
||||
echo "<label class='cpu1'><i class='fa $check'></i> cpu $cpu1 / $cpu2</label>";
|
||||
$check = in_array($cpu2, $arrConfig['domain']['vcpu']) ? 'fa-check-square-o' : 'fa-square-o';
|
||||
echo "<label class='cpu2'><i class='fa $check'></i></label>";
|
||||
}
|
||||
}
|
||||
echo "</div>";
|
||||
}
|
||||
$subaction = array_key_exists('subaction', $_GET) ? $_GET['subaction'] : '';
|
||||
$uuid = $_GET['uuid'];
|
||||
if ($_GET['refresh']) {
|
||||
$name = $_GET['name'];
|
||||
if ($lv->domain_is_active($name)) {
|
||||
echo "<meta http-equiv='refresh' content='5; url=/VMs?name=$name&refresh=true'>";
|
||||
$msg = "Waiting for $name to shutdown...";
|
||||
} else {
|
||||
echo "<script>clearHistory();</script>";
|
||||
$msg = "$name has been shutdown";
|
||||
}
|
||||
}
|
||||
if ($subaction) {
|
||||
$domName = $lv->domain_get_name_by_uuid($uuid);
|
||||
if ($subaction == 'disk-resize') {
|
||||
$capacity = str_replace(["KB","MB","GB","TB","PB", " ", ","], ["K","M","G","T","P", "", ""], strtoupper($_POST['cap']));
|
||||
$oldcap = str_replace(["KB","MB","GB","TB","PB", " ", ","], ["K","M","G","T","P", "", ""], strtoupper($_GET['oldcap']));
|
||||
if (substr($oldcap,0,-1) < substr($capacity,0,-1)){
|
||||
shell_exec("qemu-img resize -q ".escapeshellarg($_GET['disk'])." ".escapeshellarg($capacity));
|
||||
$msg = $domName." disk capacity has been changed to $capacity";
|
||||
}else {
|
||||
$msg = "Error: disk capacity has to be greater than {$_GET['oldcap']}";
|
||||
}
|
||||
}
|
||||
elseif ($subaction == 'disk-remove') {
|
||||
$msg = $lv->domain_disk_remove($domName, $_GET['dev']) ?
|
||||
"$domName disk has been removed" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-create') {
|
||||
$msg = $lv->domain_snapshot_create($domName) ?
|
||||
"Snapshot for $domName has been created" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-delete') {
|
||||
$msg = $lv->domain_snapshot_delete($domName, $_GET['snap']) ?
|
||||
"Snapshot for $domName has been deleted" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-revert') {
|
||||
$msg = $lv->domain_snapshot_revert($domName, $_GET['snap']) ?
|
||||
"$domName has been reverted" :
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
elseif ($subaction == 'snap-desc') {
|
||||
$msg = $lv->snapshot_set_metadata($domName, $_GET['snap'], $_POST['snapdesc']) ?
|
||||
"Snapshot description for $domName has been saved":
|
||||
'Error: '.$lv->get_last_error();
|
||||
}
|
||||
echo "<script>clearHistory();</script>";
|
||||
}
|
||||
|
||||
$contextMenus = [];
|
||||
|
||||
//Get domain variables for each domain
|
||||
if ($libvirt_running == "yes") {
|
||||
$doms = $lv->get_domains();
|
||||
sort($doms);
|
||||
}
|
||||
|
||||
echo '<table class="tablesorter shift kvm" id="kvm_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="header"><i class="fa fa-th-list"></i></th>
|
||||
<th class="header">Name</th>
|
||||
<th class="header">Description</th>
|
||||
<th class="header">CPUs</th>
|
||||
<th class="header">Memory</th>
|
||||
<th class="header">vDisks</th>
|
||||
<th class="header">Graphics</th>
|
||||
<th class="header">Autostart</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="kvm_list">';
|
||||
|
||||
if (empty($doms)) {
|
||||
if ($libvirt_running == "yes") {
|
||||
echo '<tr><td></td><td colspan="6">No Virtual Machines Installed</td></tr>';
|
||||
$msg = 'No VMs defined. Create from template or add XML.';
|
||||
} else {
|
||||
$msg = 'Libvirt is not running. Goto Settings tab then click Start.';
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < sizeof($doms); $i++) {
|
||||
$name = $doms[$i];
|
||||
$res = $lv->get_domain_by_name($name);
|
||||
$desc = $lv->domain_get_description($res);
|
||||
$uuid = $lv->domain_get_uuid($res);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$id = $lv->domain_get_id($res) ?: '-';
|
||||
$is_autostart = $lv->domain_get_autostart($res);
|
||||
$state = $lv->domain_state_translate($dom['state']);
|
||||
$vmicon = $lv->domain_get_icon_url($res);
|
||||
$arrConfig = domain_to_config($uuid);
|
||||
if ($state == 'running') {
|
||||
$mem = $dom['memory'] / 1024;
|
||||
}else{
|
||||
$mem = $lv->domain_get_memory($res) / 1024;
|
||||
}
|
||||
$mem = round($mem).'M';
|
||||
$vcpu = $dom['nrVirtCpu'];
|
||||
$auto = $is_autostart ? 'checked="checked"':"";
|
||||
$template = $lv->_get_single_xpath_result($res, '//domain/metadata/*[local-name()=\'vmtemplate\']/@name');
|
||||
if (empty($template)) {
|
||||
$template = 'Custom';
|
||||
}
|
||||
$log = (is_file('/var/log/libvirt/qemu/'.$name.'.log') ? 'libvirt/qemu/'.$name.'.log' : '');
|
||||
|
||||
$disks = '-';
|
||||
$diskdesc = '';
|
||||
if (($diskcnt = $lv->get_disk_count($res)) > 0) {
|
||||
$disks = $diskcnt.' / '.$lv->get_disk_capacity($res);
|
||||
$diskdesc = 'Current physical size: '.$lv->get_disk_capacity($res, true);
|
||||
}
|
||||
|
||||
$arrValidDiskBuses = getValidDiskBuses();
|
||||
$vncport = $lv->domain_get_vnc_port($res);
|
||||
$vnc = '';
|
||||
$graphics = '';
|
||||
if ($vncport > 0) {
|
||||
$wsport = $lv->domain_get_ws_port($res);
|
||||
$vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host=' . $_SERVER['HTTP_HOST'] . '&port=' . $wsport . '&path=';
|
||||
$graphics = 'VNC:'.$vncport;
|
||||
}
|
||||
else if ($vncport == -1) {
|
||||
$graphics = 'VNC:auto';
|
||||
}
|
||||
else if (!empty($arrConfig['gpu'])) {
|
||||
$arrValidGPUDevices = getValidGPUDevices();
|
||||
foreach($arrConfig['gpu'] as $arrGPU) {
|
||||
foreach($arrValidGPUDevices as $arrDev) {
|
||||
if ($arrGPU['id'] == $arrDev['id']) {
|
||||
$graphics .= $arrDev['name']."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$graphics = str_replace("\n", "<br>", trim($graphics));
|
||||
}
|
||||
|
||||
unset($dom);
|
||||
|
||||
$contextMenus[] = sprintf("addVMContext('%s', '%s', '%s', '%s', '%s', '%s');", addslashes($name), addslashes($uuid), addslashes($template), $state, addslashes($vnc), addslashes($log));
|
||||
|
||||
//Domain information
|
||||
echo '<tr style="background-color:'.bcolor($i).'">
|
||||
<td style="width: 48px; padding: 4px">'.renderVMContentIcon($uuid, $name, $vmicon, $state).'</td>
|
||||
<td><a href="#" onclick="return toggle_id(\'name'.$i.'\');" title="click for more VM info">'.$name.'</a></td>
|
||||
<td>'.$desc.'</td>
|
||||
<td><a class="vcpu'.$i.'" style="cursor:pointer">'.$vcpu.'</a></td>
|
||||
<td>'.$mem.'</td>
|
||||
<td title="'.$diskdesc.'">'.$disks.'</td>
|
||||
<td>'.$graphics.'</td>
|
||||
<td><input class="autostart" type="checkbox" name="auto_'.$name.'" title="Toggle VM auostart" '.$auto.' uuid="'.$uuid.'"></td>
|
||||
</tr>';
|
||||
|
||||
/* Disk device information */
|
||||
echo '<tr id="name'.$i.'" style="display: none">
|
||||
<td colspan="7" style="overflow: hidden">
|
||||
<table class="tablesorter domdisk" id="domdisk_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="header"><i class="fa fa-hdd-o"></i><b> Disk devices </b></th>
|
||||
<th class="header">Bus</th>
|
||||
<th class="header">Capacity</th>
|
||||
<th class="header">Allocation</th>
|
||||
<th class="header">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="domdisk_list">';
|
||||
|
||||
/* Display domain disks */
|
||||
foreach ($lv->get_disk_stats($res) as $arrDisk) {
|
||||
$capacity = $lv->format_size($arrDisk['capacity'], 0);
|
||||
$allocation = $lv->format_size($arrDisk['allocation'], 0);
|
||||
$disk = (array_key_exists('file', $arrDisk)) ? $arrDisk['file'] : $arrDisk['partition'];
|
||||
$dev = $arrDisk['device'];
|
||||
$bus = $arrDisk['bus'];
|
||||
echo '<tr>
|
||||
<td>'.$disk.'</td>
|
||||
<td>'.$arrValidDiskBuses[$bus].'</td>';
|
||||
|
||||
if ($state == 'shutoff') {
|
||||
echo '<td title="Click to increase Disk Size">
|
||||
<form method="post" action="?subaction=disk-resize&uuid='.$uuid.'&disk='.$disk.'&oldcap='.$capacity.'">
|
||||
<span class="diskresize" style="width:30px">
|
||||
<span class="text"><a href="#">'.$capacity.'</a></span>
|
||||
<input class="input" type="text" style="width:46px" name="cap" value="'.$capacity.'" val="diskresize" hidden />
|
||||
</span>
|
||||
</form>
|
||||
</td>
|
||||
<td>'.$allocation.'</td>
|
||||
<td>detach <a href="#" onclick="swal({title:\'Are you sure?\',text:\'Detach '.basename($disk).' from VM: '.$name.'\',type:\'warning\',showCancelButton:true},function(){ajaxVMDispatch(\'attached\',{action:\'disk-remove\',uuid:\''.$uuid.'\',dev:\''.$dev.'\'});});return false;" title="detach disk from VM"><i class="fa fa-eject blue"></i></a>
|
||||
</td>';
|
||||
} else {
|
||||
echo '<td>'.$capacity.'</td>
|
||||
<td>'.$allocation.'</td>
|
||||
<td>N/A</td>';
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
}
|
||||
/* end Display domain disks */
|
||||
|
||||
/* Display domain cdroms */
|
||||
foreach ($lv->get_cdrom_stats($res) as $arrCD) {
|
||||
$capacity = $lv->format_size($arrCD['capacity'], 0);
|
||||
$allocation = $lv->format_size($arrCD['allocation'], 0);
|
||||
$disk = (array_key_exists('file', $arrCD)) ? $arrCD['file'] : $arrCD['partition'];
|
||||
$dev = $arrCD['device'];
|
||||
$bus = $arrCD['bus'];
|
||||
echo '<tr>
|
||||
<td>'.$disk.'</td>
|
||||
<td>'.$arrValidDiskBuses[$bus].'</td>
|
||||
<td>'.$capacity.'</td>
|
||||
<td>'.$allocation.'</td>
|
||||
<td>';
|
||||
|
||||
if ($state == 'shutoff')
|
||||
echo 'detach <a href="#" onclick="swal({title:\'Are you sure?\',text:\'Detach '.basename($disk).' from VM: '.$name.'\',type:\'warning\',showCancelButton:true},function(){ajaxVMDispatch(\'attached\',{action:\'disk-remove\',uuid:\''.$uuid.'\',dev:\''.$dev.'\'});});return false;" title="detach disk from VM"><i class="fa fa-eject blue"></i></a>';
|
||||
else
|
||||
echo 'N/A';
|
||||
|
||||
echo ' </td>
|
||||
</tr>';
|
||||
}
|
||||
/* end Display domain cdroms */
|
||||
|
||||
echo '</tbody></table>';
|
||||
|
||||
/* Backup information */
|
||||
/* echo "<table class='tablesorter domsnap' id='backup_table'>
|
||||
<tr>
|
||||
<thead>
|
||||
<th class='header'><i class='fa fa-floppy-o'></i><b> Backups </b>";
|
||||
if ($state == 'shutoff')
|
||||
echo "<a href='?subaction=backup-create&uuid=$uuid' title='create a backup of current domain'><i class='fa fa-plus green'></i></a>";
|
||||
echo "</th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>Date</th>
|
||||
<th class='header'>Time</th>
|
||||
<th class='header'>Description</th>
|
||||
<th class='header'>Actions ";
|
||||
if ($state == 'running')
|
||||
echo " <small>(stop to enable)</small>";
|
||||
echo "</th><th class='header'></th><th class='header'></th>
|
||||
</thead>
|
||||
</tr>";
|
||||
if (false) {
|
||||
sort($tmp);
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$backup = $tmp[$ii];
|
||||
$date = date("D d M Y",$name);
|
||||
$time = date("H:i:s",$backup);
|
||||
$info = $lv->domain_backup_get_info($name, $backup);
|
||||
if(empty($info)){
|
||||
$info = "Click to change description";
|
||||
$val = "";}
|
||||
else
|
||||
$val = $info;
|
||||
echo "<tr style='background-color:".bcolor($ii)."'>
|
||||
<td>".($ii+1)."</td>
|
||||
<td>$backup</td>
|
||||
<td>$date</td>
|
||||
<td>$time</td>
|
||||
<td><form method='post' action='?subaction=backup-desc&uuid=$uuid&backup=$backup' /><span class='backdesc'>
|
||||
<span class='text'><a href='#'> $info </a></span>
|
||||
<input class='input' type='text' name='backdesc' value='$val' val='backdesc' hidden placeholder='Click to change description' title='Click to change description'/>
|
||||
</span></form>
|
||||
</td>
|
||||
<td>
|
||||
revert <a href='?subaction=backup-revert&uuid=$uuid&backup=$backup'><i class='fa fa-refresh lightblue'></i></a>
|
||||
</td>
|
||||
<td>
|
||||
delete <a href='?subaction=backup-delete&uuid=$uuid&backup=$backup'><i class='fa fa-remove red'></i></a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "<tr><td>no backups</td>
|
||||
<td>none</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
</tr>";
|
||||
echo '</table>';*/
|
||||
|
||||
/* End Backup information*/
|
||||
|
||||
/* Snapshot information */
|
||||
/*
|
||||
echo "<table class='tablesorter domsnap' id='domsnap_table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='header'><i class='fa fa-camera-retro'></i><b> Snapshots </b>";
|
||||
if ($state == 'shutoff')
|
||||
echo "<a href='?subaction=snap-create&uuid=$uuid' title='create a snapshot of current domain state'><i class='fa fa-plus green'></i></a>";
|
||||
echo "</th>
|
||||
<th class='header'>Name</th>
|
||||
<th class='header'>Date</th>
|
||||
<th class='header'>Time</th>
|
||||
<th class='header'>Description</th>
|
||||
<th class='header'>Actions ";
|
||||
if ($state == 'running')
|
||||
echo " <small>(stop to enable)</small>";
|
||||
echo "</th><th class='header'></th><th class='header'></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id=''domsnap_list>";
|
||||
$tmp = $lv->domain_snapshots_list($res);
|
||||
if (!empty($tmp)) {
|
||||
sort($tmp);
|
||||
for ($ii = 0; $ii < sizeof($tmp); $ii++) {
|
||||
$snap = $tmp[$ii];
|
||||
$date = date("D d M Y",$snap);
|
||||
$time = date("H:i:s",$snap);
|
||||
$info = $lv->domain_snapshot_get_info($res, $snap);
|
||||
if(empty($info)){
|
||||
$info = "Click to change description";
|
||||
$val = "";}
|
||||
else
|
||||
$val = $info;
|
||||
echo "<tr style='background-color:".bcolor($ii)."'>
|
||||
<td>".($ii+1)."</td>
|
||||
<td>$snap</td>
|
||||
<td>$date</td>
|
||||
<td>$time</td>
|
||||
<td><form method='post' action='?subaction=snap-desc&uuid=$uuid&snap=$snap' /><span class='snapdesc'>
|
||||
<span class='text'><a href='#'> $info </a></span>
|
||||
<input class='input' type='text' name='snapdesc' value='$val' val='snapdesc' hidden placeholder='Click to change description' title='Click to change description'/>
|
||||
</span></form>
|
||||
</td>
|
||||
<td>
|
||||
revert <a href='?subaction=snap-revert&uuid=$uuid&snap=$snap'><i class='fa fa-refresh lightblue'></i></a>
|
||||
</td>
|
||||
<td>
|
||||
delete <a href='?subaction=snap-delete&uuid=$uuid&snap=$snap'><i class='fa fa-trash red'></i></a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "<tr><td>no snapshots</td>
|
||||
<td>none</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
<td>N/A</td>
|
||||
</tr>";
|
||||
echo '</tbody></table>';
|
||||
*/
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
}
|
||||
/* End Snapshot information */
|
||||
?>
|
||||
|
||||
<input type="button" onclick="addVM()" id="btnAddVM" value="Add VM"/>
|
||||
|
||||
<script src="/webGui/javascript/jquery.filetree.js"></script>
|
||||
<script src="/webGui/javascript/jquery.switchbutton.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/dynamix.vm.manager.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/javascript/vmmanager.js"></script>
|
||||
<script>
|
||||
function vncOpen() {
|
||||
@@ -473,16 +438,24 @@ function toggle_id(itemID){
|
||||
}
|
||||
|
||||
function showInput(){
|
||||
$(this).off('click');
|
||||
$(this).siblings('input').each(function(){$(this).show();});
|
||||
$(this).siblings('input').focus();
|
||||
$(this).hide();
|
||||
$(this).off('click');
|
||||
$(this).siblings('input').each(function(){$(this).show();});
|
||||
$(this).siblings('input').focus();
|
||||
$(this).hide();
|
||||
}
|
||||
|
||||
function hideInput(){
|
||||
$(this).hide();
|
||||
$(this).siblings('span').show();
|
||||
$(this).siblings('span').click(showInput);
|
||||
$(this).hide();
|
||||
$(this).siblings('span').show();
|
||||
$(this).siblings('span').click(showInput);
|
||||
}
|
||||
|
||||
function addVM() {
|
||||
var path = location.pathname;
|
||||
var x = path.indexOf("?");
|
||||
if (x!=-1) path = path.substring(0, x);
|
||||
|
||||
location = path + "/VMTemplates";
|
||||
}
|
||||
|
||||
<?if ($display['resize']):?>
|
||||
@@ -500,42 +473,48 @@ function resize(bind) {
|
||||
<?endif;?>
|
||||
|
||||
$(function() {
|
||||
<?
|
||||
if ($msg) {
|
||||
$color = strpos($msg, "rror:")!==false ? 'red-text' : 'green-text';
|
||||
echo '$(\'#countdown\').html(\'<span class="'.$color.'">'.$msg.'</span>\');';
|
||||
}
|
||||
?>
|
||||
<?for ($i=0; $i < sizeof($doms); $i++):?>
|
||||
<? $name = $doms[$i];?>
|
||||
<? $res = $lv->get_domain_by_name($name);?>
|
||||
<? $uuid = $lv->domain_get_uuid($res);?>
|
||||
$('.vcpu<?=$i?>').tooltipster({
|
||||
trigger:'custom',
|
||||
triggerOpen:{mouseenter:true,click:true,touchstart:true},
|
||||
contentAsHTML:true,
|
||||
animation:'grow',
|
||||
triggerClose:{click:true,scroll:true,mouseleave:true,delay:1},
|
||||
interactive:true,
|
||||
viewportAware:true,
|
||||
functionBefore:function(instance,helper){instance.content("<?=showCPUs($uuid)?>");}
|
||||
});
|
||||
$('.vcpu<?=$i?>').tooltipster({
|
||||
trigger:'custom',
|
||||
triggerOpen:{mouseenter:true,click:true,touchstart:true},
|
||||
contentAsHTML:true,
|
||||
animation:'grow',
|
||||
triggerClose:{click:true,scroll:true,mouseleave:true,delay:1},
|
||||
interactive:true,
|
||||
viewportAware:true,
|
||||
functionBefore:function(instance,helper){instance.content("<?=showCPUs($uuid)?>");}
|
||||
});
|
||||
<?endfor;?>
|
||||
$('.text').click(showInput);
|
||||
$('.input').blur(hideInput);
|
||||
$('#btnAddVM').click(function AddVMEvent() {
|
||||
$('.tab>input#tab2').click();
|
||||
});
|
||||
$('.text').click(showInput);
|
||||
$('.input').blur(hideInput);
|
||||
$('#btnAddVM').click(function AddVMEvent() {
|
||||
$('.tab>input#tab2').click();
|
||||
});
|
||||
|
||||
$('.autostart').switchButton({
|
||||
labels_placement: "right"
|
||||
});
|
||||
$('.autostart').change(function () {
|
||||
$.post( "/plugins/dynamix.vm.manager/VMajax.php", { action: "domain-autostart", uuid: $(this).attr('uuid'), autostart: $(this).prop('checked'), response: "json" }, function( data ) {
|
||||
$(this).prop('checked', data.autostart );
|
||||
}, "json");
|
||||
});
|
||||
$('.autostart').switchButton({
|
||||
labels_placement: "right"
|
||||
});
|
||||
$('.autostart').change(function () {
|
||||
$.post( "/plugins/dynamix.vm.manager/VMajax.php", { action: "domain-autostart", uuid: $(this).attr('uuid'), autostart: $(this).prop('checked'), response: "json" }, function( data ) {
|
||||
$(this).prop('checked', data.autostart );
|
||||
}, "json");
|
||||
});
|
||||
|
||||
<?if ($display['resize']):?>
|
||||
resize();
|
||||
$(window).bind('resize',function(){resize(true);});
|
||||
resize();
|
||||
$(window).bind('resize',function(){resize(true);});
|
||||
<?endif;?>
|
||||
|
||||
context.init({ preventDoubleContext: false });
|
||||
<?=implode("\n\t", $contextMenus)?>
|
||||
context.init({ preventDoubleContext: false });
|
||||
<?=implode("\n\t", $contextMenus)?>
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -17,7 +17,6 @@ Markdown="false"
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Menu="VMs:2"
|
||||
Title="Templates"
|
||||
Title="Add VM"
|
||||
Tag="clipboard"
|
||||
Cond="(pgrep('libvirtd')!==false)"
|
||||
Markdown="false"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2017, Lime Technology
|
||||
@@ -41,7 +41,11 @@ Cond="(pgrep('libvirtd')!==false)"
|
||||
line-height: 12px;
|
||||
}
|
||||
</style>
|
||||
<? foreach($arrAllTemplates as $strName => $arrTemplate):
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
foreach($arrAllTemplates as $strName => $arrTemplate):
|
||||
if (empty($arrTemplate)) {
|
||||
// render header
|
||||
echo '<div class="vmheader">'.$strName.'</div>';
|
||||
@@ -54,4 +58,7 @@ Cond="(pgrep('libvirtd')!==false)"
|
||||
<p><?=htmlspecialchars($strName)?></p>
|
||||
</a>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
<? endforeach; ?>
|
||||
<br>
|
||||
<center><button type='button' onclick='done()'>Cancel</button></center>
|
||||
<br>
|
||||
@@ -13,7 +13,6 @@
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
function requireLibvirt() {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
$strSelectedTemplate = array_keys($arrAllTemplates)[1];
|
||||
|
||||
@@ -20,20 +20,5 @@ if ($var['fsState'] != "Started") {
|
||||
echo "<p class='notice'>Array must be <span class='strong big'>started</span> to view Virtual Machines.</p>";
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<link type="text/css" rel="stylesheet" href="/plugins/dynamix.vm.manager/styles/dynamix.vm.manager.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||
<style type="text/css">
|
||||
body{-webkit-overflow-scrolling:touch;}
|
||||
.fileTree{width:305px;max-height:150px;overflow:scroll;position:absolute;z-index:100;display:none;}
|
||||
</style>
|
||||
<script src="/webGui/javascript/jquery.filetree.js"></script>
|
||||
<script src="/webGui/javascript/jquery.switchbutton.js"></script>
|
||||
<script src="/plugins/dynamix.vm.manager/scripts/dynamix.vm.manager.js"></script>
|
||||
<?
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
if (count($pages)==2) $tabbed = false;
|
||||
?>
|
||||
@@ -2070,7 +2070,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//change vpus for domain
|
||||
//change vpus for domain
|
||||
function domain_set_vcpu($domain, $vcpu) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
|
||||
@@ -2083,7 +2083,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//change memory for domain
|
||||
//change memory for domain
|
||||
function domain_set_memory($domain, $memory) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
if (($old_memory = $this->domain_get_memory($domain)) == $memory)
|
||||
@@ -2095,7 +2095,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//change memory for domain
|
||||
//change memory for domain
|
||||
function domain_set_current_memory($domain, $memory) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
if (($old_memory = $this->domain_get_current_memory($domain)) == $memory)
|
||||
@@ -2107,7 +2107,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//change domain disk dev name
|
||||
//change domain disk dev name
|
||||
function domain_set_disk_dev($domain, $olddev, $dev) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
|
||||
@@ -2122,7 +2122,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//set domain description
|
||||
//set domain description
|
||||
function domain_set_description($domain, $desc) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
|
||||
@@ -2145,7 +2145,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//create metadata node for domain
|
||||
//create metadata node for domain
|
||||
function domain_set_metadata($domain) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
|
||||
@@ -2163,7 +2163,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//set description for snapshot
|
||||
//set description for snapshot
|
||||
function snapshot_set_metadata($domain, $name, $desc) {
|
||||
$this->domain_set_metadata($domain);
|
||||
$domain = $this->get_domain_object($domain);
|
||||
@@ -2184,33 +2184,33 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//get host node info
|
||||
//get host node info
|
||||
function host_get_node_info() {
|
||||
$tmp = libvirt_node_get_info($this->conn);
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//get domain autostart status true or false
|
||||
//get domain autostart status true or false
|
||||
function domain_get_autostart($domain) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
$tmp = libvirt_domain_get_autostart($domain);
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//set domain to start with libvirt
|
||||
//set domain to start with libvirt
|
||||
function domain_set_autostart($domain,$flags) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
$tmp = libvirt_domain_set_autostart($domain,$flags);
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//list all snapshots for domain
|
||||
//list all snapshots for domain
|
||||
function domain_snapshots_list($domain) {
|
||||
$tmp = libvirt_list_domain_snapshots($domain);
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
// create a snapshot and metadata node for description
|
||||
// create a snapshot and metadata node for description
|
||||
function domain_snapshot_create($domain) {
|
||||
$this->domain_set_metadata($domain);
|
||||
$domain = $this->get_domain_object($domain);
|
||||
@@ -2218,7 +2218,7 @@
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//delete snapshot and metadata
|
||||
//delete snapshot and metadata
|
||||
function domain_snapshot_delete($domain, $name) {
|
||||
$this->snapshot_remove_metadata($domain, $name);
|
||||
$name = $this->domain_snapshot_lookup_by_name($domain, $name);
|
||||
@@ -2226,21 +2226,21 @@
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//get resource number of snapshot
|
||||
//get resource number of snapshot
|
||||
function domain_snapshot_lookup_by_name($domain, $name) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
$tmp = libvirt_domain_snapshot_lookup_by_name($domain, $name);
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//revert domain to snapshot state
|
||||
//revert domain to snapshot state
|
||||
function domain_snapshot_revert($domain, $name) {
|
||||
$name = $this->domain_snapshot_lookup_by_name($domain, $name);
|
||||
$tmp = libvirt_domain_snapshot_revert($name);
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//get snapshot description
|
||||
//get snapshot description
|
||||
function domain_snapshot_get_info($domain, $name) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
$tmp = $this->get_xpath($domain, '//domain/metadata/snapshot'.$name, false);
|
||||
@@ -2250,7 +2250,7 @@
|
||||
return $var;
|
||||
}
|
||||
|
||||
//remove snapshot metadata
|
||||
//remove snapshot metadata
|
||||
function snapshot_remove_metadata($domain, $name) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
|
||||
@@ -2265,7 +2265,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//change cdrom media
|
||||
//change cdrom media
|
||||
function domain_change_cdrom($domain, $iso, $dev, $bus) {
|
||||
$domain = $this->get_domain_object($domain);
|
||||
$tmp = libvirt_domain_update_device($domain, "<disk type='file' device='cdrom'><driver name='qemu' type='raw'/><source file=".escapeshellarg($iso)."/><target dev='$dev' bus='$bus'/><readonly/></disk>", VIR_DOMAIN_DEVICE_MODIFY_CONFIG);
|
||||
@@ -2274,7 +2274,7 @@
|
||||
return ($tmp) ? $tmp : $this->_set_last_error();
|
||||
}
|
||||
|
||||
//change disk capacity
|
||||
//change disk capacity
|
||||
function disk_set_cap($disk, $cap) {
|
||||
$xml = $this->domain_get_xml($domain);
|
||||
$tmp = explode("\n", $xml);
|
||||
@@ -2287,7 +2287,7 @@
|
||||
return $this->domain_define($xml);
|
||||
}
|
||||
|
||||
//change domain boot device
|
||||
//change domain boot device
|
||||
function domain_set_boot_device($domain, $bootdev) {
|
||||
$xml = $this->domain_get_xml($domain);
|
||||
$tmp = explode("\n", $xml);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
|
||||
// Load emhttp variables if needed.
|
||||
if (!isset($var)){
|
||||
|
||||
@@ -632,18 +632,16 @@ table.tablesorter.dominfo{margin-top: 5px;}
|
||||
table.tablesorter.dominfo{margin-left:48px;}
|
||||
table.tablesorter.domdisk{margin-top: 5px;}
|
||||
table.tablesorter.domdisk{margin-left:72px;}
|
||||
table.tablesorter.domdisk th:first-child{width:50%;text-align:left;}
|
||||
table.tablesorter.domdisk td:first-child{width:50%;text-align:left;}
|
||||
table.tablesorter.domdisk th:first-child{width:55%;text-align:left;}
|
||||
table.tablesorter.domdisk td:first-child{width:55%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(2){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(2){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(3){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(3){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(4){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(4){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(5){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(5){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(6){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(6){width:10%;text-align:left;}
|
||||
table.tablesorter.domdisk th:nth-child(5){width:15%;text-align:left;}
|
||||
table.tablesorter.domdisk td:nth-child(5){width:15%;text-align:left;}
|
||||
table.tablesorter.domdisk tr>td+td+td{width:10%;white-space:nowrap;}
|
||||
table.tablesorter.domsnap{margin-top: 5px;}
|
||||
table.tablesorter.domsnap{margin-left:72px;}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
$arrValidMachineTypes = getValidMachineTypes();
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
$arrValidMachineTypes = getValidMachineTypes();
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
$arrValidMachineTypes = getValidMachineTypes();
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
$strXML = '';
|
||||
|
||||
@@ -56,7 +56,6 @@ if ((pgrep('dockerd')!==false) && (empty($display['dashapps']) || $display['dash
|
||||
|
||||
$allVMs = [];
|
||||
if ((pgrep('libvirtd')!==false) && (empty($display['dashapps']) || $display['dashapps'] == 'icons' || $display['dashapps'] == 'vms')) {
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/classes/libvirt_helpers.php";
|
||||
|
||||
$doms = $lv->get_domains();
|
||||
|
||||
Reference in New Issue
Block a user