From 19361f0b4da12745c317da9fe4be66ba47fd7de6 Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Sat, 14 Dec 2024 10:29:43 +0000 Subject: [PATCH 01/13] Initial Commit Templates Export/Import Changes for virgl(Virtio3d) Bios flag. --- .../dynamix.vm.manager/VMMachines.page | 2 +- .../dynamix.vm.manager/VMTemplates.page | 201 +++++++++++++++++- .../dynamix.vm.manager/include/VMajax.php | 44 ++++ .../dynamix.vm.manager/include/libvirt.php | 39 +++- .../include/libvirt_helpers.php | 14 +- .../sheets/VMTemplates-azure.css | 1 + .../sheets/VMTemplates-black.css | 2 + .../sheets/VMTemplates-gray.css | 2 + .../sheets/VMTemplates-white.css | 2 + .../dynamix.vm.manager/sheets/VMTemplates.css | 4 + .../templates/Custom.form.php | 50 ++++- 11 files changed, 350 insertions(+), 11 deletions(-) create mode 100644 emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-azure.css create mode 100644 emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-black.css create mode 100644 emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-gray.css create mode 100644 emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-white.css diff --git a/emhttp/plugins/dynamix.vm.manager/VMMachines.page b/emhttp/plugins/dynamix.vm.manager/VMMachines.page index 1fbdbf65e..92addef7c 100644 --- a/emhttp/plugins/dynamix.vm.manager/VMMachines.page +++ b/emhttp/plugins/dynamix.vm.manager/VMMachines.page @@ -486,7 +486,7 @@ $(function() { - + diff --git a/emhttp/plugins/dynamix.vm.manager/VMTemplates.page b/emhttp/plugins/dynamix.vm.manager/VMTemplates.page index 3ef5bf021..aa9987861 100644 --- a/emhttp/plugins/dynamix.vm.manager/VMTemplates.page +++ b/emhttp/plugins/dynamix.vm.manager/VMTemplates.page @@ -38,6 +38,16 @@ Markdown="false" if (strpos($strName,"User-") === false) $user = ""; else $user = ' class="user"'; ?> + +"> +"> +"> + + + + + +
> @@ -46,7 +56,9 @@ Markdown="false"

-
+
+ +

\ No newline at end of file +i.export{display:none;font-size:1.8rem;position:left;margin-left:1px} + + +
+
+ +
+
+
_(Save File Name)_:
+
+
_(Save Path)_:
+
+
+
+ +
+
+
_(File for import)_:
+
+
+
+ + + true]; break; +case 'vm-template-save': + $template = $_REQUEST['template']; + $name = $_REQUEST['name']; + $replace = $_REQUEST['replace']; + + if (is_file($name) && $replace == "no"){ + $arrResponse = ['success' => false, 'error' => _("File exists.")]; + } else { + $error = file_put_contents($name,json_encode($template)); + if ($error !== false) $arrResponse = ['success' => true]; + else { + $arrResponse = ['success' => false, 'error' => _("File write failed.")]; + } + } + break; + +case 'vm-template-import': + $template = $_REQUEST['template']; + $name = $_REQUEST['name']; + $replace = $_REQUEST['replace']; + $templateslocation = "/boot/config/plugins/dynamix.vm.manager/savedtemplates.json"; + + if ($template="*file") { + $template=json_decode(file_get_contents($name)); + } + + $namepathinfo = pathinfo($name); + $template_name = $namepathinfo['filename']; + + if (is_file($templateslocation)){ + $ut = json_decode(file_get_contents($templateslocation),true) ; + if (isset($ut[$template_name]) && $replace == "no"){ + $arrResponse = ['success' => false, 'error' => _("Template exists.")]; + } else { + $ut[$template_name] = $template; + $error = file_put_contents($templateslocation,json_encode($ut,JSON_PRETTY_PRINT));; + if ($error !== false) $arrResponse = ['success' => true]; + else { + $arrResponse = ['success' => false, 'error' => _("Tempalte file write failed.")]; + } + } + } + break; + default: $arrResponse = ['error' => _('Unknown action')." '$action'"]; break; diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php index 042a17ae0..5a0a1784c 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php @@ -847,6 +847,19 @@ if (($gpu['copypaste'] == "yes") && ($strProtocol == "spice")) $vmrcmousemode = "" ; else $vmrcmousemode = "" ; if ($strProtocol == "spice") $virtualaudio = "spice" ; else $virtualaudio = "none" ; + $strEGLHeadless = ""; + $strAccel3d =""; + if ($strModelType == "virtio3d") { + $strModelType = "virtio"; + if (!isset($gpu['render'])) $gpu['render'] = "auto"; + if ($gpu['render'] == "auto") { + $strEGLHeadless = ''; + $strAccel3d = ""; + } else { + $strEGLHeadless = ''; + $strAccel3d =""; + }} + $vmrc = " @@ -854,8 +867,11 @@ $vmrcmousemode + $strEGLHeadless
@@ -1350,6 +1365,7 @@ + _(Graphics ROM Needed?)_: _(GPU is primary adapater, vbios may be required.)_ @@ -2084,6 +2100,19 @@ function AutoportChange(autoport) { } } +function VMConsoleDriverChange(driver) { + if (driver.value != "virtio3d") { + document.getElementById("vncrender").style.visibility="hidden"; + document.getElementById("vncrendertext").style.visibility="hidden"; + + } else { + document.getElementById("vncrender").style.display="inline"; + document.getElementById("vncrender").style.visibility="visible"; + document.getElementById("vncrendertext").style.display="inline"; + document.getElementById("vncrendertext").style.visibility="visible"; + } +} + function ProtocolChange(protocol) { var autoport = document.getElementById("autoport").value ; if (autoport == "yes") { @@ -2391,6 +2420,7 @@ $(function() { }) ; $("#vmform").on("change", ".gpu", function changeGPUEvent() { + const ValidGPUs = ; var myvalue = $(this).val(); var mylabel = $(this).children('option:selected').text(); var myindex = $(this).closest('table').data('index'); @@ -2402,6 +2432,13 @@ $(function() { slideDownRows($vnc_sections.not(isVMAdvancedMode() ? '.basic' : '.advanced')); var MultiSel = document.getElementById("GPUMultiSel0") ; MultiSel.disabled = true ; + if (document.getElementById("vncmodel").value == "virtio3d") { + $("#vncrender").show(); + $("#vncrendertext").show(); + } else { + $("#vncrender").hide(); + $("#vncrendertext").hide(); + } } else { slideUpRows($vnc_sections); $vnc_sections.filter('.advanced').removeClass('advanced').addClass('wasadvanced'); @@ -2410,6 +2447,11 @@ $(function() { } } + if (mylabel == "None") $("#gpubootvga"+myindex).hide(); + if (myvalue != 'virtual' && myvalue != '' && myvalue !="nogpu") { + if (ValidGPUs[myvalue].bootvga == "1") $("#gpubootvga"+myindex).show(); else $("#gpubootvga"+myindex).hide(); + } + $romfile = $(this).closest('table').find('.romfile'); if (myvalue == 'virtual' || myvalue == '' || myvalue =="nogpu") { slideUpRows($romfile.not(isVMAdvancedMode() ? '.basic' : '.advanced')); From 08987bc2f1c6e6a2202405aa5852a260935282c0 Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Sat, 14 Dec 2024 11:12:49 +0000 Subject: [PATCH 02/13] Add driver and rendernode to VMMachines view --- emhttp/plugins/dynamix.vm.manager/include/VMMachines.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php b/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php index 820a53f79..48c8b7290 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php +++ b/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php @@ -78,18 +78,22 @@ foreach ($vms as $vm) { $vmrcurl = ''; $graphics = ''; $virtual = false ; + if (isset($arrConfig['gpu'][0]['model'])) {$vrtdriver=" "._("Driver").strtoupper(":{$arrConfig['gpu'][0]['model']} "); $vrtmodel =$arrConfig['gpu'][0]['model'];} else $vrtdriver = ""; + if (isset($arrConfig['gpu'][0]['render']) && $vrtmodel == "virtio3d") { + if (isset($arrConfig['gpu'][0]['render']) && $arrConfig['gpu'][0]['render'] == "auto") $vrtdriver .= "
"._("RenderGPU").":"._("Auto"); else $vrtdriver .= "
"._("RenderGPU").":{$arrValidGPUDevices[$arrConfig['gpu'][0]['render']]['name']}"; + } if ($vmrcport > 0) { $wsport = $lv->domain_get_ws_port($res); $vmrcprotocol = $lv->domain_get_vmrc_protocol($res); if ($vmrcprotocol == "vnc") $vmrcscale = "&resize=scale"; else $vmrcscale = ""; $vmrcurl = autov('/plugins/dynamix.vm.manager/'.$vmrcprotocol.'.html',true).$vmrcscale.'&autoconnect=true&host='._var($_SERVER,'HTTP_HOST'); if ($vmrcprotocol == "spice") $vmrcurl .= '&vmname='. urlencode($vm) .'&port=/wsproxy/'.$vmrcport.'/'; else $vmrcurl .= '&port=&path=/wsproxy/'.$wsport.'/'; - $graphics = strtoupper($vmrcprotocol).":".$vmrcport."\n"; + $graphics = strtoupper($vmrcprotocol).':'._($auto)."$vrtdriver\n"; $virtual = true ; } elseif ($vmrcport == -1 || $autoport) { $vmrcprotocol = $lv->domain_get_vmrc_protocol($res); if ($autoport == "yes") $auto = "auto"; else $auto="manual"; - $graphics = strtoupper($vmrcprotocol).':'._($auto)."\n"; + $graphics = strtoupper($vmrcprotocol).':'._($auto)."$vrtdriver\n"; $virtual = true ; } if (!empty($arrConfig['gpu'])) { From 8616faad598a363be56d0f21586de33408c0a7a8 Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Sun, 15 Dec 2024 09:14:11 +0000 Subject: [PATCH 03/13] Add support to detect auto gpu in use. --- emhttp/plugins/dynamix.vm.manager/include/libvirt.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php index 5a0a1784c..0c5f3a083 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php @@ -2221,6 +2221,8 @@ $var = $tmp[0]; unset($tmp); + + if (!str_contains($var,"pci")) $var = trim(shell_exec("udevadm info -q symlink -r $var")); $var = str_replace(['/dev/dri/by-path/pci-0000:','-render'],['',''],$var); return $var; } From 8591914a185bb476e931ddcd665014903b66744e Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Thu, 19 Dec 2024 08:03:39 +0000 Subject: [PATCH 04/13] Fix Templates CSS --- emhttp/plugins/dynamix.vm.manager/VMTemplates.page | 2 +- emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-azure.css | 2 +- emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-black.css | 2 +- emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-gray.css | 2 +- emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-white.css | 2 +- emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates.css | 3 --- 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/emhttp/plugins/dynamix.vm.manager/VMTemplates.page b/emhttp/plugins/dynamix.vm.manager/VMTemplates.page index aa9987861..ce12319e6 100644 --- a/emhttp/plugins/dynamix.vm.manager/VMTemplates.page +++ b/emhttp/plugins/dynamix.vm.manager/VMTemplates.page @@ -46,7 +46,7 @@ Markdown="false" - +
diff --git a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-azure.css b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-azure.css index 795f64a94..f5548270d 100644 --- a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-azure.css +++ b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-azure.css @@ -1 +1 @@ -.fileTree{background:#f2f2f2;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:relative;z-index:100;display:none} \ No newline at end of file +.fileTree{background:#f2f2f2;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:absolute;z-index:100;display:none} \ No newline at end of file diff --git a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-black.css b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-black.css index e708a6b28..bc79e2b47 100644 --- a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-black.css +++ b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-black.css @@ -1,2 +1,2 @@ -.fileTree{background:#1c1c1c;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:relative;z-index:100;display:none} +.fileTree{background:#1c1c1c;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:absolute;z-index:100;display:none} diff --git a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-gray.css b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-gray.css index e708a6b28..bc79e2b47 100644 --- a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-gray.css +++ b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-gray.css @@ -1,2 +1,2 @@ -.fileTree{background:#1c1c1c;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:relative;z-index:100;display:none} +.fileTree{background:#1c1c1c;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:absolute;z-index:100;display:none} diff --git a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-white.css b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-white.css index bb0fe6cd1..e93340e20 100644 --- a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-white.css +++ b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates-white.css @@ -1,2 +1,2 @@ -.fileTree{background:#f2f2f2;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:relative;z-index:100;display:none} +.fileTree{background:#f2f2f2;width:300px;max-height:150px;overflow-y:scroll;overflow-x:hidden;position:absolute;z-index:100;display:none} diff --git a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates.css b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates.css index d3b144267..90565f4fd 100644 --- a/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates.css +++ b/emhttp/plugins/dynamix.vm.manager/sheets/VMTemplates.css @@ -3,6 +3,3 @@ .vmtemplate img{width:48px;height:48px} .vmtemplate p{text-align:center;margin-top:8px;line-height:12px} div.template,div#dialogWindow,input#upload{display:none} -#resetsort{margin-left:12px;display:inline-block;width:32px} -.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset button[disabled]{cursor:default;color:#808080;background:-webkit-gradient(linear,left top,right top,from(#404040),to(#808080)) 0 0 no-repeat,-webkit-gradient(linear,left top,right top,from(#404040),to(#808080)) 0 100% no-repeat,-webkit-gradient(linear,left bottom,left top,from(#404040),to(#404040)) 0 100% no-repeat,-webkit-gradient(linear,left bottom,left top,from(#808080),to(#808080)) 100% 100% no-repeat;background:linear-gradient(90deg,#404040 0,#808080) 0 0 no-repeat,linear-gradient(90deg,#404040 0,#808080) 0 100% no-repeat,linear-gradient(0deg,#404040 0,#404040) 0 100% no-repeat,linear-gradient(0deg,#808080 0,#808080) 100% 100% no-repeat;background-size:100% 2px,100% 2px,2px 100%,2px 100%} -.dropdown-menu{z-index:10001} From f4bda545c912e6fcdf5ff4debd2eb2793beb6723 Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Fri, 20 Dec 2024 19:59:59 +0000 Subject: [PATCH 05/13] Add Display Options --- .../dynamix.vm.manager/include/libvirt.php | 27 +++++++++- .../include/libvirt_helpers.php | 50 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php index 0c5f3a083..25e63c2fd 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php @@ -860,6 +860,12 @@ $strAccel3d =""; }} + $strDisplayOptions = ""; + if ($strModelType == "qxl") { + if (empty($gpu['DisplayOptions'])) $gpu['DisplayOptions'] ="ram='65536' vram='16384' vgamem='16384' heads='1' primary='yes'"; + $strDisplayOptions = $gpu['DisplayOptions']; + } + $vmrc = " @@ -869,7 +875,7 @@ $strEGLHeadless