mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
feat(instances): a new VM is made on one form in three steps
The create page had three tabs (flavor, custom, template), each with its own copy of the same create form; every flavor rendered one more copy in a dialog, and fixes had to be made in each copy. All of them posted the same form to the same job, differing only in where the disk comes from. The page is now one form in sections: name and size, disk, networks and an Advanced section. The disk section offers three sources as radio cards (a new disk, existing volumes, a copy of a template); only the chosen source's fields are shown, and the others are disabled, so they are neither sent nor validated. A template's copy goes into the template's pool unless another is picked. Flavors are presets that fill vCPU, memory and disk size and pick a new disk; they are added and deleted in a dialog outside the form. Every source uses the per-interface network rows, so a new disk no longer requires a MAC: libvirt gives an interface without one its address, as it did for the other sources. A refused form comes back with its source, volumes, template and networks, and the focus on its first error. Without a storage pool or a network the page shows why instead of the form, and a host that cannot be read is a message, not a 500. The host dialog and the machine page share the form's look: hosts are rows with their CPU and memory use, the machine page is a card with Cancel/Next and the XML way is a collapsible section. All three steps show the same step indicator, done steps linking back. The create job refuses more than one disk source (the page sends one; a crafted request could send two, and the job would have used the first). A field with help text is described by its help and its error. Frontend review fixes: the presets and the disclosure buttons show a focus ring for keyboard users; a disclosure spans its card and its chevron turns while open; a preset says it picks a new disk; numeric fields bring a numeric keyboard and MAC fields no autocorrection; the machine page's Next waits for a machine type. Tom Select's control keeps the text colour of the select it replaces: its own fixed colour made typed text invisible on dark Bootswatch themes, on every page that uses it.
This commit is contained in:
parent
c1744402b4
commit
ab5ed59ea1
17 changed files with 991 additions and 1417 deletions
|
|
@ -43,10 +43,6 @@
|
|||
<script src="{% static 'js/filter-table.js' %}"></script>
|
||||
{% if request.user.is_superuser %}
|
||||
<script>
|
||||
function goto_compute(compute) {
|
||||
window.location.href = "{% url 'instances:create_instance_select_type' 1 %}".replace(1, compute);
|
||||
}
|
||||
|
||||
// The new-VM dialog's CPU bars: each compute's load over one second,
|
||||
// read when the dialog opens, two computes at a time (each read holds
|
||||
// a worker for that second). Answers of an earlier opening are ignored.
|
||||
|
|
@ -54,12 +50,12 @@
|
|||
let cpuOpening = 0, cpuQueue = [], cpuReading = 0;
|
||||
|
||||
function setCpuUsage(cell, percent, text) {
|
||||
const bar = cell.querySelector(".progress-bar");
|
||||
bar.style.width = (percent || 0) + "%";
|
||||
const meter = cell.querySelector(".progress");
|
||||
cell.querySelector(".progress-bar").style.width = (percent || 0) + "%";
|
||||
if (percent === null) {
|
||||
bar.removeAttribute("aria-valuenow");
|
||||
meter.removeAttribute("aria-valuenow");
|
||||
} else {
|
||||
bar.setAttribute("aria-valuenow", percent);
|
||||
meter.setAttribute("aria-valuenow", percent);
|
||||
}
|
||||
cell.querySelector(".cpu-usage-value").textContent = text;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
{% load i18n %}
|
||||
{% load django_bootstrap5 %}
|
||||
{% load bootstrap_icons %}
|
||||
{% if request.user.is_superuser %}
|
||||
<button href="#addFlavor" type="button" class="btn btn-success btn-header float-end" title="{% trans "Add New Flavor" %}" data-bs-toggle="modal">
|
||||
<span aria-hidden="true">{% bs_icon 'plus'%} </span>
|
||||
</button>
|
||||
|
||||
<!-- Modal Flavor -->
|
||||
<div class="modal fade" id="addFlavor" tabindex="-1" role="dialog" aria-labelledby="addFlavorLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">{% trans "Add New Flavor" %}</h4>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" role="form" action="{% url 'instances:flavor_create' %}" id="flavor-create-form">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form flavor_form layout='horizontal' %}
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||
{% trans "Close" %}
|
||||
</button>
|
||||
<button form="flavor-create-form" type="submit" class="btn btn-primary">
|
||||
{% trans "Add" %}
|
||||
</button>
|
||||
</div>
|
||||
</div> <!-- /.modal-content -->
|
||||
</div> <!-- /.modal-dialog -->
|
||||
</div> <!-- /.modal -->
|
||||
{% endif %}
|
||||
|
|
@ -4,65 +4,51 @@
|
|||
<span aria-hidden="true">{% bs_icon 'plus-circle-fill'%} </span>
|
||||
</a>
|
||||
|
||||
<!-- Modal pool -->
|
||||
<div class="modal fade" id="AddInstance" tabindex="-1" role="dialog" aria-labelledby="AddInstanceModal" aria-hidden="true">
|
||||
<div class="modal fade" id="AddInstance" tabindex="-1" aria-labelledby="AddInstanceTitle" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-scrollable modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">{% trans "Choose a compute for new instance" %}</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
<h2 class="modal-title h5" id="AddInstanceTitle">{% trans "New instance" %}</h2>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans "Close" %}"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" aria-label="Select compute for instance create form">{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr style="cursor:default;pointer-events:none">
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th>{% trans "VCPU" %}
|
||||
<th>{% trans "CPU Usage" %}</th>
|
||||
<th>{% trans "Memory" %}</th>
|
||||
<th>{% trans "Mem Usage" %}</th>
|
||||
<th>{% trans "Action" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for compute in computes %}
|
||||
{% if compute.status is True %}
|
||||
<tr style="text-decoration: none">
|
||||
<td>{{ compute.name }}</td>
|
||||
<td>{{ compute.cpu_count }}</td>
|
||||
<td class="cpu-usage" data-url="{% url 'compute_graph' compute.id %}">
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-primary" role="progressbar" aria-label="{% trans "Mem Usage" %}" style="width: 0%"
|
||||
aria-valuemin="0" aria-valuemax="100" aria-label="{% trans "CPU Usage" %}">
|
||||
</div>
|
||||
</div>
|
||||
<small class="cpu-usage-value"></small>
|
||||
</td>
|
||||
<td>{{ compute.ram_size|filesizeformat }}</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-primary" role="progressbar" aria-label="{% trans "Mem Usage" %}" style="width: {{ compute.ram_usage }}%"
|
||||
aria-valuenow="{{ compute.ram_usage }}" aria-valuemin="0" aria-valuemax="100">{{ compute.ram_usage }}%
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="col-1">
|
||||
<button class="btn btn-success btn-sm" type="button" onclick="goto_compute('{{ compute.id }}');">
|
||||
{% trans "Choose" %}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% include "create_steps.html" with step=1 %}
|
||||
<div class="text-body-secondary mb-3">{% trans "Choose the host the VM runs on." %}</div>
|
||||
<div class="list-group">
|
||||
{% for compute in computes %}
|
||||
{% if compute.status is True %}
|
||||
<a class="list-group-item list-group-item-action py-3" href="{% url 'instances:create_instance_select_type' compute.id %}">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-12 col-md-3 fw-semibold">{{ compute.name }}</div>
|
||||
<div class="col-6 col-md-4">
|
||||
<div class="small text-body-secondary">{% trans "CPU" %} · {{ compute.cpu_count }} vCPU</div>
|
||||
<div class="cpu-usage d-flex align-items-center gap-2" data-url="{% url 'compute_graph' compute.id %}">
|
||||
<div class="progress flex-grow-1" role="progressbar" aria-label="{% blocktrans with name=compute.name %}CPU usage of {{ name }}{% endblocktrans %}"
|
||||
aria-valuemin="0" aria-valuemax="100">
|
||||
<div class="progress-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
<small class="cpu-usage-value"></small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 col-md-4">
|
||||
<div class="small text-body-secondary">{% trans "Memory" %} · {{ compute.ram_size|filesizeformat }}</div>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<div class="progress flex-grow-1" role="progressbar" aria-label="{% blocktrans with name=compute.name %}Memory usage of {{ name }}{% endblocktrans %}"
|
||||
aria-valuenow="{{ compute.ram_usage }}" aria-valuemin="0" aria-valuemax="100">
|
||||
<div class="progress-bar" style="width: {{ compute.ram_usage }}%"></div>
|
||||
</div>
|
||||
<small>{{ compute.ram_usage }}%</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-1 d-none d-md-block text-end" aria-hidden="true">{% bs_icon 'chevron-right' %}</div>
|
||||
</div>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% empty %}
|
||||
<p>{% trans "No compute is reachable." %}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- /.modal-content -->
|
||||
</div> <!-- /.modal-dialog -->
|
||||
</div> <!-- /.modal -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
{% load bootstrap_icons %}
|
||||
|
||||
{% block title %}{% trans "Create new instance" %} - {% trans "Select Type" %}{% endblock %}
|
||||
{% block title %}{% trans "Create new instance" %} - {% trans "Machine" %}{% endblock %}
|
||||
|
||||
{% block style %}
|
||||
<style>.create-vm { max-width: 56rem; }</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_heading%}
|
||||
{% blocktrans with host=compute.name %}New instance on {{ host }} {% endblocktrans %}
|
||||
|
|
@ -10,108 +15,88 @@
|
|||
|
||||
{% block content %}
|
||||
{% include 'pleasewaitdialog.html' %}
|
||||
<div class="create-vm mx-auto">
|
||||
{% include "create_steps.html" with step=2 %}
|
||||
|
||||
{% if form.errors %}
|
||||
{% for field in form %}
|
||||
{% for error in field.errors %}
|
||||
<div class="alert alert-danger">
|
||||
<strong>{{ field.label }}:</strong> <span>{{ error|escape }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% for error in form.non_field_errors %}
|
||||
<div class="alert alert-danger">
|
||||
<strong>{{ error|escape }}</strong>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div role="tabpanel">
|
||||
<!-- Nav tabs -->
|
||||
<ul class="nav nav-tabs" role="tablist" aria-label="Instance create method">
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#select_architecture" type="button" role="tab" aria-controls="select_architecture" aria-selected="true">
|
||||
{% trans "Architecture" %}
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#addFromXML" type="button" role="tab" aria-controls="addFromXML" aria-selected="false">
|
||||
{% trans "XML" %}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="select_architecture">
|
||||
<form method="post" role="form" aria-label="Select instance architecture form">{% csrf_token %}
|
||||
<div class="row">
|
||||
<label class="col-sm-3 col-form-label" for="select_archs">{% trans "Architecture" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select class="form-select" id="select_archs" name="archs" onchange="get_machine_types({{ compute_id }}, value);">
|
||||
{% for hpv in hypervisors %}
|
||||
<option value="{{ hpv }}" {% if hpv == default_arch %}selected{% endif %}>{{ hpv }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="col-sm-3 col-form-label" for="select_chipset">{% trans "Chipset" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select class="form-select" id="select_chipset" name="chipset">
|
||||
<!-- fill with script -->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="d-grid col-sm-6 offset-sm-3 mt-3">
|
||||
<button class="btn btn-primary" type="button" name="create_instance" onclick="goto_create()">
|
||||
{% trans "Next" %}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="clearfix"></div>
|
||||
<section class="card mb-3" aria-labelledby="machine-heading">
|
||||
<div class="card-body">
|
||||
<h2 class="h5 card-title" id="machine-heading">{% trans "Machine" %}</h2>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" for="select_archs">{% trans "Architecture" %}</label>
|
||||
<select class="form-select" id="select_archs" name="archs">
|
||||
{% for hpv in hypervisors %}
|
||||
<option value="{{ hpv }}"{% if hpv == default_arch %} selected{% endif %}>{{ hpv }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="addFromXML">
|
||||
<div>
|
||||
<form method="post" role="form" aria-label="Create instance with XML form">{% csrf_token %}
|
||||
<div class="col-sm-12 xmlheight">
|
||||
<input type="hidden" name="dom_xml"/>
|
||||
<textarea id="editor"></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary float-end" name="create_xml" onclick="showPleaseWaitDialog()">
|
||||
{% trans "Create" %}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" for="select_chipset">{% trans "Machine type" %}</label>
|
||||
<select class="form-select" id="select_chipset" name="chipset" aria-describedby="chipset_help"></select>
|
||||
<div id="chipset_help" class="form-text">{% trans "The host's machine types for this architecture." %}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="d-flex flex-wrap gap-2 justify-content-end mb-4">
|
||||
<a class="btn btn-link" href="{% url 'instances' compute.id %}">{% trans "Cancel" %}</a>
|
||||
<button class="btn btn-primary" type="button" id="next" disabled>{% trans "Next" %}</button>
|
||||
</div>
|
||||
|
||||
<section class="card mb-3" aria-labelledby="xml-heading">
|
||||
<div class="card-body">
|
||||
<h2 class="h5 card-title mb-0" id="xml-heading">
|
||||
<button class="btn p-0 border-0 text-body fw-medium w-100 text-start focus-ring disclosure" type="button" data-bs-toggle="collapse" data-bs-target="#from-xml"
|
||||
aria-expanded="false" aria-controls="from-xml">
|
||||
{% bs_icon 'chevron-down' %} {% trans "Or define it from XML" %}
|
||||
</button>
|
||||
</h2>
|
||||
<div class="collapse" id="from-xml">
|
||||
<form method="post" class="pt-3" aria-label="{% trans "Create instance from XML" %}">{% csrf_token %}
|
||||
<input type="hidden" name="dom_xml">
|
||||
<div class="xmlheight mb-3"><textarea id="editor" aria-label="{% trans "Domain XML" %}"></textarea></div>
|
||||
<div class="d-flex justify-content-end">
|
||||
<button type="submit" class="btn btn-primary" name="create_xml" onclick="showPleaseWaitDialog()">
|
||||
{% trans "Create VM" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block script %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
let arch = $("#select_archs").val();
|
||||
get_machine_types({{ compute_id }}, arch);
|
||||
});
|
||||
|
||||
function get_machine_types(compute_id, arch) {
|
||||
get_machine_type_url = "/computes/" + compute_id + "/archs/" + arch + "/machines";
|
||||
$.getJSON(get_machine_type_url, function (data) {
|
||||
$("#select_chipset").find('option').remove();
|
||||
$("#select_archs").val(arch);
|
||||
$.each(data['machines'], function(i, item) {
|
||||
$("#select_chipset").append(
|
||||
$("<option>").val(item).text(item).prop("selected", item == '{{ default_machine }}')
|
||||
);
|
||||
});
|
||||
// the machine types of the chosen architecture, the default one selected
|
||||
function load_machines(arch) {
|
||||
const next = document.querySelector("#next");
|
||||
next.disabled = true;
|
||||
$.getJSON("/computes/{{ compute_id }}/archs/" + encodeURIComponent(arch) + "/machines", function (data) {
|
||||
document.querySelector("#select_chipset").replaceChildren(...data['machines'].map(
|
||||
item => new Option(item, item, false, item === "{{ default_machine|escapejs }}")));
|
||||
next.disabled = !data['machines'].length;
|
||||
});
|
||||
}
|
||||
|
||||
// placeholders, not "x86_64"/"pc": an architecture such as ppc64 contains "pc"
|
||||
function create_url(arch, machine) {
|
||||
return "{% url 'instances:create_instance' compute.id '__arch__' '__machine__' %}"
|
||||
.replace("__arch__", encodeURIComponent(arch)).replace("__machine__", encodeURIComponent(machine));
|
||||
}
|
||||
|
||||
function goto_create() {
|
||||
window.location.href = create_url(document.querySelector("#select_archs").value,
|
||||
document.querySelector("#select_chipset").value);
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
const archs = document.querySelector("#select_archs");
|
||||
archs.addEventListener("change", () => load_machines(archs.value));
|
||||
document.querySelector("#next").addEventListener("click", goto_create);
|
||||
load_machines(archs.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script src="{% static "js/ace/ace.js" %}"></script>
|
||||
|
|
@ -123,21 +108,7 @@
|
|||
editor.getSession().on("change",function () {
|
||||
input.val(editor.getSession().getValue());
|
||||
})
|
||||
// the editor measures itself when its section is shown
|
||||
document.querySelector("#from-xml").addEventListener("shown.bs.collapse", () => editor.resize());
|
||||
</script>
|
||||
{% if request.user.is_superuser %}
|
||||
<script>
|
||||
function goto_create() {
|
||||
let compute = '{{ compute.id }}';
|
||||
let arch = $("#select_archs").val();
|
||||
let machine = $("#select_chipset").val();
|
||||
//create_machine_url = "/computes/" + compute + "/create/archs/" + arch + "/machines/" + machine;
|
||||
// placeholders, not "x86_64"/"pc": an arch such as ppc64 contains "pc"
|
||||
url = "{% url 'instances:create_instance' compute.id '__arch__' '__machine__' %}"
|
||||
.replace("__arch__", encodeURIComponent(arch))
|
||||
.replace("__machine__", encodeURIComponent(machine));
|
||||
window.location.href = url;//create_machine_url;
|
||||
}
|
||||
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
19
instances/templates/create_steps.html
Normal file
19
instances/templates/create_steps.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{% load i18n %}
|
||||
{# The steps of creating a VM; step is the current one (1-3), a done step links back to it. #}
|
||||
<nav aria-label="{% trans "Create a VM" %}">
|
||||
<ol class="create-steps list-unstyled d-flex flex-wrap gap-2 small mb-3">
|
||||
{% if step == 1 %}
|
||||
<li class="fw-semibold" aria-current="step">1. {% trans "Host" %}</li>
|
||||
{% else %}
|
||||
<li><a class="text-decoration-underline" href="{% url 'instances:index' %}">1. {% trans "Host" %}</a>: {{ compute.name }}</li>
|
||||
{% endif %}
|
||||
{% if step == 2 %}
|
||||
<li class="fw-semibold" aria-current="step">2. {% trans "Machine" %}</li>
|
||||
{% elif step == 3 %}
|
||||
<li><a class="text-decoration-underline" href="{% url 'instances:create_instance_select_type' compute.id %}">2. {% trans "Machine" %}</a>: {{ arch }}, {{ machine }}</li>
|
||||
{% else %}
|
||||
<li class="text-body-secondary">2. {% trans "Machine" %}</li>
|
||||
{% endif %}
|
||||
<li{% if step == 3 %} class="fw-semibold" aria-current="step"{% else %} class="text-body-secondary"{% endif %}>3. {% trans "Details" %}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
Loading…
Add table
Add a link
Reference in a new issue