Merge pull request #1562 from SimonFair/VM-Updates-and-Fixes

VM Manager updates and fixes
This commit is contained in:
tom mortensen
2023-12-29 11:16:07 -08:00
committed by GitHub
3 changed files with 30 additions and 4 deletions

View File

@@ -267,7 +267,7 @@ foreach ($vms as $vm) {
if ($snap['parent'] == "" || $snap['parent'] == "Base") $j++;
$steps[$j] .= $snap['name'].';';
}
echo "<thead class='child' child-id='$i'><tr><th><i class='fa fa-clone'></i> <b>",_('Snapshots'),"</b></th><th></th><th>",_('Date/Time'),"</th><th>",_('Type'),"</th><th>",_('Parent'),"</th><th>",_('Memory'),"</th></tr></thead>";
echo "<thead class='child' child-id='$i'><tr><th><i class='fa fa-clone'></i> <b>",_('Snapshots'),"</b></th><th></th><th>",_('Date/Time'),"</th><th>",_('Type (Method)'),"</th><th>",_('Parent'),"</th><th>",_('Memory'),"</th></tr></thead>";
echo "<tbody class='child'child-id='$i'>";
foreach ($steps as $stepsline) {
$snapshotlist = explode(";",$stepsline);
@@ -275,7 +275,7 @@ foreach ($vms as $vm) {
foreach ($snapshotlist as $snapshotitem) {
if ($snapshotitem == "") continue;
$snapshot = $snapshots[$snapshotitem] ;
$snapshotstate = _(ucfirst($snapshot["state"]));
$snapshotstate = _(ucfirst($snapshot["state"]))." ({$snapshot["method"]})";
$snapshotdesc = $snapshot["desc"];
$snapshotmemory = _(ucfirst($snapshot["memory"]["@attributes"]["snapshot"]));
$snapshotparent = $snapshot["parent"] ? $snapshot["parent"] : "None";

View File

@@ -1409,10 +1409,11 @@ private static $encoding = 'UTF-8';
if ($p2['bus'] && $p2['slot'] && $p2['function'] && $p2['bus']==$pci['bus'] && $p2['slot']==$pci['slot'] && $p2['function']==$function) unset($old['devices']['hostdev'][$k]);
}
}
// remove and rebuild usb controllers
// remove and rebuild usb + scsi controllers
$devices = $old['devices']['controller'];
foreach ($devices as $key => $controller) {
if ($controller['@attributes']['type']=='usb') unset($old['devices']['controller'][$key]);
if ($controller['@attributes']['type']=='scsi') unset($old['devices']['controller'][$key]);
}
// preserve existing disk driver settings
foreach ($new['devices']['disk'] as $key => $disk) {
@@ -1731,7 +1732,7 @@ private static $encoding = 'UTF-8';
return $snaps ;
}
function write_snapshots_database($vm,$name) {
function write_snapshots_database($vm,$name,$method="QEMU") {
global $lv ;
$dbpath = "/etc/libvirt/qemu/snapshot/$vm" ;
if (!is_dir($dbpath)) mkdir($dbpath) ;
@@ -1749,6 +1750,7 @@ private static $encoding = 'UTF-8';
$snaps[$vmsnap]["desc"]= $b["description"];
$snaps[$vmsnap]["memory"]= $b["memory"];
$snaps[$vmsnap]["creationtime"]= $b["creationTime"];
$snaps[$vmsnap]["method"]= $method;
$disks =$lv->get_disk_stats($vm) ;
foreach($disks as $disk) {

View File

@@ -270,4 +270,28 @@ function my_preg_split($split, $text, $count=2) {
function delete_file(...$file) {
array_map('unlink',array_filter($file,'file_exists'));
}
function my_mkdir($dirname) {
$pathinfo = pathinfo($dirname);
$parent = $pathinfo["dirname"];
$userPathFound = strpos($dirname,"/mnt/user");
$realdir = $dirname;
if ($userPathFound !== false) {
$realLocation = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg("$parent")));
$realdir = str_replace("/mnt/user","/mnt/$realLocation",$dirname);
$parent = dirname($realdir);
}
$fstype = trim(shell_exec(" stat -f -c '%T' $parent"));
switch ($fstype) {
case "zfs":
$zfsdataset = trim(shell_exec("zfs list -H -o name $parent")) ;
shell_exec("zfs create $zfsdataset/{$pathinfo['filename']}");
break;
case "btrfs":
shell_exec("btrfs subvolume create $realdir");
break;
default:
mkdir($realdir, 0777, true);
break;
}
}
?>