Merge pull request #1474 from SimonFair/VM-template-enhancements-for-Windows-VMs

VM  template enhancements for windows vms
This commit is contained in:
tom mortensen
2023-10-28 09:15:17 -07:00
committed by GitHub
3 changed files with 75 additions and 25 deletions

View File

@@ -369,6 +369,7 @@
$cpumode = '';
$cpucache = '';
$cpufeatures = '';
$cpumigrate = '';
if (!empty($domain['cpumode']) && $domain['cpumode'] == 'host-passthrough') {
$cpumode .= "mode='host-passthrough'";
$cpucache = "<cache mode='passthrough'/>";
@@ -389,9 +390,11 @@
$intCores = $vcpus / $intCPUThreadsPerCore;
$intThreads = $intCPUThreadsPerCore;
}
if (!empty($domain['cpumigrate'])) $cpumigrate = " migratable='".$domain['cpumigrate']."'" ;
}
$cpustr = "<cpu $cpumode>
$cpustr = "<cpu $cpumode $cpumigrate>
<topology sockets='1' cores='{$intCores}' threads='{$intThreads}'/>
$cpucache
$cpufeatures
@@ -439,10 +442,13 @@
break;
}
if ($os_type == "windows") $hypervclock = "<timer name='hypervclock' present='yes'/>" ; else $hypervclock = "" ;
$clock = "<clock offset='" . $domain['clock'] . "'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
$hypervclock
</clock>";
$hyperv = '';
@@ -1424,7 +1430,7 @@
}
//create a storage volume and add file extension
function volume_create($name, $capacity, $allocation, $format) {
/*function volume_create($name, $capacity, $allocation, $format) {
$capacity = $this->parse_size($capacity);
$allocation = $this->parse_size($allocation);
($format != 'raw' ) ? $ext = $format : $ext = 'img';
@@ -1441,7 +1447,7 @@
$tmp = libvirt_storagevolume_create_xml($pool, $xml);
return ($tmp) ? $tmp : $this->_set_last_error();
}
}*/
function get_hypervisor_name() {
$tmp = libvirt_connect_get_information($this->conn);
@@ -2096,6 +2102,17 @@
return $var;
}
function domain_get_cpu_migrate($domain) {
$tmp = $this->get_xpath($domain, '//domain/cpu/@migratable', false);
if (!$tmp)
return 'no';
$var = $tmp[0];
unset($tmp);
return $var;
}
function domain_get_vcpu($domain) {
$tmp = $this->get_xpath($domain, '//domain/vcpu', false);
$var = $tmp[0];
@@ -2245,20 +2262,20 @@
$objNodes = $xpath->query('//domain/devices/hostdev[@type="pci"]');
if ($objNodes->length > 0) {
foreach ($objNodes as $objNode) {
$dom = $xpath->query('source/address/@domain', $objNode)->Item(0)->value;
$bus = $xpath->query('source/address/@bus', $objNode)->Item(0)->value;
$slot = $xpath->query('source/address/@slot', $objNode)->Item(0)->value;
$func = $xpath->query('source/address/@function', $objNode)->Item(0)->value;
$dom = $xpath->query('source/address/@domain', $objNode)->Item(0)->nodeValue;
$bus = $xpath->query('source/address/@bus', $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);
$rom = ($rom->length > 0 ? $rom->Item(0)->value : '');
$boot =$xpath->query('boot/@order', $objNode)->Item(0)->value;
$rom = ($rom->length > 0 ? $rom->Item(0)->nodeValue : '');
$boot =$xpath->query('boot/@order', $objNode)->Item(0)->nodeValue;
$devid = str_replace('0x', '', 'pci_'.$dom.'_'.$bus.'_'.$slot.'_'.$func);
$tmp2 = $this->get_node_device_information($devid);
$guest["multi"] = $xpath->query('address/@multifunction', $objNode)->Item(0)->value ? "on" : "off" ;
$guest["dom"] = $xpath->query('address/@domain', $objNode)->Item(0)->value;
$guest["bus"] = $xpath->query('address/@bus', $objNode)->Item(0)->value;
$guest["slot"] = $xpath->query('address/@slot', $objNode)->Item(0)->value;
$guest["func"] = $xpath->query('address/@function', $objNode)->Item(0)->value;
$guest["multi"] = $xpath->query('address/@multifunction', $objNode)->Item(0)->nodeValue ? "on" : "off" ;
$guest["dom"] = $xpath->query('address/@domain', $objNode)->Item(0)->nodeValue;
$guest["bus"] = $xpath->query('address/@bus', $objNode)->Item(0)->nodeValue;
$guest["slot"] = $xpath->query('address/@slot', $objNode)->Item(0)->nodeValue;
$guest["func"] = $xpath->query('address/@function', $objNode)->Item(0)->nodeValue;
$devs[] = [
'domain' => $dom,
'bus' => $bus,
@@ -2626,7 +2643,7 @@
}
//change disk capacity
function disk_set_cap($disk, $cap) {
/*function disk_set_cap($disk, $cap) {
$xml = $this->domain_get_xml($domain);
$tmp = explode("\n", $xml);
for ($i = 0; $i < sizeof($tmp); $i++)
@@ -2636,7 +2653,7 @@
$xml = join("\n", $tmp);
return $this->domain_define($xml);
}
}*/
//change domain boot device
function domain_set_boot_device($domain, $bootdev) {

View File

@@ -1094,7 +1094,7 @@ private static $encoding = 'UTF-8';
$arrValidNetworks['bridges'] = array_values($arrBridges);
// This breaks VMSettings.page if libvirt is not running
if ($libvirt_running == "yes") {
/* if ($libvirt_running == "yes") {
$arrVirtual = $lv->libvirt_get_net_list($lv->get_connection());
if (($key = array_search('default', $arrVirtual)) !== false) {
@@ -1104,7 +1104,7 @@ private static $encoding = 'UTF-8';
array_unshift($arrVirtual, 'default');
$arrValidNetworks['libvirt'] = array_values($arrVirtual);
}
}*/
return $arrValidNetworks;
}
@@ -1276,6 +1276,7 @@ private static $encoding = 'UTF-8';
'maxmem' => $lv->domain_get_memory($res),
'password' => '', //TODO?
'cpumode' => $lv->domain_get_cpu_type($res),
'cpumigrate' => $lv->domain_get_cpu_migrate($res),
'vcpus' => $dom['nrVirtCpu'],
'vcpu' => $lv->domain_get_vcpu_pins($res),
'hyperv' => ($lv->domain_get_feature($res, 'hyperv') ? 1 : 0),

View File

@@ -54,6 +54,7 @@
'maxmem' => 1024 * 1024,
'password' => '',
'cpumode' => 'host-passthrough',
'cpumigrate' => 'on',
'vcpus' => 1,
'vcpu' => [0],
'hyperv' => 1,
@@ -313,13 +314,26 @@
</blockquote>
</div>
<?
$migratehidden = "disabled hidden" ;
if ($arrConfig['domain']['cpumode'] == 'host-passthrough') $migratehidden = "" ;
?>
<table>
<tr class="advanced">
<td>_(CPU Mode)_:</td>
<td><span class="advanced">_(CPU)_ </span>_(Mode)_:</td>
<td>
<select name="domain[cpumode]" title="_(define type of cpu presented to this vm)_">
<select id="cpu" name="domain[cpumode]" class="cpu" title="_(define type of cpu presented to this vm)_">
<?mk_dropdown_options(['host-passthrough' => _('Host Passthrough').' (' . $strCPUModel . ')', 'custom' => _('Emulated').' ('._('QEMU64').')'], $arrConfig['domain']['cpumode']);?>
</select>
<span class="advanced" id="domain_cpumigrate_text"<?=$migratehidden?>>_(Migratable)_:</span>
<select name="domain[cpumigrate]" id="domain_cpumigrate" <?=$migratehidden?> class="narrow" title="_(define if migratable)_">
<?
echo mk_option($arrConfig['domain']['cpumigrate'], 'on', 'On');
echo mk_option($arrConfig['domain']['cpumigrate'], 'off', 'Off') ;
?>
</select>
</td>
</tr>
</table>
@@ -334,6 +348,10 @@
<b>Emulated</b><br>
If you are having difficulties with Host Passthrough mode, you can try the emulated mode which doesn't expose the guest to host-based CPU features. This may impact the performance of your VM.
</p>
<p>
<b>Migratable</b><br>
Migratable attribute may be used to explicitly request such features to be removed from (on) or kept in (off) the virtual CPU. Off will not remove any host features when using Host Passthrough. Not support on emulated.
</p>
</blockquote>
</div>
@@ -381,10 +399,8 @@
}
?>
</select>
</td>
<td class="advanced">_(Max)_ _(Memory)_:</td>
<td class="advanced">
<span class="advanced">_(Max)_ _(Memory)_:</span>
<select name="domain[maxmem]" id="domain_maxmem" class="narrow" title="_(define the maximum amount of memory)_">
<?
echo mk_option($arrConfig['domain']['maxmem'], 128 * 1024, '128 MB');
@@ -397,7 +413,6 @@
?>
</select>
</td>
<td></td>
</tr>
</table>
<div class="basic">
@@ -1834,6 +1849,23 @@ $(function() {
}
});
$("#vmform").on("change", ".cpu", function changeCPUEvent() {
var myvalue = $(this).val();
var mylabel = $(this).children('option:selected').text();
var cpumigrate = document.getElementById("domain_cpumigrate_text") ;
var cpumigrate_text = document.getElementById("domain_cpumigrate") ;
if (myvalue == "custom") {
document.getElementById("domain_cpumigrate_text").style.visibility="hidden";
document.getElementById("domain_cpumigrate").style.visibility="hidden";
} else {
document.getElementById("domain_cpumigrate_text").style.display="inline";
document.getElementById("domain_cpumigrate_text").style.visibility="visible";
document.getElementById("domain_cpumigrate").style.display="inline";
document.getElementById("domain_cpumigrate").style.visibility="visible";
}
}) ;
$("#vmform").on("change", ".gpu", function changeGPUEvent() {
var myvalue = $(this).val();
var mylabel = $(this).children('option:selected').text();