0.11.0: VM configuration editor (cpu, memory, loader, graphics, switch, autostart)
This commit is contained in:
1 parent
f4160054ab
commit
02cb6b1079
7 files changed
+201
-2
No files matched your search
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
require_once 'vmmngr-boot.inc';
|
||||
require_once 'vmmngr-config-lib.inc';
|
||||
|
||||
$name = (string)($_GET['name'] ?? '');
|
||||
// POSTs from this page carry the VM name in the act field; accept that too so
|
||||
@@ -24,6 +25,48 @@ if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && isset($
|
||||
$vmName = $name;
|
||||
}
|
||||
|
||||
if ($verb === 'save_config') {
|
||||
if (vmm_vm_state($name) === 'running') {
|
||||
$_SESSION['vmmngr_error'] = gettext('Stop the VM before changing CPU, memory or loader.');
|
||||
header('Location: vmmngr_vm.php?name=' . urlencode($name));
|
||||
exit;
|
||||
}
|
||||
$cpu = trim((string)($_POST['cpu'] ?? ''));
|
||||
$mem = strtoupper(trim((string)($_POST['memory'] ?? '')));
|
||||
$loader = (string)($_POST['loader'] ?? '');
|
||||
$graphics = (string)($_POST['graphics'] ?? 'no');
|
||||
$switch = trim((string)($_POST['switch'] ?? ''));
|
||||
|
||||
if (!preg_match('/^[0-9]{1,2}$/', $cpu) || (int)$cpu < 1 || (int)$cpu > 64) {
|
||||
$_SESSION['vmmngr_error'] = gettext('vCPU must be between 1 and 64.');
|
||||
} elseif (!preg_match('/^[0-9]{1,5}[MG]$/', $mem)) {
|
||||
$_SESSION['vmmngr_error'] = gettext('Memory must look like 2G or 512M.');
|
||||
} elseif (!in_array($loader, ['uefi', 'uefi-csm', 'grub', 'bhyve'], true)) {
|
||||
$_SESSION['vmmngr_error'] = gettext('Unknown loader.');
|
||||
} else {
|
||||
$pairs = [
|
||||
'cpu' => $cpu,
|
||||
'memory' => $mem,
|
||||
'loader' => $loader,
|
||||
'graphics' => $graphics === 'yes' ? 'yes' : 'no',
|
||||
];
|
||||
if ($switch !== '') {
|
||||
$pairs['network0_switch'] = $switch;
|
||||
}
|
||||
$res = vmm_conf_set($name, $pairs);
|
||||
if (!$res['ok']) {
|
||||
$_SESSION['vmmngr_error'] = (string)$res['error'];
|
||||
} else {
|
||||
vmm_autostart_set($name, isset($_POST['autostart']));
|
||||
$_SESSION['vmmngr_error'] = $res['changed'] === []
|
||||
? gettext('No changes.')
|
||||
: sprintf(gettext('Updated: %s'), implode(', ', $res['changed']));
|
||||
}
|
||||
}
|
||||
header('Location: vmmngr_vm.php?name=' . urlencode($name));
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($verb === 'novnc_start' || $verb === 'novnc_stop') {
|
||||
if ($verb === 'novnc_stop') {
|
||||
vmm_novnc_stop($name);
|
||||
@@ -175,6 +218,70 @@ vmm_nav('', $name);
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
$confNow = vmm_conf_get($name);
|
||||
$autoOn = in_array($name, vmm_autostart_names(), true);
|
||||
$switchNames = array_map(static fn($x) => (string)($x['name'] ?? ''), vmm_switches());
|
||||
?>
|
||||
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
|
||||
<colgroup><col class="area_data_settings_col_tag"><col class="area_data_settings_col_data"></colgroup>
|
||||
<thead><?php html_separator2(); html_titleline2(gettext('Configuration'), 2); ?></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('vCPU');?></td>
|
||||
<td class="celldata"><input type="text" name="cpu" size="6" value="<?=vmm_h((string)($confNow['cpu'] ?? '1'));?>" <?=$isRunning ? 'disabled' : '';?>/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('Memory');?></td>
|
||||
<td class="celldata"><input type="text" name="memory" size="8" value="<?=vmm_h((string)($confNow['memory'] ?? '1G'));?>" <?=$isRunning ? 'disabled' : '';?>/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('Loader');?></td>
|
||||
<td class="celldata">
|
||||
<select name="loader" <?=$isRunning ? 'disabled' : '';?>>
|
||||
<?php foreach (['uefi', 'uefi-csm', 'grub', 'bhyve'] as $ld): ?>
|
||||
<option value="<?=$ld;?>" <?=($confNow['loader'] ?? '') === $ld ? 'selected' : '';?>><?=$ld;?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('Graphics (VNC)');?></td>
|
||||
<td class="celldata">
|
||||
<select name="graphics" <?=$isRunning ? 'disabled' : '';?>>
|
||||
<option value="no" <?=($confNow['graphics'] ?? 'no') === 'no' ? 'selected' : '';?>>no</option>
|
||||
<option value="yes" <?=($confNow['graphics'] ?? '') === 'yes' ? 'selected' : '';?>>yes</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('Network switch');?></td>
|
||||
<td class="celldata">
|
||||
<select name="switch" <?=$isRunning ? 'disabled' : '';?>>
|
||||
<?php foreach ($switchNames as $sw): ?>
|
||||
<option value="<?=vmm_h($sw);?>" <?=($confNow['network0_switch'] ?? '') === $sw ? 'selected' : '';?>><?=vmm_h($sw);?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('Autostart');?></td>
|
||||
<td class="celldata">
|
||||
<label><input type="checkbox" name="autostart" value="1" <?=$autoOn ? 'checked' : '';?>/> <?=gettext('start at boot (vm_list)');?></label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="celltag"> </td>
|
||||
<td class="celldata">
|
||||
<button type="submit" class="formbtn" name="act" value="save_config:<?=vmm_h($name);?>" <?=$isRunning ? 'disabled' : '';?>><?=gettext('Save');?></button>
|
||||
<?php if ($isRunning): ?>
|
||||
<span style="opacity:.75;margin-left:8px;"><?=gettext('Stop the VM to change these values.');?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
$vncBind = '';
|
||||
foreach (($info['sections']['console-ports'] ?? []) as $b) {
|
||||
|
||||
Reference in new issue
Block a user