VMs: corrected USB/PCI host devices recreation

This commit is contained in:
bergware
2018-08-15 09:52:09 +02:00
parent b0b3b98a57
commit 345a640ab8
4 changed files with 27 additions and 39 deletions
@@ -1,6 +1,7 @@
<?PHP
/* Copyright 2005-2017, Lime Technology
* Copyright 2015-2017, Derek Macias, Eric Schultz, Jon Panozzo.
/* Copyright 2005-2018, Lime Technology
* Copyright 2015-2018, Derek Macias, Eric Schultz, Jon Panozzo.
* Copyright 2012-2018, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -27,7 +28,6 @@
// Check if program is running and
$libvirt_running = trim(shell_exec( "[ -f /proc/`cat /var/run/libvirt/libvirtd.pid 2> /dev/null`/exe ] && echo 'yes' || echo 'no' 2> /dev/null" ));
$arrAllTemplates = [
' Windows ' => '', /* Windows Header */
@@ -168,7 +168,6 @@
]
],
' Pre-packaged ' => '', /* Pre-built Header */
'LibreELEC' => [
@@ -181,7 +180,6 @@
'icon' => 'openelec.png'
],
' Linux ' => '', /* Linux Header */
'Linux' => [
@@ -260,7 +258,6 @@
'os' => 'vyos'
],
' ' => '', /* Custom / XML Expert Header */
'Custom' => [
@@ -269,7 +266,6 @@
]
];
$arrOpenELECVersions = [
'6.0.3_1' => [
'name' => '6.0.3',
@@ -305,7 +301,6 @@
]
];
$arrLibreELECVersions = [
'7.0.1_1' => [
'name' => '7.0.1',
@@ -317,7 +312,6 @@
]
];
$virtio_isos = [
'virtio-win-0.1.141-1' => [
'name' => 'virtio-win-0.1.141-1.iso',
@@ -571,7 +565,6 @@
return $arrJSON;
}
$cacheValidPCIDevices = null;
function getValidPCIDevices() {
global $cacheValidPCIDevices;
@@ -668,7 +661,6 @@
return $arrValidPCIDevices;
}
function getValidGPUDevices() {
$arrValidPCIDevices = getValidPCIDevices();
@@ -679,7 +671,6 @@
return $arrValidGPUDevices;
}
function getValidAudioDevices() {
$arrValidPCIDevices = getValidPCIDevices();
@@ -690,7 +681,6 @@
return $arrValidAudioDevices;
}
function getValidOtherDevices() {
$arrValidPCIDevices = getValidPCIDevices();
@@ -701,7 +691,6 @@
return $arrValidOtherDevices;
}
function getValidOtherStubbedDevices() {
$arrValidPCIDevices = getValidPCIDevices();
@@ -712,7 +701,6 @@
return $arrValidOtherStubbedDevices;
}
$cacheValidUSBDevices = null;
function getValidUSBDevices() {
global $cacheValidUSBDevices;
@@ -772,7 +760,6 @@
return $arrValidUSBDevices;
}
function getValidMachineTypes() {
global $lv;
@@ -808,7 +795,6 @@
return $arrValidMachineTypes;
}
function getLatestMachineType($strType = 'i440fx') {
$arrMachineTypes = getValidMachineTypes();
@@ -821,7 +807,6 @@
return array_shift(array_keys($arrMachineTypes));
}
function getValidDiskDrivers() {
$arrValidDiskDrivers = [
'raw' => 'raw',
@@ -831,7 +816,6 @@
return $arrValidDiskDrivers;
}
function getValidDiskBuses() {
$arrValidDiskBuses = [
'virtio' => 'VirtIO',
@@ -844,7 +828,6 @@
return $arrValidDiskBuses;
}
function getValidCdromBuses() {
$arrValidCdromBuses = [
'scsi' => 'SCSI',
@@ -856,7 +839,6 @@
return $arrValidCdromBuses;
}
function getValidVNCModels() {
$arrValidVNCModels = [
'cirrus' => 'Cirrus',
@@ -867,7 +849,6 @@
return $arrValidVNCModels;
}
function getValidKeyMaps() {
$arrValidKeyMaps = [
'ar' => 'Arabic (ar)',
@@ -909,14 +890,12 @@
return $arrValidKeyMaps;
}
function getHostCPUModel() {
$cpu = explode('#', exec("dmidecode -q -t 4|awk -F: '{if(/Version:/) v=$2; else if(/Current Speed:/) s=$2} END{print v\"#\"s}'"));
list($strCPUModel) = explode('@', str_replace(["Processor","CPU","(C)","(R)","(TM)"], ["","","&#169;","&#174;","&#8482;"], $cpu[0]) . '@');
return trim($strCPUModel);
}
function getNetworkBridges() {
exec("brctl show|grep -Po '^(vir)?br\d\S*'", $arrValidBridges);
@@ -934,7 +913,6 @@
return array_values($arrValidBridges);
}
function domain_to_config($uuid) {
global $lv;
global $domain_cfg;
@@ -953,7 +931,6 @@
$arrHostDevs = $lv->domain_get_host_devices_pci($res);
$arrUSBDevs = $lv->domain_get_host_devices_usb($res);
// Metadata Parsing
// libvirt xpath parser sucks, use php's xpath parser instead
$strDOMXML = $lv->domain_get_xml($res);
@@ -973,7 +950,6 @@
$arrTemplateValues['name'] = 'Custom';
}
$arrGPUDevices = [];
$arrAudioDevices = [];
$arrOtherDevices = [];
@@ -1103,4 +1079,25 @@
];
}
function array_update_recursive(&$old, &$new) {
$hostdev = [];
// update USB & PCI host devices
foreach ($new['devices']['hostdev'] as $key => $device) {
$vendor = $device['source']['vendor']['@attributes']['id'];
$product = $device['source']['product']['@attributes']['id'];
$pci = $device['source']['address']['@attributes'];
foreach ($old['devices']['hostdev'] as $k => $d) {
$v = $d['source']['vendor']['@attributes']['id'];
$p = $d['source']['product']['@attributes']['id'];
$p2 = $d['source']['address']['@attributes'];
if ($vendor && $product && $vendor==$v && $product==$p) $hostdev[] = $d;
if ($pci['bus'] && $pci['slot'] && $pci['bus']==$p2['bus'] && $pci['slot']==$p2['slot']) $hostdev[] = $d;
}
}
// update parent arrays
if ($hostdev) $new['devices']['hostdev'] = $hostdev;
unset($old['cputune']['vcpupin'], $old['devices']['hostdev']);
// set namespace
$new['metadata']['vmtemplate']['@attributes']['xmlns'] = 'unraid';
}
?>