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:
parent
d682c4bc82
commit
eb3bc69754
10 changed files with 139 additions and 69 deletions
|
|
@ -13,6 +13,9 @@ class KeepSecretsMixin:
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.instance.type = self.conn_type # the form's own kind, never a posted one
|
||||
if "password" in self.fields:
|
||||
self.fields["password"].strip = False # a SASL password may begin or end with a space
|
||||
for name in ("password", "gstfsd_key"):
|
||||
if name in self.fields and getattr(self.instance, name):
|
||||
self.fields[name].widget.attrs["placeholder"] = _("Stored, leave empty to keep")
|
||||
|
|
@ -31,56 +34,56 @@ SASL_LABELS = {"login": _("SASL login"), "password": _("SASL password")} | DETAI
|
|||
|
||||
|
||||
class TcpComputeForm(KeepSecretsMixin, forms.ModelForm):
|
||||
conn_type = CONN_TCP
|
||||
kind = "TCP"
|
||||
about = _("libvirt over TCP, with a SASL login")
|
||||
hostname = forms.CharField(validators=[validate_hostname])
|
||||
type = forms.IntegerField(widget=forms.HiddenInput, initial=CONN_TCP)
|
||||
|
||||
class Meta:
|
||||
model = Compute
|
||||
widgets = SECRET_WIDGETS
|
||||
labels = SASL_LABELS
|
||||
help_texts = DETAILS_HELP
|
||||
fields = "__all__"
|
||||
exclude = ["type"]
|
||||
|
||||
|
||||
class SshComputeForm(KeepSecretsMixin, forms.ModelForm):
|
||||
conn_type = CONN_SSH
|
||||
kind = "SSH"
|
||||
about = _("libvirt over SSH, with the panel's SSH key")
|
||||
hostname = forms.CharField(validators=[validate_hostname], label=_("FQDN/IP"))
|
||||
type = forms.IntegerField(widget=forms.HiddenInput, initial=CONN_SSH)
|
||||
|
||||
class Meta:
|
||||
model = Compute
|
||||
widgets = SECRET_WIDGETS
|
||||
labels = {"login": _("SSH user")} | DETAILS
|
||||
help_texts = DETAILS_HELP
|
||||
exclude = ["password"]
|
||||
exclude = ["password", "type"]
|
||||
|
||||
|
||||
class TlsComputeForm(KeepSecretsMixin, forms.ModelForm):
|
||||
conn_type = CONN_TLS
|
||||
kind = "TLS"
|
||||
about = _("libvirt over TLS, with certificates")
|
||||
hostname = forms.CharField(validators=[validate_hostname])
|
||||
type = forms.IntegerField(widget=forms.HiddenInput, initial=CONN_TLS)
|
||||
|
||||
class Meta:
|
||||
model = Compute
|
||||
widgets = SECRET_WIDGETS
|
||||
labels = SASL_LABELS
|
||||
help_texts = DETAILS_HELP
|
||||
fields = "__all__"
|
||||
exclude = ["type"]
|
||||
|
||||
|
||||
class SocketComputeForm(KeepSecretsMixin, forms.ModelForm):
|
||||
conn_type = CONN_SOCKET
|
||||
kind = _("Local")
|
||||
about = _("the libvirt of the host the panel runs on, by its socket")
|
||||
hostname = forms.CharField(widget=forms.HiddenInput, initial="localhost")
|
||||
type = forms.IntegerField(widget=forms.HiddenInput, initial=CONN_SOCKET)
|
||||
|
||||
class Meta:
|
||||
model = Compute
|
||||
widgets = SECRET_WIDGETS
|
||||
labels = DETAILS
|
||||
help_texts = DETAILS_HELP
|
||||
fields = ["name", "details", "hostname", "type", "migration_address", "gstfsd_key"]
|
||||
fields = ["name", "details", "hostname", "migration_address", "gstfsd_key"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue