1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00
webvirtcloud/instances/templates/instance.html
catborise d5cc696d73 feat(instances): the VM page shows the VM's screen
A running or paused VM with a VNC or SPICE console shows its screen
beside the summary (virDomainScreenshot, PNG), read again every 10 s
while the page is in view; clicking it opens the console. It is for
those who may open the console (the screen shows what the console
does) and is left out while there is none to show, also on a host whose
libvirt gives PPM. The VM list does not read screens: one a VM would
cost too much.
2026-11-26 14:21:36 +03:00

184 lines
12 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% load common_tags %}
{% load vm_states %}
{% load i18n %}
{% load operations %}
{% load bootstrap_icons %}
{% block title %}{% trans "Instance" %} - {{ instance.name }}{% endblock %}
{% block style %}
{% if request.user.is_superuser %}<link href="{% static 'css/tom-select.bootstrap5.min.css' %}" rel="stylesheet">{% endif %}
{% endblock style %}
{% block page_header %}{% endblock page_header %}{# the card below has the heading #}
{% block content %}
{# the VM at a glance in one card: who and where it is, what it has, and its sections as the card's footer #}
<section class="card mb-3" aria-labelledby="vm-name" id="vm-summary" data-status="{{ instance.status }}" data-reason="{{ instance.state_and_reason.1 }}"
data-status-url="{% url 'instances:status' instance.id %}" data-osinfo-url="{% url 'instances:osinfo' instance.id %}"
data-opens-on="{% if instance.is_template and can_clone %}#clone{% endif %}"
data-random-mac-url="{% url 'instances:random_mac_address' %}"
{% if can_open_console and vdi_reachable %}data-vdi-url="{% url 'vdi_url' compute.id instance.name %}"{% endif %}>
<div class="card-body p-3 d-flex flex-wrap flex-md-nowrap gap-3">
<div class="flex-grow-1" style="min-width: 0;">
<div class="d-flex flex-wrap justify-content-between align-items-start gap-2">
<div style="min-width: 0;">
<div class="d-flex flex-wrap align-items-center gap-2">
<h1 class="h4 mb-0 text-break" id="vm-name">{{ instance.name }}</h1>
{% vm_state instance.status as state %}
<span class="badge text-bg-{{ state.1 }}">{{ state.0 }}</span>
{% if instance.is_template %}<span class="badge text-bg-light border">{% trans "Template" %}</span>{% endif %}
{% include 'common/tag_badges.html' with tags=instance.tags.all %}
</div>
{% if instance.title %}<p class="text-body-secondary mb-1">{{ instance.title }}</p>{% endif %}
{% include 'instances/host_link.html' %}
</div>
<div class="d-flex gap-2">
{% if instance.is_template and can_clone %}
<button type="button" class="btn btn-sm btn-primary" id="clone-button">{% bs_icon 'copy' %} {% trans "Clone" %}</button>
{% endif %}
{% if instance.guest_agent_ready %}
<button type="button" class="btn btn-sm btn-outline-secondary" id="os-details-button">{% bs_icon 'info-circle' %} {% trans "OS details" %}</button>
{% endif %}
<a class="btn btn-sm btn-outline-secondary" href="{% url 'instances:instance' instance.id %}">{% bs_icon 'arrow-clockwise' %} {% trans "Refresh" %}</a>
</div>
</div>
{# shown by instance_status.js while the VM's state cannot be read #}
<div class="alert alert-warning small py-2 mt-2 mb-0" id="vm-host-lost" role="status" hidden>{% trans "This page could not be refreshed: its state and figures may be out of date." %}</div>
{# a VM a fault stopped or paused says why; a full storage pauses it until there is space #}
{% if instance.state_reason %}
<div class="alert alert-danger small py-2 mt-2 mb-0" role="status">
<strong>{{ instance.state_reason }}</strong>
{% for error in instance.disk_error_texts %}<div>{{ error }}</div>{% endfor %}
{% if instance.disk_full %}
<div>{% if request.user.is_superuser %}{% trans "Free space on its storage, then resume it." %}{% else %}{% trans "An administrator has to free space on its storage and resume it." %}{% endif %}</div>
{% endif %}
</div>
{% endif %}
{% if not instance.is_template %}
<div class="d-flex flex-wrap column-gap-3 row-gap-1 small mt-2">
{% if not instance.guest_agent %}
<span>{% bs_icon 'dash-circle' %} {% trans "Guest agent off" %}</span>
{% elif instance.guest_agent_ready %}
<span><span class="text-success">{% bs_icon 'check-circle' %}</span> {% trans "Guest agent connected" %}</span>
{% else %}
<span><span class="text-warning">{% bs_icon 'exclamation-circle' %}</span> {% trans "Guest agent not connected" %}</span>
{% endif %}
<span>{% bs_icon 'camera' %} {% blocktrans count counter=instance.snapshots|length %}{{ counter }} snapshot{% plural %}{{ counter }} snapshots{% endblocktrans %}</span>
</div>
{% endif %}
<dl class="row g-2 small mb-0 mt-1">
<div class="col-auto col-lg-2">
<dt class="fw-normal text-body-secondary d-inline d-lg-block">{% trans "CPU" %}</dt>
<dd class="mb-0 d-inline d-lg-block">{% firstof instance.cur_vcpu instance.vcpu %} {% trans "of" %} {{ instance.vcpu }} {% trans "vCPU" %}</dd>
</div>
<div class="col-auto col-lg-2">
<dt class="fw-normal text-body-secondary d-inline d-lg-block">{% trans "Memory" %}</dt>
<dd class="mb-0 d-inline d-lg-block">{{ instance.cur_memory }} MiB</dd>
</div>
<div class="col-auto col-lg-5">
<dt class="fw-normal text-body-secondary d-inline d-lg-block">{% trans "Disks" %}</dt>
<dd class="mb-0 d-inline d-lg-block">{% for disk in instance.disks %}{{ disk.dev }} {{ disk.size|binary_size }}{% if not forloop.last %} · {% endif %}{% empty %}{% trans "None" %}{% endfor %}</dd>
</div>
{% if not instance.is_template %}
<div class="col-auto col-lg-3">
<dt class="fw-normal text-body-secondary d-inline d-lg-block">{% trans "IPv4" %}</dt>
<dd class="mb-0 d-inline d-lg-block font-monospace" data-address-mac="{% for nic in instance.networks %}{{ nic.mac }} {% endfor %}" data-address-family="ipv4" data-empty="—">{% trans "Reading…" %}</dd>
</div>
{% endif %}
</dl>
</div>
{% if show_screen %}
{# the VM's screen, read by instance_page.js every few seconds and shown once one has come; opens the console where it can #}
{% if screen_opens_console %}
<button type="button" class="vm-screen" id="vm-screen" hidden data-url="{% url 'console' compute.id instance.uuid %}"
data-window="console-{{ instance.uuid }}" data-screen-url="{% url 'instances:screen' instance.id %}"
title="{% trans "Open console" %}">
<img alt="{% blocktrans with name=instance.name %}Screen of {{ name }}{% endblocktrans %}">
</button>
{% else %}
<div class="vm-screen" id="vm-screen" hidden data-screen-url="{% url 'instances:screen' instance.id %}">
<img alt="{% blocktrans with name=instance.name %}Screen of {{ name }}{% endblocktrans %}">
</div>
{% endif %}
{% endif %}
</div>
<div class="card-footer p-1">
{# p-1 inside the scroller keeps the focus ring from being clipped #}
<ul class="nav nav-pills nav-fill flex-nowrap overflow-x-auto gap-1 p-1 small" id="navbtn" role="tablist" aria-label="{% trans "Instance actions" %}">
{# a template is cloned, not run: no power, access, snapshots or stats #}
{% if not instance.is_template %}
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2 active" id="power-tab" aria-controls="power" data-bs-toggle="pill" data-bs-target="#power" type="button" role="tab" aria-selected="true">{% bs_icon 'power' %} {% trans "Power" %}</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2" id="access-tab" aria-controls="access" data-bs-toggle="pill" data-bs-target="#access" type="button" role="tab" aria-selected="false">{% bs_icon 'lock' %} {% trans "Access" %}</button>
</li>
{% endif %}
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2" id="resize-tab" aria-controls="resize" data-bs-toggle="pill" data-bs-target="#resize" type="button" role="tab" aria-selected="false">{% bs_icon 'arrows-angle-expand' %} {% trans "Resize" %}</button>
</li>
{% if can_snapshot and not instance.is_template %}
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2" id="snapshots-tab" aria-controls="snapshots" data-bs-toggle="pill" data-bs-target="#snapshots" type="button" role="tab" aria-selected="false">{% bs_icon 'camera' %} {% trans "Snapshot" %}</button>
</li>
{% endif %}
{% if show_settings %}
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2" id="settings-tab" aria-controls="settings" data-bs-toggle="pill" data-bs-target="#settings" type="button" role="tab" aria-selected="false">{% bs_icon 'gear-wide-connected' %} {% trans "Settings" %}</button>
</li>
{% endif %}
{% if not instance.is_template %}
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2" id="graphics-tab" aria-controls="graphics" data-bs-toggle="pill" data-bs-target="#graphics" type="button" role="tab" aria-selected="false">{% bs_icon 'bar-chart-line' %} {% trans "Stats" %}</button>
</li>
{% endif %}
{% if backups %}
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2" id="backups-tab" aria-controls="backups" data-bs-toggle="pill" data-bs-target="#backups" type="button" role="tab" aria-selected="false">{% bs_icon 'archive' %} {% trans "Backups" %}</button>
</li>
{% endif %}
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap px-2" id="undefine-tab" aria-controls="undefine" data-bs-toggle="pill" data-bs-target="#undefine" type="button" role="tab" aria-selected="false">{% bs_icon 'trash' %} {% trans "Destroy" %}</button>
</li>
</ul>
</div>
</section>
<div id="job-panel" aria-live="polite"></div>
<div id="mainTabMenu">
<!-- Tab panes -->
<div class="tab-content" id=mainTabMenuContent>
{% if not instance.is_template %}
{% include 'instances/power_tab.html' %}
{% include 'instances/access_tab.html' %}
{% endif %}
{% include 'instances/resize_tab.html' %}
{% if can_snapshot and not instance.is_template %}{% include 'instances/snapshots_tab.html' %}{% endif %}
{% if show_settings %}{% include 'instances/settings_tab.html' %}{% endif %}
{% if not instance.is_template %}{% include 'instances/stats_tab.html' %}{% endif %}
{% if backups %}{% include 'vmbackups/vm_tab.html' %}{% endif %}
{% include 'instances/destroy_tab.html' %}
</div>
</div>
{% endblock %}
{% block script %}
{% if request.user.is_superuser %}{# the add-owner user list and the tags #}
<script src="{% static 'js/tom-select.complete.min.js' %}"></script>
<script src="{% static 'js/searchable_select.js' %}"></script>
{% endif %}
<script src="{% static 'js/ace/ace.js' %}" type="text/javascript" charset="utf-8"></script>
<script src="{% static 'js/xml_editor.js' %}"></script>
<script src="{% static 'js/chart.umd.min.js' %}"></script>
<script src="{% static 'js/charts.js' %}"></script>
<script src="{% static 'js/poll.js' %}"></script>
{% if not instance.is_template %}<script src="{% static 'js/instance_stats.js' %}"></script>{% endif %}
<script src="{% static 'js/instance_status.js' %}"></script>
<script src="{% static 'js/vm_addresses.js' %}" data-url="{% url 'instances:nic_addresses' instance.id %}"></script>
{% job_panel_script job_resource %}
<script src="{% static 'js/instance_tabs.js' %}"></script>
<script src="{% static 'js/instance_page.js' %}"></script>
{% endblock %}