0.2.0: job engine, VM actions, theme-aware styling
This commit is contained in:
1 parent
c62de24cc0
commit
485a267ffe
14 files changed
+901
-71
No files matched your search
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"appname": "VM Manager",
|
||||
"version": "0.1.0-preview",
|
||||
"version": "0.2.0",
|
||||
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
||||
"vm_source": "auto",
|
||||
"bridges": ["ix0bridge"],
|
||||
"default_bridge": "ix0bridge",
|
||||
"enable": true,
|
||||
"job_timeout": 900
|
||||
"job_timeout": 900,
|
||||
"ram_budget_pct": 85
|
||||
}
|
||||
@@ -42,3 +42,36 @@ if (!function_exists('vmm_badge')) {
|
||||
return sprintf('%s %s', $icon, $p['source']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('vmm_css')) {
|
||||
/**
|
||||
* Theme-aware styles: no hardcoded dark panels — colours derive from the
|
||||
* XigmaNAS theme variables, so light and dark themes both stay readable.
|
||||
*/
|
||||
function vmm_css(): void
|
||||
{
|
||||
?>
|
||||
<style>
|
||||
.vmm-badge{display:inline-block;padding:1px 8px;border-radius:10px;font-size:11px;font-weight:600;border:1px solid currentColor;background:transparent;white-space:nowrap}
|
||||
.vmm-running{color:#2f9e63}
|
||||
.vmm-stopped{color:#c25656}
|
||||
.vmm-suspended,.vmm-starting{color:#b98a1f}
|
||||
.vmm-unknown,.vmm-locked{color:#7d7dab}
|
||||
.vmm-grid{display:flex;flex-wrap:wrap;gap:10px;margin:10px 0 14px}
|
||||
.vmm-card{flex:1 1 160px;min-width:160px;padding:10px 12px;border:1px solid rgba(127,127,127,.35);border-radius:6px;background:var(--bgc-area-data,transparent);color:inherit}
|
||||
.vmm-card .k{font-size:11px;text-transform:uppercase;letter-spacing:.05em;opacity:.7}
|
||||
.vmm-card .v{font-size:20px;font-weight:600;margin-top:2px}
|
||||
.vmm-card .s{font-size:11px;opacity:.75;margin-top:2px}
|
||||
.vmm-mono{font-family:monospace;font-size:12px}
|
||||
.vmm-raw{background:var(--bgc-input-ro,rgba(127,127,127,.08));color:inherit;border:1px solid rgba(127,127,127,.3);border-radius:4px;padding:10px;overflow:auto;max-height:340px;white-space:pre-wrap}
|
||||
.vmm-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
||||
.vmm-job{display:none;margin:12px 0;border:1px solid rgba(127,127,127,.35);border-radius:6px;padding:10px;background:var(--bgc-area-data,transparent)}
|
||||
.vmm-job-head{font-size:12px;margin-bottom:6px;opacity:.9}
|
||||
.vmm-job-state{font-weight:600;margin-left:6px}
|
||||
.vmm-ok{color:#2f9e63}
|
||||
.vmm-err{color:#c25656}
|
||||
</style>
|
||||
<script src="vmmngr.js"></script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* vmmngr.js - minimal helpers for the VM Manager GUI.
|
||||
* Mutations are POST-only against vmmngr_api.php; long tasks run as jobs.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function post(data) {
|
||||
return fetch('vmmngr_api.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
|
||||
body: new URLSearchParams(data).toString()
|
||||
}).then(function (r) { return r.json(); });
|
||||
}
|
||||
|
||||
function poll(id, box) {
|
||||
var head = box.querySelector('.vmm-job-head');
|
||||
var stateEl = box.querySelector('.vmm-job-state');
|
||||
var logEl = box.querySelector('pre');
|
||||
var timer = setInterval(function () {
|
||||
fetch('vmmngr_api.php?action=job&id=' + encodeURIComponent(id), {credentials: 'same-origin'})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (d) {
|
||||
if (!d.ok) { return; }
|
||||
var j = d.job;
|
||||
stateEl.textContent = j.state + (j.rc !== null && j.rc !== undefined ? ' (rc ' + j.rc + ')' : '');
|
||||
stateEl.className = 'vmm-job-state ' + (j.state === 'failed' ? 'vmm-err' : 'vmm-ok');
|
||||
logEl.textContent = j.log || '';
|
||||
logEl.scrollTop = logEl.scrollHeight;
|
||||
if (j.state === 'done' || j.state === 'failed' || j.state === 'canceled') {
|
||||
clearInterval(timer);
|
||||
}
|
||||
});
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
window.vmmTrack = function (id) {
|
||||
var box = document.getElementById('vmm-job');
|
||||
if (!box) { return; }
|
||||
box.style.display = 'block';
|
||||
box.innerHTML = '<div class="vmm-job-head">Job <span class="vmm-mono">' + id + '</span><span class="vmm-job-state">queued</span></div><pre class="vmm-raw"></pre>';
|
||||
poll(id, box);
|
||||
};
|
||||
|
||||
window.vmmRun = function (verb, vm, confirmText) {
|
||||
var payload = {action: 'action', verb: verb, vm: vm};
|
||||
if (confirmText !== undefined && confirmText !== null) {
|
||||
payload.confirm = confirmText;
|
||||
}
|
||||
post(payload).then(function (d) {
|
||||
if (!d.ok) {
|
||||
alert(d.error || 'action refused');
|
||||
return;
|
||||
}
|
||||
vmmTrack(d.job.id);
|
||||
}).catch(function (e) {
|
||||
alert('request failed: ' + e);
|
||||
});
|
||||
};
|
||||
|
||||
window.vmmConfirmRun = function (verb, vm, question) {
|
||||
if (!window.confirm(question)) { return; }
|
||||
vmmRun(verb, vm);
|
||||
};
|
||||
|
||||
window.vmmDestroy = function (vm) {
|
||||
if (!window.confirm('Destroy ' + vm + '?\n\nAll disks and snapshots of this VM are deleted. This cannot be undone.')) {
|
||||
return;
|
||||
}
|
||||
var typed = window.prompt('Type the VM name to confirm:', '');
|
||||
if (typed === null) { return; }
|
||||
if (typed !== vm) {
|
||||
alert('Name does not match - nothing was done.');
|
||||
return;
|
||||
}
|
||||
vmmRun('destroy', vm, typed);
|
||||
};
|
||||
})();
|
||||
+75
-30
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* vmmngr.php - VM Manager dashboard (read-only preview 0.1.0)
|
||||
* vmmngr.php - VM Manager dashboard (0.2.0: actions via job engine)
|
||||
*/
|
||||
|
||||
require_once 'vmmngr-boot.inc';
|
||||
@@ -11,6 +11,7 @@ $vmprov = vmm_resolve('vm');
|
||||
$vms = $vmprov['available'] ? vmm_list() : [];
|
||||
$ver = $vmprov['available'] ? vmm_vm_version() : ['version' => '', 'rev' => ''];
|
||||
$vm_dir = $vmprov['available'] ? vmm_vm_dir() : '';
|
||||
$budget = vmm_ram_budget();
|
||||
|
||||
$running = array_values(array_filter($vms, static fn(array $v): bool => ($v['state'] ?? '') === 'running'));
|
||||
$mem_used = 0;
|
||||
@@ -19,27 +20,17 @@ foreach ($running as $v) {
|
||||
$mem_used += vmm_size_to_bytes((string)($v['memory'] ?? '0'));
|
||||
$cpus += (int)($v['cpu'] ?? 0);
|
||||
}
|
||||
vmm_job_recover();
|
||||
$jobs = vmm_job_list(5);
|
||||
|
||||
include 'fbegin.inc';
|
||||
vmm_css();
|
||||
?>
|
||||
<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 print_info_box(sprintf(gettext('vm-bhyve was not found. Neither %s nor the bundled copy exists.'), '/usr/local/sbin/vm')); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="vmm-grid">
|
||||
@@ -51,7 +42,7 @@ include 'fbegin.inc';
|
||||
<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 class="s"><?=$cpus;?> vCPU · <?=gettext('budget');?> <?=vmm_human_bytes($budget['limit']);?> (<?=$budget['pct'];?>%)</div>
|
||||
</div>
|
||||
<div class="vmm-card">
|
||||
<div class="k"><?=gettext('vm-bhyve');?></div>
|
||||
@@ -65,16 +56,18 @@ include 'fbegin.inc';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="vmm-job" class="vmm-job"></div>
|
||||
|
||||
<table class="area_data_selection" style="width:100%;table-layout:fixed;border-collapse:collapse;">
|
||||
<colgroup>
|
||||
<col style="width:20%">
|
||||
<col style="width:16%">
|
||||
<col style="width:11%">
|
||||
<col style="width:8%">
|
||||
<col style="width:6%">
|
||||
<col style="width:8%">
|
||||
<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%">
|
||||
<col style="width:6%">
|
||||
<col style="width:33%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<?php
|
||||
@@ -88,8 +81,8 @@ include 'fbegin.inc';
|
||||
<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>
|
||||
<th class="lhell"><?=gettext('Auto');?></th>
|
||||
<th class="lhebl"><?=gettext('Actions');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -97,8 +90,13 @@ include 'fbegin.inc';
|
||||
<tr><td class="lcell" colspan="8"><?=gettext('No virtual machines found.');?></td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($vms as $v): ?>
|
||||
<?php
|
||||
$n = (string)$v['name'];
|
||||
$isRunning = ($v['state'] ?? '') === 'running';
|
||||
$jsName = htmlspecialchars(json_encode($n), ENT_QUOTES);
|
||||
?>
|
||||
<tr>
|
||||
<td class="lcell"><strong><?=vmm_h((string)$v['name']);?></strong></td>
|
||||
<td class="lcell"><strong><?=vmm_h($n);?></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>
|
||||
@@ -106,7 +104,15 @@ include 'fbegin.inc';
|
||||
<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>
|
||||
<span class="vmm-actions">
|
||||
<?php if ($isRunning): ?>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Stop');?>" onclick='vmmConfirmRun("stop", <?=$jsName;?>, "Stop <?=vmm_h($n);?>?")'/>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Restart');?>" onclick='vmmConfirmRun("restart", <?=$jsName;?>, "Restart <?=vmm_h($n);?>?")'/>
|
||||
<?php else: ?>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Start');?>" onclick='vmmRun("start", <?=$jsName;?>)'/>
|
||||
<?php endif; ?>
|
||||
<a class="formbtn" href="vmmngr_vm.php?name=<?=urlencode($n);?>"><?=gettext('Details');?></a>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -114,12 +120,51 @@ include 'fbegin.inc';
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<table class="area_data_selection" style="width:100%;border-collapse:collapse;">
|
||||
<colgroup>
|
||||
<col style="width:26%">
|
||||
<col style="width:10%">
|
||||
<col style="width:14%">
|
||||
<col style="width:10%">
|
||||
<col style="width:40%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<?php html_separator2(); html_titleline2(gettext('Recent jobs'), 5); ?>
|
||||
<tr>
|
||||
<th class="lhell"><?=gettext('Job');?></th>
|
||||
<th class="lhell"><?=gettext('Action');?></th>
|
||||
<th class="lhell"><?=gettext('VM');?></th>
|
||||
<th class="lhell"><?=gettext('State');?></th>
|
||||
<th class="lhebl"><?=gettext('Started');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ($jobs === []): ?>
|
||||
<tr><td class="lcell" colspan="5"><?=gettext('No jobs yet.');?></td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($jobs as $j): ?>
|
||||
<tr>
|
||||
<td class="lcell vmm-mono"><a href="vmmngr_jobs.php?id=<?=urlencode((string)$j['id']);?>"><?=vmm_h((string)$j['id']);?></a></td>
|
||||
<td class="lcell"><?=vmm_h((string)$j['verb']);?></td>
|
||||
<td class="lcell"><?=vmm_h((string)$j['vm']);?></td>
|
||||
<td class="lcell">
|
||||
<span class="<?=($j['state'] ?? '') === 'failed' ? 'vmm-err' : 'vmm-ok';?>"><?=vmm_h((string)$j['state']);?></span>
|
||||
</td>
|
||||
<td class="lcebl vmm-mono"><?=!empty($j['started']) ? date('Y-m-d H:i:s', (int)$j['started']) : '—';?></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.')
|
||||
'status',
|
||||
gettext('Status'),
|
||||
gettext('0.2.0: start/stop/restart/reset/poweroff/destroy run as jobs. Every action is locked per VM and logged; long operations continue if you close the browser.')
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
+44
-5
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
* vmmngr_api.php - read-only JSON endpoint.
|
||||
* vmmngr_api.php - JSON endpoint for the VM Manager GUI.
|
||||
*
|
||||
* GET/POST ?action=list|info|selfcheck
|
||||
* Every request requires an authenticated admin session (XigmaNAS auth.inc).
|
||||
* GET ?action=list|info|selfcheck|job|jobs
|
||||
* POST ?action=action (verb, vm, confirm) - mutations are POST only
|
||||
* POST ?action=cancel (id)
|
||||
*
|
||||
* Requires an authenticated XigmaNAS session with admin rights.
|
||||
*/
|
||||
|
||||
require_once 'vmmngr-boot.inc';
|
||||
@@ -12,8 +15,11 @@ if (!session::is_admin()) {
|
||||
vmm_json(['ok' => false, 'error' => 'forbidden'], 403);
|
||||
}
|
||||
|
||||
$method = strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET'));
|
||||
$action = (string)($_REQUEST['action'] ?? '');
|
||||
$name = (string)($_REQUEST['name'] ?? '');
|
||||
$name = (string)($_REQUEST['vm'] ?? $_REQUEST['name'] ?? '');
|
||||
$confirm = (string)($_REQUEST['confirm'] ?? '');
|
||||
$id = (string)($_REQUEST['id'] ?? '');
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
@@ -33,10 +39,43 @@ switch ($action) {
|
||||
// no break
|
||||
|
||||
case 'selfcheck':
|
||||
case '':
|
||||
vmm_json(['ok' => true, 'selfcheck' => vmm_selfcheck()]);
|
||||
// no break
|
||||
|
||||
case 'action':
|
||||
if ($method !== 'POST') {
|
||||
vmm_json(['ok' => false, 'error' => 'POST required'], 405);
|
||||
}
|
||||
$verb = (string)($_POST['verb'] ?? '');
|
||||
$check = vmm_action_check($verb, $name, $confirm);
|
||||
if (!$check['ok']) {
|
||||
vmm_json(['ok' => false, 'error' => $check['error']], 409);
|
||||
}
|
||||
$job = vmm_job_new($verb, $name);
|
||||
vmm_json(['ok' => true, 'job' => $job], 202);
|
||||
// no break
|
||||
|
||||
case 'cancel':
|
||||
if ($method !== 'POST') {
|
||||
vmm_json(['ok' => false, 'error' => 'POST required'], 405);
|
||||
}
|
||||
$res = vmm_job_cancel($id);
|
||||
vmm_json($res, $res['ok'] ? 200 : 409);
|
||||
// no break
|
||||
|
||||
case 'job':
|
||||
$job = vmm_job_get($id);
|
||||
if ($job === null) {
|
||||
vmm_json(['ok' => false, 'error' => 'job not found'], 404);
|
||||
}
|
||||
$job['log'] = vmm_job_log($id);
|
||||
vmm_json(['ok' => true, 'job' => $job]);
|
||||
// no break
|
||||
|
||||
case 'jobs':
|
||||
vmm_json(['ok' => true, 'jobs' => vmm_job_list(30, $name)]);
|
||||
// no break
|
||||
|
||||
default:
|
||||
vmm_json(['ok' => false, 'error' => 'unknown action'], 400);
|
||||
}
|
||||
@@ -11,12 +11,7 @@ $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>
|
||||
<?php vmm_css(); ?>
|
||||
|
||||
<form action="vmmngr_config.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||
|
||||
@@ -38,6 +33,8 @@ include 'fbegin.inc';
|
||||
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>
|
||||
<?php $b = vmm_ram_budget(); ?>
|
||||
<tr><td class="celltag"><?=gettext('RAM budget');?></td><td class="celldata"><?=vmm_human_bytes(vmm_ram_used());?> <?=gettext('in use');?> · <?=gettext('limit');?> <?=vmm_human_bytes($b['limit']);?> (<?=$b['pct'];?>% <?=gettext('of');?> <?=vmm_human_bytes($b['total']);?>)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/*
|
||||
* vmmngr_jobs.php - job history and log viewer (0.2.0)
|
||||
*/
|
||||
|
||||
require_once 'vmmngr-boot.inc';
|
||||
|
||||
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Jobs')];
|
||||
$id = (string)($_GET['id'] ?? '');
|
||||
$job = $id !== '' ? vmm_job_get($id) : null;
|
||||
$jobs = vmm_job_list(50);
|
||||
|
||||
include 'fbegin.inc';
|
||||
vmm_css();
|
||||
?>
|
||||
|
||||
<form action="vmmngr_jobs.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||
|
||||
<?php if ($job !== null): ?>
|
||||
<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('Job'), $job['id']), 2); ?>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td class="celltag"><?=gettext('Action');?></td><td class="celldata"><?=vmm_h((string)$job['verb']);?></td></tr>
|
||||
<tr><td class="celltag"><?=gettext('VM');?></td><td class="celldata"><a href="vmmngr_vm.php?name=<?=urlencode((string)$job['vm']);?>"><?=vmm_h((string)$job['vm']);?></a></td></tr>
|
||||
<tr><td class="celltag"><?=gettext('State');?></td><td class="celldata"><span class="<?=($job['state'] ?? '') === 'failed' ? 'vmm-err' : 'vmm-ok';?>"><?=vmm_h((string)$job['state']);?></span><?php if ($job['error'] ?? ''): ?> — <?=vmm_h((string)$job['error']);?><?php endif; ?></td></tr>
|
||||
<tr><td class="celltag"><?=gettext('Return code');?></td><td class="celldata vmm-mono"><?=vmm_h((string)($job['rc'] ?? '—'));?></td></tr>
|
||||
<tr><td class="celltag"><?=gettext('Requested by');?></td><td class="celldata vmm-mono"><?=vmm_h((string)($job['by'] ?? ''));?></td></tr>
|
||||
<tr><td class="celltag"><?=gettext('Timing');?></td><td class="celldata vmm-mono">
|
||||
<?=!empty($job['created']) ? date('Y-m-d H:i:s', (int)$job['created']) : '—';?>
|
||||
<?php if (!empty($job['started'])): ?> → <?=date('H:i:s', (int)$job['started']);?><?php endif; ?>
|
||||
<?php if (!empty($job['ended'])): ?> → <?=date('H:i:s', (int)$job['ended']);?> (<?=(int)$job['ended'] - (int)($job['started'] ?? $job['ended']);?>s)<?php endif; ?>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('Log');?></td>
|
||||
<td class="celldata">
|
||||
<pre class="vmm-raw vmm-mono"><?=vmm_h(vmm_job_log((string)$job['id']));?></pre>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<?php endif; ?>
|
||||
|
||||
<table class="area_data_selection" style="width:100%;border-collapse:collapse;">
|
||||
<colgroup>
|
||||
<col style="width:26%">
|
||||
<col style="width:10%">
|
||||
<col style="width:14%">
|
||||
<col style="width:10%">
|
||||
<col style="width:10%">
|
||||
<col style="width:30%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<?php html_separator2(); html_titleline2(gettext('All jobs'), 6); ?>
|
||||
<tr>
|
||||
<th class="lhell"><?=gettext('Job');?></th>
|
||||
<th class="lhell"><?=gettext('Action');?></th>
|
||||
<th class="lhell"><?=gettext('VM');?></th>
|
||||
<th class="lhell"><?=gettext('State');?></th>
|
||||
<th class="lhell">RC</th>
|
||||
<th class="lhebl"><?=gettext('Started');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ($jobs === []): ?>
|
||||
<tr><td class="lcell" colspan="6"><?=gettext('No jobs yet.');?></td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($jobs as $j): ?>
|
||||
<tr>
|
||||
<td class="lcell vmm-mono"><a href="vmmngr_jobs.php?id=<?=urlencode((string)$j['id']);?>"><?=vmm_h((string)$j['id']);?></a></td>
|
||||
<td class="lcell"><?=vmm_h((string)$j['verb']);?></td>
|
||||
<td class="lcell"><?=vmm_h((string)$j['vm']);?></td>
|
||||
<td class="lcell"><span class="<?=($j['state'] ?? '') === 'failed' ? 'vmm-err' : 'vmm-ok';?>"><?=vmm_h((string)$j['state']);?></span></td>
|
||||
<td class="lcell vmm-mono"><?=vmm_h((string)($j['rc'] ?? '—'));?></td>
|
||||
<td class="lcebl vmm-mono"><?=!empty($j['started']) ? date('Y-m-d H:i:s', (int)$j['started']) : '—';?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</td></tr></tbody></table></form>
|
||||
<?php include 'fend.inc'; ?>
|
||||
+56
-16
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* vmmngr_vm.php - VM detail view (read-only preview 0.1.0)
|
||||
* vmmngr_vm.php - VM detail view with actions (0.2.0)
|
||||
*/
|
||||
|
||||
require_once 'vmmngr-boot.inc';
|
||||
@@ -13,18 +13,11 @@ if ($name === '' || !vmm_valid_name($name)) {
|
||||
|
||||
$info = vmm_info($name);
|
||||
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), $name];
|
||||
$jobs = vmm_job_list(10, $name);
|
||||
|
||||
include 'fbegin.inc';
|
||||
vmm_css();
|
||||
?>
|
||||
<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">
|
||||
|
||||
@@ -34,6 +27,8 @@ include 'fbegin.inc';
|
||||
<?php
|
||||
$g = $info['general'] ?? [];
|
||||
$state = vmm_state_from_string((string)($g['state'] ?? ''));
|
||||
$isRunning = $state['state'] === 'running';
|
||||
$jsName = htmlspecialchars(json_encode($name), ENT_QUOTES);
|
||||
?>
|
||||
|
||||
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
|
||||
@@ -53,10 +48,27 @@ include 'fbegin.inc';
|
||||
<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>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('Actions');?></td>
|
||||
<td class="celldata">
|
||||
<span class="vmm-actions">
|
||||
<?php if ($isRunning): ?>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Stop');?>" onclick='vmmConfirmRun("stop", <?=$jsName;?>, "Stop <?=vmm_h($name);?>?")'/>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Restart');?>" onclick='vmmConfirmRun("restart", <?=$jsName;?>, "Restart <?=vmm_h($name);?>?")'/>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Power off');?>" onclick='vmmConfirmRun("poweroff", <?=$jsName;?>, "Force power off <?=vmm_h($name);?>? Unsaved data in the guest may be lost.")'/>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Reset');?>" onclick='vmmConfirmRun("reset", <?=$jsName;?>, "Hard reset <?=vmm_h($name);?>?")'/>
|
||||
<?php else: ?>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Start');?>" onclick='vmmRun("start", <?=$jsName;?>)'/>
|
||||
<input type="button" class="formbtn" value="<?=gettext('Destroy');?>" onclick='vmmDestroy(<?=$jsName;?>)'/>
|
||||
<?php endif; ?>
|
||||
<a class="formbtn" href="vmmngr.php"><?=gettext('Back');?></a>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
<div id="vmm-job" class="vmm-job"></div>
|
||||
|
||||
<?php foreach (($info['sections'] ?? []) as $type => $blocks): ?>
|
||||
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
|
||||
@@ -90,15 +102,43 @@ include 'fbegin.inc';
|
||||
<br />
|
||||
<?php endforeach; ?>
|
||||
|
||||
<details>
|
||||
<table class="area_data_selection" style="width:100%;border-collapse:collapse;">
|
||||
<colgroup>
|
||||
<col style="width:30%">
|
||||
<col style="width:12%">
|
||||
<col style="width:12%">
|
||||
<col style="width:46%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<?php html_separator2(); html_titleline2(gettext('Jobs for this VM'), 4); ?>
|
||||
<tr>
|
||||
<th class="lhell"><?=gettext('Job');?></th>
|
||||
<th class="lhell"><?=gettext('Action');?></th>
|
||||
<th class="lhell"><?=gettext('State');?></th>
|
||||
<th class="lhebl"><?=gettext('Started');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ($jobs === []): ?>
|
||||
<tr><td class="lcell" colspan="4"><?=gettext('No jobs yet.');?></td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($jobs as $j): ?>
|
||||
<tr>
|
||||
<td class="lcell vmm-mono"><a href="vmmngr_jobs.php?id=<?=urlencode((string)$j['id']);?>"><?=vmm_h((string)$j['id']);?></a></td>
|
||||
<td class="lcell"><?=vmm_h((string)$j['verb']);?></td>
|
||||
<td class="lcell"><span class="<?=($j['state'] ?? '') === 'failed' ? 'vmm-err' : 'vmm-ok';?>"><?=vmm_h((string)$j['state']);?></span></td>
|
||||
<td class="lcebl vmm-mono"><?=!empty($j['started']) ? date('Y-m-d H:i:s', (int)$j['started']) : '—';?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<details style="margin-top:12px;">
|
||||
<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'; ?>
|
||||
Reference in new issue
Block a user