1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

fix(computes): the compute forms save their own kind, a password as typed, and say when the host is not reached

The kind of a compute came from a hidden form field: posted as another
number it was saved, and the edit page of that compute failed. Each form
now saves its own kind. Passwords lost their leading and trailing spaces
on the forms and the API, so a SASL password with one never worked. A
host name whose last label is all digits, such as an IPv4 address with a
trailing dot, was taken and libvirt could not resolve it. A host saved with
a wrong password or not answering was saved silently; the page now says
why the panel cannot connect to it.
This commit is contained in:
catborise 2026-11-12 08:47:32 +03:00
parent d682c4bc82
commit eb3bc69754
10 changed files with 139 additions and 69 deletions

View file

@ -9,6 +9,12 @@ _hostname = re.compile(r"[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-
_login = re.compile(r"[A-Za-z0-9._][A-Za-z0-9._-]*")
def _is_name(value):
"""A host name: its last label is never all digits ("192.0.2.1." is no
address and no name, libvirt cannot resolve it)."""
return bool(_hostname.fullmatch(value)) and not value.rstrip(".").rsplit(".", 1)[-1].isdigit()
def validate_hostname(value):
"""An IPv4 address or a host name that goes safely into a libvirt
connection URI. No scheme, port, path, query, whitespace or IPv6 literal:
@ -19,7 +25,7 @@ def validate_hostname(value):
if ip_address(value).version == 4:
return
except ValueError:
if _hostname.fullmatch(value):
if _is_name(value):
return
raise ValidationError(_("Enter an IPv4 address or a host name, without a scheme, port or path"))
@ -42,7 +48,7 @@ def validate_migration_address(value):
if not getattr(ip_address(value), "scope_id", None):
return
except ValueError:
if _hostname.fullmatch(value):
if _is_name(value):
return
raise ValidationError(_("Enter an IP address or a host name, without a scheme or port"))