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

+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'; ?>