vmmngr 0.1.0-preview: read-only VM Manager extension (installer, vmm-ctl, GUI)

This commit is contained in:
Claw committed 2026-11-17 19:16:16 +01:00
commit 5f664cc8c2
14 files changed
+1422

No files matched your search

+1
View File
@@ -0,0 +1 @@
<a href="vmmngr.php">VM Manager</a>
+10
View File
@@ -0,0 +1,10 @@
{
"appname": "VM Manager",
"version": "0.1.0-preview",
"rootfolder": "/mnt/Daten/extensions/vmmngr",
"vm_source": "auto",
"bridges": ["ix0bridge"],
"default_bridge": "ix0bridge",
"enable": true,
"job_timeout": 900
}
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* vmmngr-boot.inc - bootstrap for all VM Manager pages.
*
* Works both in the extension tree and through the symlinks in /usr/local/www:
* realpath() resolves the link, so the shared library is found either way.
*/
require_once 'auth.inc';
require_once 'guiconfig.inc';
$vmm_self = realpath(__FILE__);
$vmm_root = dirname(dirname($vmm_self));
require_once $vmm_root . '/bin/vmm-lib.php';
if (!function_exists('vmm_badge')) {
function vmm_badge(string $state): string
{
$map = [
'running' => ['vmm-running', gettext('Running')],
'stopped' => ['vmm-stopped', gettext('Stopped')],
'suspended' => ['vmm-suspended', gettext('Suspended')],
'starting' => ['vmm-starting', gettext('Starting')],
'locked' => ['vmm-locked', gettext('Locked')],
];
[$cls, $label] = $map[$state] ?? ['vmm-unknown', ucfirst($state)];
return sprintf('<span class="vmm-badge %s">%s</span>', $cls, htmlspecialchars($label));
}
function vmm_h(string $s): string
{
return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
}
function vmm_source_label(array $p): string
{
$icon = match ($p['source']) {
'system' => '🖥',
'bundle' => '📦',
default => '⚠',
};
return sprintf('%s %s', $icon, $p['source']);
}
}
+128
View File
@@ -0,0 +1,128 @@
<?php
/*
* vmmngr.php - VM Manager dashboard (read-only preview 0.1.0)
*/
require_once 'vmmngr-boot.inc';
$pgtitle = [gettext('Extensions'), gettext('VM Manager')];
$conf = vmm_config();
$vmprov = vmm_resolve('vm');
$vms = $vmprov['available'] ? vmm_list() : [];
$ver = $vmprov['available'] ? vmm_vm_version() : ['version' => '', 'rev' => ''];
$vm_dir = $vmprov['available'] ? vmm_vm_dir() : '';
$running = array_values(array_filter($vms, static fn(array $v): bool => ($v['state'] ?? '') === 'running'));
$mem_used = 0;
$cpus = 0;
foreach ($running as $v) {
$mem_used += vmm_size_to_bytes((string)($v['memory'] ?? '0'));
$cpus += (int)($v['cpu'] ?? 0);
}
include 'fbegin.inc';
?>
<style>
.vmm-badge{display:inline-block;padding:1px 8px;border-radius:10px;font-size:11px;font-weight:600;letter-spacing:.02em}
.vmm-running{background:#153e2b;color:#5ee79b;border:1px solid #2f7d54}
.vmm-stopped{background:#3a2c2c;color:#e0a0a0;border:1px solid #7d4a4a}
.vmm-suspended,.vmm-starting{background:#3a3320;color:#e8cf7a;border:1px solid #7d6a2f}
.vmm-unknown,.vmm-locked{background:#2c2c3a;color:#a9a9d0;border:1px solid #4a4a7d}
.vmm-grid{display:flex;flex-wrap:wrap;gap:10px;margin:10px 0 14px}
.vmm-card{flex:1 1 150px;min-width:150px;padding:10px 12px;border:1px solid #3a3f46;border-radius:6px;background:#23272c}
.vmm-card .k{font-size:11px;text-transform:uppercase;letter-spacing:.05em;opacity:.65}
.vmm-card .v{font-size:20px;font-weight:600;margin-top:2px}
.vmm-card .s{font-size:11px;opacity:.7;margin-top:2px}
.vmm-mono{font-family:monospace;font-size:12px}
</style>
<form action="vmmngr.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
<?php if (!$vmprov['available']): ?>
<?php print_info_box(sprintf(gettext('vm-bhyve was not found. Neither %s nor the bundled copy exists.'), '/usr/local/sbin/vm') . '<br />' . gettext('Install vm-bhyve or run the installer with a bundled vendor tree.')); ?>
<?php endif; ?>
<div class="vmm-grid">
<div class="vmm-card">
<div class="k"><?=gettext('Virtual Machines');?></div>
<div class="v"><?=count($running);?> / <?=count($vms);?></div>
<div class="s"><?=gettext('running / total');?></div>
</div>
<div class="vmm-card">
<div class="k"><?=gettext('Assigned Memory');?></div>
<div class="v"><?=vmm_human_bytes($mem_used);?></div>
<div class="s"><?=$cpus;?> vCPU</div>
</div>
<div class="vmm-card">
<div class="k"><?=gettext('vm-bhyve');?></div>
<div class="v"><?=vmm_h((string)($ver['version'] ?? '?'));?></div>
<div class="s"><?=vmm_source_label($vmprov);?> · rev <?=vmm_h((string)($ver['rev'] ?? '?'));?></div>
</div>
<div class="vmm-card">
<div class="k"><?=gettext('Datastore');?></div>
<div class="v"><?=vmm_h(ltrim(str_replace('zfs:', '', $vm_dir), '/'));?></div>
<div class="s vmm-mono"><?=vmm_h($vm_dir);?></div>
</div>
</div>
<table class="area_data_selection" style="width:100%;table-layout:fixed;border-collapse:collapse;">
<colgroup>
<col style="width:20%">
<col style="width:12%">
<col style="width:9%">
<col style="width:7%">
<col style="width:9%">
<col style="width:18%">
<col style="width:7%">
<col style="width:18%">
</colgroup>
<thead>
<?php
html_separator2();
html_titleline2(gettext('Virtual Machines'), 8);
?>
<tr>
<th class="lhell"><?=gettext('Name');?></th>
<th class="lhell"><?=gettext('State');?></th>
<th class="lhell"><?=gettext('Loader');?></th>
<th class="lhell"><?=gettext('vCPU');?></th>
<th class="lhell"><?=gettext('Memory');?></th>
<th class="lhell"><?=gettext('Datastore');?></th>
<th class="lhell"><?=gettext('Autostart');?></th>
<th class="lhebl"><?=gettext('Details');?></th>
</tr>
</thead>
<tbody>
<?php if ($vms === []): ?>
<tr><td class="lcell" colspan="8"><?=gettext('No virtual machines found.');?></td></tr>
<?php else: ?>
<?php foreach ($vms as $v): ?>
<tr>
<td class="lcell"><strong><?=vmm_h((string)$v['name']);?></strong></td>
<td class="lcell"><?=vmm_badge((string)$v['state']);?></td>
<td class="lcell"><?=vmm_h((string)$v['loader']);?></td>
<td class="lcell"><?=vmm_h((string)$v['cpu']);?></td>
<td class="lcell"><?=vmm_h((string)$v['memory']);?></td>
<td class="lcell"><?=vmm_h((string)$v['datastore']);?></td>
<td class="lcell"><?=!empty($v['auto']) ? gettext('yes') : gettext('no');?></td>
<td class="lcebl">
<a class="formbtn" href="vmmngr_vm.php?name=<?=urlencode((string)$v['name']);?>"><?=gettext('Open');?></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<div id="remarks">
<?php
html_remark2(
'preview',
gettext('Preview build'),
gettext('This build is read-only on purpose: it lists and inspects the existing machines but does not start, stop or change anything. Actions, creation wizard, images and templates follow in the next milestone.')
);
?>
</div>
</td></tr></tbody></table></form>
<?php include 'fend.inc'; ?>
+42
View File
@@ -0,0 +1,42 @@
<?php
/*
* vmmngr_api.php - read-only JSON endpoint.
*
* GET/POST ?action=list|info|selfcheck
* Every request requires an authenticated admin session (XigmaNAS auth.inc).
*/
require_once 'vmmngr-boot.inc';
if (!session::is_admin()) {
vmm_json(['ok' => false, 'error' => 'forbidden'], 403);
}
$action = (string)($_REQUEST['action'] ?? '');
$name = (string)($_REQUEST['name'] ?? '');
switch ($action) {
case 'list':
$vms = vmm_list();
vmm_json(['ok' => true, 'count' => count($vms), 'vms' => $vms]);
// no break
case 'info':
if (!vmm_valid_name($name)) {
vmm_json(['ok' => false, 'error' => 'invalid name'], 400);
}
$info = vmm_info($name);
if (isset($info['error'])) {
vmm_json(['ok' => false, 'error' => $info['error']], 500);
}
vmm_json(['ok' => true, 'vm' => $name, 'info' => $info]);
// no break
case 'selfcheck':
case '':
vmm_json(['ok' => true, 'selfcheck' => vmm_selfcheck()]);
// no break
default:
vmm_json(['ok' => false, 'error' => 'unknown action'], 400);
}
+120
View File
@@ -0,0 +1,120 @@
<?php
/*
* vmmngr_config.php - environment and provider self-check (preview 0.1.0)
*/
require_once 'vmmngr-boot.inc';
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Configuration')];
$sc = vmm_selfcheck();
$conf = vmm_config();
include 'fbegin.inc';
?>
<style>
.vmm-mono{font-family:monospace;font-size:12px}
.vmm-raw{background:#1b1f23;border:1px solid #333a41;border-radius:4px;padding:10px;overflow:auto;max-height:420px}
.vmm-ok{color:#5ee79b}
.vmm-miss{color:#e0a0a0}
</style>
<form action="vmmngr_config.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
<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('Environment'), 2); ?>
</thead>
<tbody>
<tr><td class="celltag"><?=gettext('Platform');?></td><td class="celldata"><?=vmm_h($sc['platform']);?> · <?=vmm_h($sc['product']);?> · <?=vmm_h($sc['os']);?></td></tr>
<tr><td class="celltag">PHP</td><td class="celldata"><?=vmm_h($sc['php']);?></td></tr>
<tr><td class="celltag"><?=gettext('Extension root');?></td><td class="celldata vmm-mono"><?=vmm_h($sc['root']);?></td></tr>
<tr><td class="celltag">vm_dir</td><td class="celldata vmm-mono"><?=vmm_h($sc['vm_dir']);?></td></tr>
<tr><td class="celltag"><?=gettext('Kernel modules');?></td><td class="celldata">
vmm: <span class="<?=$sc['kld']['vmm'] === 'loaded' ? 'vmm-ok' : 'vmm-miss';?>"><?=vmm_h($sc['kld']['vmm']);?></span> ·
nmdm: <span class="<?=$sc['kld']['nmdm'] === 'loaded' ? 'vmm-ok' : 'vmm-miss';?>"><?=vmm_h($sc['kld']['nmdm']);?></span>
</td></tr>
<tr><td class="celltag"><?=gettext('Virtual machines');?></td><td class="celldata"><?=$sc['vm_count'];?> <?=gettext('total');?>, <?=$sc['vm_running'];?> <?=gettext('running');?></td></tr>
</tbody>
</table>
<br />
<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('Components and provider'), 2); ?>
</thead>
<tbody>
<?php
$rows = [
'vm' => gettext('vm-bhyve'),
'grub' => gettext('grub-bhyve'),
'firmware' => gettext('UEFI firmware'),
'ttyd' => gettext('Web terminal (ttyd)'),
];
foreach ($rows as $key => $label):
$p = $sc[$key];
$ok = !empty($p['available']);
?>
<tr>
<td class="celltag"><?=$label;?></td>
<td class="celldata">
<span class="<?=$ok ? 'vmm-ok' : 'vmm-miss';?>"><?=$ok ? gettext('available') : gettext('missing');?></span>
· <?=gettext('source');?>: <strong><?=vmm_h((string)$p['source']);?></strong>
<div class="vmm-mono"><?=vmm_h((string)$p['path']);?></div>
<?php if ($key === 'vm' && !empty($sc['vm']['version']['version'])): ?>
<div class="vmm-mono"><?=vmm_h((string)$sc['vm']['version']['version']);?> (rev <?=vmm_h((string)($sc['vm']['version']['rev'] ?? '?'));?>)</div>
<?php endif; ?>
<?php if ($key === 'firmware' && !empty($sc['firmware']['mtime'])): ?>
<div class="vmm-mono"><?=vmm_h((string)$sc['firmware']['mtime']);?> · <?=vmm_h(vmm_human_bytes((int)$sc['firmware']['size']));?></div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr><td class="celltag"><?=gettext('Update policy');?></td><td class="celldata"><span class="vmm-mono">vm_source = <?=vmm_h((string)$conf['vm_source']);?></span> — <?=gettext('the system installation always wins; the bundle only fills gaps.');?></td></tr>
</tbody>
</table>
<br />
<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('Datastores and switches'), 2); ?>
</thead>
<tbody>
<?php foreach (($sc['datastores'] ?? []) as $ds): ?>
<tr>
<td class="celltag"><?=gettext('Datastore');?></td>
<td class="celldata vmm-mono"><?=vmm_h(implode(' · ', array_map('strval', $ds)));?></td>
</tr>
<?php endforeach; ?>
<?php if (($sc['datastores'] ?? []) === []): ?>
<tr><td class="celltag"><?=gettext('Datastore');?></td><td class="celldata"><?=gettext('none reported');?></td></tr>
<?php endif; ?>
<?php foreach (($sc['switches'] ?? []) as $sw): ?>
<tr>
<td class="celltag"><?=gettext('Switch');?></td>
<td class="celldata vmm-mono"><?=vmm_h(implode(' · ', array_map('strval', $sw)));?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<details style="margin-top:12px;">
<summary style="cursor:pointer;padding:6px 0;"><?=gettext('Raw self-check (JSON)');?></summary>
<pre class="vmm-raw vmm-mono"><?=vmm_h(json_encode($sc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));?></pre>
</details>
</td></tr></tbody></table></form>
<?php include 'fend.inc'; ?>
+104
View File
@@ -0,0 +1,104 @@
<?php
/*
* vmmngr_vm.php - VM detail view (read-only preview 0.1.0)
*/
require_once 'vmmngr-boot.inc';
$name = (string)($_GET['name'] ?? '');
if ($name === '' || !vmm_valid_name($name)) {
header('Location: vmmngr.php');
exit;
}
$info = vmm_info($name);
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), $name];
include 'fbegin.inc';
?>
<style>
.vmm-badge{display:inline-block;padding:1px 8px;border-radius:10px;font-size:11px;font-weight:600}
.vmm-running{background:#153e2b;color:#5ee79b;border:1px solid #2f7d54}
.vmm-stopped{background:#3a2c2c;color:#e0a0a0;border:1px solid #7d4a4a}
.vmm-suspended,.vmm-starting{background:#3a3320;color:#e8cf7a;border:1px solid #7d6a2f}
.vmm-unknown,.vmm-locked{background:#2c2c3a;color:#a9a9d0;border:1px solid #4a4a7d}
.vmm-mono{font-family:monospace;font-size:12px}
.vmm-raw{background:#1b1f23;border:1px solid #333a41;border-radius:4px;padding:10px;overflow:auto;max-height:420px}
</style>
<form action="vmmngr_vm.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
<?php if (isset($info['error'])): ?>
<?php print_info_box(sprintf(gettext('Could not read VM details: %s'), vmm_h((string)$info['error']))); ?>
<?php else: ?>
<?php
$g = $info['general'] ?? [];
$state = vmm_state_from_string((string)($g['state'] ?? ''));
?>
<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(sprintf('%s: %s', gettext('Virtual Machine'), $name), 2);
?>
</thead>
<tbody>
<tr><td class="celltag"><?=gettext('State');?></td><td class="celldata"><?=vmm_badge($state['state']);?> <?php if ($state['pid']): ?><span class="vmm-mono">PID <?=$state['pid'];?></span><?php endif; ?></td></tr>
<tr><td class="celltag"><?=gettext('Loader');?></td><td class="celldata"><?=vmm_h((string)($g['loader'] ?? ''));?></td></tr>
<tr><td class="celltag"><?=gettext('vCPU / Memory');?></td><td class="celldata"><?=vmm_h((string)($g['cpu'] ?? ''));?> vCPU · <?=vmm_h((string)($g['memory'] ?? ''));?><?php if (!empty($g['memory-resident'])): ?> <span class="vmm-mono">(<?=vmm_h((string)$g['memory-resident']);?>)</span><?php endif; ?></td></tr>
<tr><td class="celltag"><?=gettext('Datastore');?></td><td class="celldata"><?=vmm_h((string)($g['datastore'] ?? ''));?></td></tr>
<tr><td class="celltag">UUID</td><td class="celldata vmm-mono"><?=vmm_h((string)($g['uuid'] ?? ''));?></td></tr>
</tbody>
</table>
<br />
<?php foreach (($info['sections'] ?? []) as $type => $blocks): ?>
<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(vmm_h(ucwords(str_replace('-', ' ', $type))), 2); ?>
</thead>
<tbody>
<?php foreach ($blocks as $b): ?>
<?php foreach ($b['data'] as $k => $v): ?>
<tr>
<td class="celltag"><?=vmm_h((string)$k);?></td>
<td class="celldata vmm-mono"><?=vmm_h((string)$v);?></td>
</tr>
<?php endforeach; ?>
<?php foreach ($b['lines'] as $line): ?>
<tr>
<td class="celltag">—</td>
<td class="celldata vmm-mono"><?=vmm_h((string)$line);?></td>
</tr>
<?php endforeach; ?>
<?php if ($b['data'] === [] && $b['lines'] === []): ?>
<tr><td class="celltag">—</td><td class="celldata"><?=gettext('none');?></td></tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
<br />
<?php endforeach; ?>
<details>
<summary style="cursor:pointer;padding:6px 0;"><?=gettext('Raw vm-bhyve output');?></summary>
<pre class="vmm-raw vmm-mono"><?=vmm_h((string)($info['raw'] ?? ''));?></pre>
</details>
<?php endif; ?>
<div id="remarks">
<?php html_remark2('preview', gettext('Read-only'), gettext('Actions are intentionally not wired yet. This page shows exactly what vm-bhyve reports.')); ?>
</div>
</td></tr></tbody></table></form>
<?php include 'fend.inc'; ?>