From 505205089d144100e03734a3d85a8886f0cb52b0 Mon Sep 17 00:00:00 2001
From: SimonFair <39065407+SimonFair@users.noreply.github.com>
Date: Thu, 7 Dec 2023 14:37:00 +0000
Subject: [PATCH 1/2] Add spin up check to CD info function.
---
.../dynamix.vm.manager/include/libvirt.php | 27 +++++++++++++------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
index 847077d9b..e90b13bee 100644
--- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
+++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
@@ -1238,33 +1238,44 @@
return $tmp;
}
- function get_cdrom_stats($domain, $sort=true) {
+ function get_cdrom_stats($domain, $sort=true,$spincheck = false) {
+ $unraiddisks = array_merge_recursive(@parse_ini_file('state/disks.ini',true)?:[], @parse_ini_file('state/devs.ini',true)?:[]);
$dom = $this->get_domain_object($domain);
-
+ $tmp = false;
$buses = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@bus', false);
- $disks = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@dev', false);
+ $cds = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@dev', false);
$files = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/source/@file', false);
$boot = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/boot/@*', false);
$ret = [];
- for ($i = 0; $i < $disks['num']; $i++) {
- $tmp = libvirt_domain_get_block_info($dom, $disks[$i]);
+ for ($i = 0; $i < $cds['num']; $i++) {
+ $spundown = 0;
+ $reallocation = null;
+ if (isset($files[$i])) $reallocation = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($files[$i])." 2>/dev/null"));
+ if ($spincheck) {
+ if (isset($unraiddisks[$reallocation]['spundown']) && $unraiddisks[$reallocation]['spundown'] == 1) $spundown = 1; else $tmp = libvirt_domain_get_block_info($dom, $cds[$i]);
+ } else $tmp = libvirt_domain_get_block_info($dom, $cds[$i]);
+
if ($tmp) {
$tmp['bus'] = $buses[$i];
$tmp["boot order"] = $boot[$i] ?? "";
+ $tmp['reallocation'] = $reallocation;
+ $tmp['spundown'] = $spundown;
$ret[] = $tmp;
}
else {
$this->_set_last_error();
$ret[] = [
- 'device' => $disks[$i],
+ 'device' => $cds[$i],
'file' => $files[$i],
'type' => '-',
'capacity' => '-',
'allocation' => '-',
'physical' => '-',
- 'bus' => $buses[$i]
+ 'bus' => $buses[$i],
+ 'reallocation' => $reallocation,
+ 'spundown' => $spundown
];
}
}
@@ -1282,7 +1293,7 @@
}
unset($buses);
- unset($disks);
+ unset($cds);
unset($files);
return $ret;
From c0f79e89298b7e92388d1b35b78675f5918c56f5 Mon Sep 17 00:00:00 2001
From: SimonFair <39065407+SimonFair@users.noreply.github.com>
Date: Fri, 29 Mar 2024 07:48:33 +0000
Subject: [PATCH 2/2] Add tooltip and * if spundown.
---
emhttp/plugins/dynamix.vm.manager/include/VMMachines.php | 8 +++++---
emhttp/plugins/dynamix.vm.manager/include/libvirt.php | 2 +-
emhttp/plugins/dynamix/include/Helpers.php | 9 +++++++++
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php b/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php
index 7c7ed0a4c..e585677d0 100644
--- a/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php
+++ b/emhttp/plugins/dynamix.vm.manager/include/VMMachines.php
@@ -53,7 +53,7 @@ foreach ($vms as $vm) {
$image = substr($icon,-4)=='.png' ? "" : (substr($icon,0,5)=='icon-' ? "" : "");
$arrConfig = domain_to_config($uuid);
$snapshots = getvmsnapshots($vm) ;
- $cdroms = $lv->get_cdrom_stats($res) ;
+ $cdroms = $lv->get_cdrom_stats($res,true,true) ;
if ($state == 'running') {
$mem = $dom['memory']/1024;
} else {
@@ -215,7 +215,7 @@ foreach ($vms as $vm) {
$boot= $arrDisk["boot order"];
$serial = $arrDisk["serial"];
if ($boot < 1) $boot = _('Not set');
- $reallocation = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($disk)." 2>/dev/null"));
+ $reallocation = trim(get_realvolume($disk));
if (!empty($reallocation)) $reallocationstr = "($reallocation)"; else $reallocationstr = "";
echo "