mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(instances): a refused XML definition comes back in its editor
On the machine step, "Or define it from XML" lost the definition when it was refused: a taken name re-rendered the page with an empty, collapsed editor; malformed XML went on to libvirt, and libvirt's refusal sent the browser back to an empty page with the reason at the top. All three refusals now render the page with the section open, the submitted XML in the editor (and in the field it posts, so it can be sent again unchanged), and the reason above the editor, which takes the focus. Fixes #174 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
575077c8ac
commit
9c6e07a467
3 changed files with 48 additions and 13 deletions
|
|
@ -1975,22 +1975,24 @@ def create_instance_select_type(request, compute_id):
|
|||
default_machine = app_settings.INSTANCE_MACHINE_DEFAULT_TYPE
|
||||
default_arch = app_settings.INSTANCE_ARCH_DEFAULT_TYPE
|
||||
|
||||
if request.method == "POST":
|
||||
if "create_xml" in request.POST:
|
||||
xml = request.POST.get("dom_xml", "")
|
||||
try:
|
||||
name = util.get_xml_path(xml, "/domain/name")
|
||||
except util.etree.Error:
|
||||
name = None
|
||||
# a refused definition comes back in the editor, its reason beside it
|
||||
xml_error = None
|
||||
if request.method == "POST" and "create_xml" in request.POST:
|
||||
xml = request.POST.get("dom_xml", "")
|
||||
try:
|
||||
name = util.get_xml_path(xml, "/domain/name")
|
||||
if name in instances:
|
||||
error_msg = _("A virtual machine with this name already exists")
|
||||
messages.error(request, error_msg)
|
||||
xml_error = _("A virtual machine with this name already exists")
|
||||
else:
|
||||
with libvirt_compute_lock(compute):
|
||||
conn._defineXML(xml)
|
||||
utils.refr(compute)
|
||||
instance = compute.instance_set.get(name=name)
|
||||
return redirect(reverse("instances:instance", args=[instance.id]))
|
||||
except util.etree.Error as err:
|
||||
xml_error = _("The XML is not well-formed: %(error)s") % {"error": err}
|
||||
except libvirtError as err:
|
||||
xml_error = _("libvirt Error - %(exception)s") % {"exception": error_text(request, err)}
|
||||
|
||||
return render(request, "create_instance_w1.html", locals())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue