mirror of
https://github.com/unraid/webgui.git
synced 2026-01-28 20:49:04 -06:00
Add ALL VMs start & stop operation
This commit is contained in:
@@ -116,12 +116,22 @@ div.PanelText{display:none;}
|
||||
<tbody id="kvm_list"><tr><td colspan='8' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i>Please wait... retrieving VM information</td></tr></tbody>
|
||||
</table>
|
||||
<input type="button" onclick="addVM()" id="btnAddVM" value="Add VM"/>
|
||||
<input type="button" onclick="startAll()" value="Start all VMs"/>
|
||||
<input type="button" onclick="stopAll()" value="Stop all VMs"/>
|
||||
|
||||
<script src="<?autov('/webGui/javascript/jquery.filetree.js')?>"></script>
|
||||
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
|
||||
<script src="<?autov('/plugins/dynamix.vm.manager/scripts/dynamix.vm.manager.js')?>"></script>
|
||||
<script src="<?autov('/plugins/dynamix.vm.manager/javascript/vmmanager.js')?>"></script>
|
||||
<script>
|
||||
function startAll() {
|
||||
for (var i=0,vm; vm=kvm[i]; i++) if (vm.state!='running') $('#vm-'+vm.id).addClass('fa-spin');
|
||||
$.post('/plugins/dynamix.vm.manager/classes/VMManager.php',{action:'start'}, function(){loadlist();});
|
||||
}
|
||||
function stopAll() {
|
||||
for (var i=0,vm; vm=kvm[i]; i++) if (vm.state=='running') $('#vm-'+vm.id).addClass('fa-spin');
|
||||
$.post('/plugins/dynamix.vm.manager/classes/VMManager.php',{action:'stop'}, function(){loadlist();});
|
||||
}
|
||||
function vncOpen() {
|
||||
$.post('/plugins/dynamix.vm.manager/classes/vnc.php',{cmd:'open',root:'<?=$docroot?>',file:'<?=$docroot?>/plugins/dynamix.vm.manager/vncconnect.vnc'},function(data) {
|
||||
window.location.href = data;
|
||||
|
||||
@@ -22,7 +22,9 @@ if (empty($vms)) {
|
||||
echo '<tr><td colspan="8" style="text-align:center;padding-top:12px">No Virtual Machines installed</td></tr>';
|
||||
return;
|
||||
}
|
||||
$menu = []; $i = 0;
|
||||
$i = 0;
|
||||
$menu = [];
|
||||
$kvm = ['var kvm=[];'];
|
||||
foreach ($vms as $vm) {
|
||||
$res = $lv->get_domain_by_name($vm);
|
||||
$desc = $lv->domain_get_description($res);
|
||||
@@ -69,7 +71,7 @@ foreach ($vms as $vm) {
|
||||
}
|
||||
unset($dom);
|
||||
$menu[] = sprintf("addVMContext('%s','%s','%s','%s','%s','%s');", addslashes($vm),addslashes($uuid),addslashes($template),$state,addslashes($vnc),addslashes($log));
|
||||
|
||||
$kvm[] = "kvm.push({id:'$uuid',state:'$state'});";
|
||||
/* VM information */
|
||||
echo "<tr style='background-color:".bcolor($i)."'>";
|
||||
echo "<td style='width:48px;padding:4px'>".renderVMContentIcon($uuid, $vm, $vmicon, $state)."</td>";
|
||||
@@ -131,5 +133,5 @@ foreach ($vms as $vm) {
|
||||
echo "</tbody></table>";
|
||||
echo "</td></tr>";
|
||||
}
|
||||
echo "\0".implode($menu);
|
||||
echo "\0".implode($menu).implode($kvm);
|
||||
?>
|
||||
39
plugins/dynamix.vm.manager/classes/VMManager.php
Normal file
39
plugins/dynamix.vm.manager/classes/VMManager.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2018, Lime Technology
|
||||
* Copyright 2015-2018, Derek Macias, Eric Schultz, Jon Panozzo.
|
||||
* Copyright 2012-2018, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* 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";
|
||||
|
||||
$vms = $lv->get_domains() ?: [];
|
||||
|
||||
foreach ($vms as $vm) {
|
||||
$res = $lv->get_domain_by_name($vm);
|
||||
$uuid = $lv->domain_get_uuid($res);
|
||||
$domName = $lv->domain_get_name_by_uuid($uuid);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$state = $lv->domain_state_translate($dom['state']);
|
||||
switch ($_POST['action']) {
|
||||
case 'stop':
|
||||
if ($state!='running') continue;
|
||||
$result = $lv->domain_shutdown($domName) ? ['success'=>true, 'state'=>$lv->domain_get_state($domName)] : ['error'=>$lv->get_last_error()];
|
||||
$n = 10; // wait for VM to die
|
||||
while ($result['success'] && $lv->domain_get_state($domName)=='running') {sleep(1); if(!--$n) break;}
|
||||
break;
|
||||
case 'start':
|
||||
if ($state=='running') continue;
|
||||
$result = $lv->domain_start($domName) ? ['success'=>true, 'state'=>$lv->domain_get_state($domName)] : ['error'=>$lv->get_last_error()];
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -12,7 +12,6 @@ function ajaxVMDispatch(params, reload){
|
||||
|
||||
function addVMContext(name, uuid, template, state, vncurl, log){
|
||||
var opts = [{header:name, image:"/plugins/dynamix.vm.manager/images/dynamix.vm.manager.png"}];
|
||||
|
||||
var path = location.pathname;
|
||||
var x = path.indexOf("?");
|
||||
if (x!=-1) path = path.substring(0,x);
|
||||
|
||||
Reference in New Issue
Block a user