From cfa1ec486075fedccdfdcf7c0b8f213aad1a371f Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:39:15 +0100 Subject: [PATCH] Add nogpu --- .../dynamix.vm.manager/include/VMMachines.php | 1 + .../plugins/dynamix.vm.manager/include/libvirt.php | 2 +- .../dynamix.vm.manager/include/libvirt_helpers.php | 5 +++++ .../dynamix.vm.manager/javascript/vmmanager.js | 10 ++++++++-- .../dynamix.vm.manager/templates/Custom.form.php | 14 +++++++------- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php b/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php index 5bcec8694..846cbe874 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php +++ b/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php @@ -94,6 +94,7 @@ foreach ($vms as $vm) { if (!empty($arrConfig['gpu'])) { $arrValidGPUDevices = getValidGPUDevices(); foreach ($arrConfig['gpu'] as $arrGPU) { + if ($arrGPU['id'] == "nogpu") {$graphics .= "No GPU"."\n";continue;} foreach ($arrValidGPUDevices as $arrDev) { if ($arrGPU['id'] == $arrDev['id']) { if (count(array_filter($arrValidGPUDevices, function($v) use ($arrDev) { return $v['name'] == $arrDev['name']; })) > 1) { diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php index 4d0660064..c7d28a9f9 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php @@ -799,7 +799,7 @@ if (empty($gpu['id']) || in_array($gpu['id'], $gpudevs_used)) { continue; } - + if ($gpu['id'] == 'nogpu') break; if ($gpu['id'] == 'virtual') { $strKeyMap = ''; if (!empty($gpu['keymap'])) { diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php index e8f31708e..64b57e7f7 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php @@ -1281,6 +1281,11 @@ private static $encoding = 'UTF-8'; continue; } } + if (empty($arrGPUDevices)) { + $arrGPUDevices[] = [ + 'id' => 'nogpu', + ]; + } // Add claimed USB devices by this VM to the available USB devices /* diff --git a/emhttp/plugins/dynamix.vm.manager/javascript/vmmanager.js b/emhttp/plugins/dynamix.vm.manager/javascript/vmmanager.js index 4c598a089..07dad2bf2 100644 --- a/emhttp/plugins/dynamix.vm.manager/javascript/vmmanager.js +++ b/emhttp/plugins/dynamix.vm.manager/javascript/vmmanager.js @@ -90,6 +90,7 @@ function addVMContext(name, uuid, template, state, vmrcurl, vmrcprotocol, log, f var consolesplit = consolein.split(";"); var console = consolesplit[0]; var rdpopt = consolesplit[1]; + var rundivider = false; if (x!=-1) path = path.substring(0,x); if (vmrcurl !== "" && state == "running") { if (console == "web" || console == "both") { @@ -104,21 +105,26 @@ function addVMContext(name, uuid, template, state, vmrcurl, vmrcprotocol, log, f e.preventDefault(); ajaxVMDispatchconsoleRV({action:"domain-consoleRV", uuid:uuid, vmrcurl:vmrcurl}, "loadlist") ; }}); - } + } + rundivider = true; + } + if (state == "running") { if (webui != "") { opts.push({text:_("Open WebUI") , icon:"fa-globe", action:function(e) { e.preventDefault(); ajaxVMDispatchWebUI({action:"domain-openWebUI", uuid:uuid, vmrcurl:webui}, "loadlist") ; }}); + rundivider = true; } if (rdpopt == "yes") { opts.push({text:_("VM Remote Desktop Protocol(RDP)"), icon:"fa-desktop", action:function(e) { e.preventDefault(); ajaxVMDispatchconsoleRV({action:"domain-consoleRDP", uuid:uuid, vmrcurl:vmrcurl}, "loadlist") ; }}); + rundivider = true; } - opts.push({divider:true}); } + if (rundivider) opts.push({divider:true}); context.settings({right:false,above:false}); if (state == "running") { opts.push({text:_("Stop"), icon:"fa-stop", action:function(e) { diff --git a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php index a60910877..d853d1269 100644 --- a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php +++ b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php @@ -1140,14 +1140,14 @@ } else { echo mk_option($arrGPU['id'], '', _('None')); } - + echo mk_option($arrGPU['id'], 'nogpu', _('No GPU')); foreach($arrValidGPUDevices as $arrDev) { echo mk_option($arrGPU['id'], $arrDev['id'], $arrDev['name'].' ('.$arrDev['id'].')'); } ?> _(Multifunction)_: @@ -1234,7 +1234,7 @@ - + _(Graphics ROM BIOS)_: @@ -2341,12 +2341,12 @@ $(function() { slideUpRows($vnc_sections); $vnc_sections.filter('.advanced').removeClass('advanced').addClass('wasadvanced'); var MultiSel = document.getElementById("GPUMultiSel0") ; - MultiSel.disabled = false ; + if (myvalue=="nogpu") MultiSel.disabled = true ; else MultiSel.disabled = false ; } } $romfile = $(this).closest('table').find('.romfile'); - if (myvalue == 'virtual' || myvalue == '') { + if (myvalue == 'virtual' || myvalue == '' || myvalue =="nogpu") { slideUpRows($romfile.not(isVMAdvancedMode() ? '.basic' : '.advanced')); $romfile.filter('.advanced').removeClass('advanced').addClass('wasadvanced'); } else { @@ -2396,7 +2396,7 @@ $(function() { } while (gpu); form.find('select[name="gpu[0][id]"] option').each(function(){ var gpu = $(this).val(); - if (gpu != 'virtual' && !gpus.includes(gpu)) form.append(''); + if ((gpu != 'virtual' && gpu != 'nogpu') && !gpus.includes(gpu)) form.append(''); }); // remove unused sound cards var sound = [], i = 0; @@ -2471,7 +2471,7 @@ $(function() { } while (gpu); form.find('select[name="gpu[0][id]"] option').each(function(){ var gpu = $(this).val(); - if (gpu != 'virtual' && !gpus.includes(gpu)) form.append(''); + if ((gpu != 'virtual' && gpu != 'nogpu') && !gpus.includes(gpu)) form.append(''); }); // remove unused sound cards var sound = [], i = 0;