0.11.0: VM configuration editor (cpu, memory, loader, graphics, switch, autostart)

This commit is contained in:
Claw committed 2026-11-17 21:27:19 +01:00
1 parent f4160054ab
commit 02cb6b1079
7 files changed
+201 -2

No files matched your search

+5
View File
@@ -2,6 +2,11 @@
All notable changes to the VM Manager extension. All notable changes to the VM Manager extension.
## 0.11.0
- VM detail: configuration editor for vCPU, memory, loader, VNC, network switch and
autostart (stopped guests only); writes `<vm>.conf` with a `.vmmngr.bak` backup and
keeps `vm_list` in sync.
## 0.10.2 ## 0.10.2
- Create wizard: driver ISO (virtio-win) as second CD device, separate download row, - Create wizard: driver ISO (virtio-win) as second CD device, separate download row,
hint when no virtio image is present. hint when no virtio image is present.
+1
View File
@@ -14,6 +14,7 @@ Status: **0.10.1** – feature-complete for daily use on a single node.
|---|---| |---|---|
| Dashboard | all guests with state, loader, vCPU, RAM, datastore, autostart; start/stop/restart inline | | Dashboard | all guests with state, loader, vCPU, RAM, datastore, autostart; start/stop/restart inline |
| VM actions | start, stop, restart, reset, power-off, destroy (typed name required, ZFS holds released first) | | VM actions | start, stop, restart, reset, power-off, destroy (typed name required, ZFS holds released first) |
| VM settings | edit vCPU, memory, loader, graphics/VNC, network switch and autostart of a stopped VM |
| Create wizard | template, datastore, vCPU/RAM/disk, switch, optional boot ISO, optional virtio-win driver ISO, optional start, optional cloud-init image | | Create wizard | template, datastore, vCPU/RAM/disk, switch, optional boot ISO, optional virtio-win driver ISO, optional start, optional cloud-init image |
| Images | ISO/IMG inventory, HTTP(S) downloads as jobs, delete with typed confirmation, virtio-win preset | | Images | ISO/IMG inventory, HTTP(S) downloads as jobs, delete with typed confirmation, virtio-win preset |
| Templates | list, edit, duplicate, delete, create from skeleton | | Templates | list, edit, duplicate, delete, create from skeleton |
+66
View File
@@ -1223,6 +1223,72 @@ function vmm_attached_isos(string $name): array
return array_values(array_filter($out, static fn($d) => ($d['path'] ?? '') !== '')); return array_values(array_filter($out, static fn($d) => ($d['path'] ?? '') !== ''));
} }
/**
* Read a VM's config file into a key => value map (quoted values, comments kept
* out of the map).
*/
function vmm_conf_get(string $name): array
{
$conf = vmm_vm_conf_path($name);
if ($conf === '' || !is_file($conf)) {
return [];
}
$out = [];
foreach (preg_split('/\R/', (string)file_get_contents($conf)) ?: [] as $line) {
if (preg_match('/^([A-Za-z0-9_]+)="([^"]*)"\s*$/', trim($line), $m)) {
$out[$m[1]] = $m[2];
} elseif (preg_match('/^([A-Za-z0-9_]+)=([^"\s].*)\s*$/', trim($line), $m)) {
$out[$m[1]] = $m[2];
}
}
return $out;
}
/**
* Update or insert config keys, keeping every other line untouched.
* Returns ['ok'=>bool, 'changed'=>[...]].
*/
function vmm_conf_set(string $name, array $pairs): array
{
$conf = vmm_vm_conf_path($name);
if ($conf === '' || !is_file($conf)) {
return ['ok' => false, 'error' => 'vm config not found'];
}
$lines = preg_split('/\R/', (string)file_get_contents($conf)) ?: [];
$changed = [];
foreach ($pairs as $key => $value) {
if (!preg_match('/^[A-Za-z0-9_]+$/', (string)$key)) {
continue;
}
$value = (string)$value;
$isNumeric = preg_match('/^[0-9]+[A-Za-z]?$/', $value) === 1 && preg_match('/^(cpu|memory)$/', (string)$key) === 1;
$line = $isNumeric ? $key . '=' . $value : $key . '="' . $value . '"';
$found = false;
foreach ($lines as $i => $existing) {
if (preg_match('/^' . preg_quote((string)$key, '/') . '=/', trim($existing))) {
if (trim($existing) !== $line) {
$lines[$i] = $line;
$changed[] = (string)$key;
}
$found = true;
break;
}
}
if (!$found) {
$lines[] = $line;
$changed[] = (string)$key;
}
}
if ($changed === []) {
return ['ok' => true, 'changed' => []];
}
@copy($conf, $conf . '.vmmngr.bak');
if (@file_put_contents($conf, implode("\n", $lines) . "\n") === false) {
return ['ok' => false, 'error' => 'cannot write vm config'];
}
return ['ok' => true, 'changed' => $changed];
}
/** /**
* Attach ISOs as read-only CD devices and drop any previously attached ones. * Attach ISOs as read-only CD devices and drop any previously attached ones.
* Returns ['added' => [...], 'removed' => [...]] * Returns ['added' => [...], 'removed' => [...]]
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"appname": "VM Manager", "appname": "VM Manager",
"version": "0.10.2", "version": "0.11.0",
"rootfolder": "/mnt/Daten/extensions/vmmngr", "rootfolder": "/mnt/Daten/extensions/vmmngr",
"vm_source": "auto", "vm_source": "auto",
"bridges": ["ix0bridge"], "bridges": ["ix0bridge"],
+20
View File
@@ -147,6 +147,26 @@ if (!function_exists('vmm_register_boot')) {
return ''; return '';
} }
function vmm_autostart_names(): array
{
$list = trim(vmm_rc_param('vm_list'));
if ($list === '') {
return [];
}
return preg_split('/\s+/', $list) ?: [];
}
function vmm_autostart_set(string $name, bool $on): bool
{
$names = vmm_autostart_names();
$names = array_values(array_filter($names, static fn($n) => $n !== $name));
if ($on) {
$names[] = $name;
}
vmm_set_rc_param('vm_list', implode(' ', $names));
return true;
}
function vmm_boot_state(): array function vmm_boot_state(): array
{ {
global $config; global $config;
+107
View File
@@ -4,6 +4,7 @@
*/ */
require_once 'vmmngr-boot.inc'; require_once 'vmmngr-boot.inc';
require_once 'vmmngr-config-lib.inc';
$name = (string)($_GET['name'] ?? ''); $name = (string)($_GET['name'] ?? '');
// POSTs from this page carry the VM name in the act field; accept that too so // 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; $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_start' || $verb === 'novnc_stop') {
if ($verb === 'novnc_stop') { if ($verb === 'novnc_stop') {
vmm_novnc_stop($name); vmm_novnc_stop($name);
@@ -175,6 +218,70 @@ vmm_nav('', $name);
</tbody> </tbody>
</table> </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">&nbsp;</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 <?php
$vncBind = ''; $vncBind = '';
foreach (($info['sections']['console-ports'] ?? []) as $b) { foreach (($info['sections']['console-ports'] ?? []) as $b) {
+1 -1
View File
@@ -1 +1 @@
0.10.2 0.11.0