1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00
webvirtcloud/static/js/create_machine.js
catborise 6abea495f1 fix(logs): failures name their job, VM and user; the new VM form shows a list it could not load
- A failed cancel hook logged "worker task cancel failed": it now names
  the job, its kind, resource and user, with the traceback for a fault
  of the panel.
- novncd logged "Console connection failed" without the VM or the user.
- django-axes wrote four INFO lines a login ("Reset 0 access
  attempts"...); logins are on the Logs page, so it logs warnings only.
- The new VM form's machine types and disk buses answered 200 with an
  empty object when libvirt failed, and nothing was logged: the list
  stayed empty, the form could not go on and said nothing. They answer
  400 with the error, as the pool's volume list does, the warning is
  logged with the compute, and the form's lists show an error they get
  with the page's messages.
2026-11-06 23:48:44 +03:00

43 lines
2 KiB
JavaScript

// The create wizard's first page (create_instance_w1.html): the machine
// types of the chosen architecture, Next to the form for them, and a VM
// defined from XML instead.
// the machine types of the chosen architecture, the default one selected;
// the list is empty while it loads, and a newer load aborts the older one
function load_machines(arch) {
const next = document.querySelector("#next"), list = document.querySelector("#select_chipset");
next.disabled = true;
list.replaceChildren();
if (list.request) list.request.abort();
list.request = $.getJSON(list.dataset.machinesUrl.replace("__arch__", encodeURIComponent(arch)), function (data) {
list.replaceChildren(...data['machines'].map(
item => new Option(item, item, false, item === list.dataset.default)));
next.disabled = !data['machines'].length;
}).fail(showLoadError);
}
// placeholders, not "x86_64"/"pc": an architecture such as ppc64 contains "pc"
function create_url(arch, machine) {
return document.querySelector("#next").dataset.createUrl
.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);
}
const archs = document.querySelector("#select_archs");
archs.addEventListener("change", () => load_machines(archs.value));
document.querySelector("#next").addEventListener("click", goto_create);
load_machines(archs.value);
// the XML editor fills the form's field
const editor = ace.edit("editor");
editor.getSession().setMode("ace/mode/xml");
const xml_input = document.querySelector('input[name="dom_xml"]');
editor.getSession().on("change", function () {
xml_input.value = editor.getSession().getValue();
});
// the editor measures itself when its section is shown
document.querySelector("#from-xml").addEventListener("shown.bs.collapse", () => editor.resize());