From 5842b5acf9667a6df749ace41225ee7f00b0bc99 Mon Sep 17 00:00:00 2001 From: SimonFair <39065407+SimonFair@users.noreply.github.com> Date: Sat, 27 Jan 2024 23:48:15 +0000 Subject: [PATCH] Add SSD flag for vdisks. --- .../dynamix.vm.manager/include/libvirt.php | 14 ++++++- .../include/libvirt_helpers.php | 10 ++--- .../templates/Custom.form.php | 37 +++++++++++++++++-- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php index 234eee8ca..3436482b9 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php @@ -261,6 +261,9 @@ if (!empty($disk['boot'])) { $arrReturn['boot'] = $disk['boot']; } + if (!empty($disk['rotation'])) { + $arrReturn['rotation'] = $disk['rotation']; + } if (!empty($disk['serial'])) { $arrReturn['serial'] = $disk['serial']; } @@ -687,13 +690,18 @@ if ($disk["serial"] != "") $serial = "".$disk["serial"]."" ; else $serial = "" ; + $rotation_rate = ""; + if ($disk['bus'] == "scsi" || $disk['bus'] == "sata" || $disk['bus'] == "ide" ) { + if ($disk['rotation']) $rotation_rate = " rotation_rate='1' "; + } + if ($strDevType == 'file' || $strDevType == 'block') { $strSourceType = ($strDevType == 'file' ? 'file' : 'dev'); $diskstr .= " - + $bootorder $readonly $serial @@ -1307,6 +1315,7 @@ if ($tmp) { $tmp['bus'] = $disk->target->attributes()->bus->__toString(); $tmp["boot order"] = $disk->boot->attributes()->order ?? ""; + $tmp["rotation"] = $disk->target->attributes()->rotation_rate ?? "0"; $tmp['serial'] = $disk->serial ; // Libvirt reports 0 bytes for raw disk images that haven't been @@ -1335,6 +1344,7 @@ 'physical' => '-', 'bus' => $disk->target->attributes()->bus->__toString(), 'boot order' => $disk->boot->attributes()->order , + 'rotation' => $disk->target->attributes()->rotation_rate ?? "0", 'serial' => $disk->serial ]; } @@ -2365,6 +2375,7 @@ foreach ($objNodes as $objNode) { $dom = $xpath->query('source/address/@domain', $objNode)->Item(0)->nodeValue; $bus = $xpath->query('source/address/@bus', $objNode)->Item(0)->nodeValue; + $rotation = $xpath->query('target/address/@rotation_rate', $objNode)->Item(0)->nodeValue; $slot = $xpath->query('source/address/@slot', $objNode)->Item(0)->nodeValue; $func = $xpath->query('source/address/@function', $objNode)->Item(0)->nodeValue; $rom = $xpath->query('rom/@file', $objNode); @@ -2388,6 +2399,7 @@ 'product' => $tmp2['product_name'], 'product_id' => $tmp2['product_id'], 'boot' => $boot, + 'rotation' => $rotation, 'rom' => $rom, 'guest' => $guest ]; diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php index 515d1b92e..b8b66d638 100644 --- a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php +++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php @@ -1289,6 +1289,7 @@ private static $encoding = 'UTF-8'; 'dev' => $disk['device'], 'bus' => $disk['bus'], 'boot' => $disk['boot order'], + 'rotation' => $disk['rotation'], 'serial' => $disk['serial'], 'select' => $default_option ]; @@ -1300,7 +1301,8 @@ private static $encoding = 'UTF-8'; 'driver' => 'raw', 'dev' => 'hda', 'select' => '', - 'bus' => 'virtio' + 'bus' => 'virtio', + 'rotation' => "0" ]; } @@ -2521,11 +2523,7 @@ function addtemplatexml($post) { 'overrides' => $usertemplate ]; file_put_contents($templateslocation,json_encode($savedtemplates,JSON_PRETTY_PRINT)); - // Fire off the vnc/spice popup if available - $reply = ['success' => true]; - - #} else { - # $reply = ['error' => $lv->get_last_error()]; + $reply = ['success' => true]; return $reply; } diff --git a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php index 8804b0d2f..9e04f95d8 100644 --- a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php +++ b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php @@ -303,7 +303,6 @@ } if (strpos($arrConfig['template']['name'],"User-") !== false) $arrConfig['template']['name'] = str_replace("User-","",$arrConfig['template']['name']); - #var_dump($arrConfig); ?> @@ -805,11 +804,14 @@ _(vDisk Bus)_: - + _(Boot Order)_: + if ($arrDisk['bus'] == "virtio" || $arrDisk['bus'] == "usb") $ssddisabled = "hidden "; else $ssddisabled = " ";?> + >_(SSD)_: + =$arrDisk['rotation'] ? "checked ":"";?> title="_(Set SDD flag)_" value="=$arrDisk['rotation']?>" > @@ -857,6 +859,11 @@ Specify the order the devices are used for booting. + + vDisk SSD Flag + Specify the vdisk shows as SSD within the guest, only supported on SCSI, SATA and IDE bus types. + + vDisk Serial Set the device serial number presented to the VM. @@ -949,12 +956,14 @@ _(vDisk Bus)_: - + _(Boot Order)_: + _(SSD)_: + _(Serial)_: @@ -1700,6 +1709,28 @@ function ShareChange(share) { } } +function BusChange(bus) { + var value = bus.value; + var index = bus.name.indexOf("]") + 1; + var name = bus.name.substr(0,index) ; + if (value == "virtio" || value == "usb" ) { + document.getElementById(name+"[rotatetext]").style.visibility="hidden"; + document.getElementById(name+"[rotation]").style.visibility="hidden"; + } else { + document.getElementById(name+"[rotation]").style.display="inline"; + document.getElementById(name+"[rotation]").style.visibility="visible"; + document.getElementById(name+"[rotatetext]").style.display="inline"; + document.getElementById(name+"[rotatetext]").style.visibility="visible"; + } +} + +function updateSSDCheck(ssd) { + var value = ssd.value; + var index = ssd.name.indexOf("]") + 1; + var name = ssd.name.substr(0,index) ; + if (document.getElementById(name+"[rotation]").checked) ssd.value = "1"; else ssd.value = "0"; +} + function BIOSChange(bios) { var value = bios.value; if (value == "0") {
+ vDisk SSD Flag + Specify the vdisk shows as SSD within the guest, only supported on SCSI, SATA and IDE bus types. +
vDisk Serial Set the device serial number presented to the VM. @@ -949,12 +956,14 @@