Files
vmmngr/gui/vmmngr_vm.php
T

146 lines
7.6 KiB
PHP

<?php
/*
* vmmngr_vm.php - VM detail view with actions (0.2.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];
$jobs = vmm_job_list(10, $name);
include 'fbegin.inc';
vmm_css();
?>
<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'] ?? ''));
$isRunning = $state['state'] === 'running';
$jsName = htmlspecialchars(json_encode($name), ENT_QUOTES);
?>
<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>
<tr>
<td class="celltag"><?=gettext('Actions');?></td>
<td class="celldata">
<span class="vmm-actions">
<?php if ($isRunning): ?>
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="stop:<?=vmm_h($name);?>" onclick="return confirm('Stop <?=vmm_h($name);?>?')"><?=gettext('Stop');?></button>
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="restart:<?=vmm_h($name);?>" onclick="return confirm('Restart <?=vmm_h($name);?>?')"><?=gettext('Restart');?></button>
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="poweroff:<?=vmm_h($name);?>" onclick="return confirm('Force power off <?=vmm_h($name);?>? Unsaved guest data may be lost.')"><?=gettext('Power off');?></button>
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="reset:<?=vmm_h($name);?>" onclick="return confirm('Hard reset <?=vmm_h($name);?>?')"><?=gettext('Reset');?></button>
<?php else: ?>
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="start:<?=vmm_h($name);?>"><?=gettext('Start');?></button>
<input type="text" name="confirm" value="" placeholder="<?=gettext('type name to destroy');?>" style="width:150px"/>
<button type="submit" class="formbtn" formaction="vmmngr_do.php" formmethod="post" name="act" value="destroy:<?=vmm_h($name);?>" onclick="return confirm('Destroy <?=vmm_h($name);?>? All disks and snapshots are deleted.')"><?=gettext('Destroy');?></button>
<?php endif; ?>
<a class="formbtn" href="vmmngr.php"><?=gettext('Back');?></a>
</span>
</td>
</tr>
</tbody>
</table>
<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;">
<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; ?>
<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; ?>
</td></tr></tbody></table></form>
<?php include 'fend.inc'; ?>