mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
Migration is client-driven: libvirt sends the VM's memory to the destination's own host name unless a migration URI is given, and the app never gave one. Where the hosts cannot resolve each other's names (or the names point at a management network) every migration failed with "Unable to resolve address '<host name>' service '49152'". A compute now has an optional migration address (an IP address or a host name, no scheme or port), editable in the compute form and the API. A VM migrating to that compute is sent to tcp://<address> (bracketed for IPv6). Empty, the default for existing computes, keeps the previous behavior. The compute's host name is not reused, because for SSH computes it can be an ssh_config alias. The migration log entry names the address when one is set.
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import re
|
|
from ipaddress import ip_address
|
|
|
|
from django.core.exceptions import ValidationError
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
have_symbol = re.compile("[^a-zA-Z0-9._-]+")
|
|
wrong_ip = re.compile("^0.|^255.")
|
|
wrong_name = re.compile("[^a-zA-Z0-9._-]+")
|
|
|
|
|
|
def validate_hostname(value):
|
|
sym = have_symbol.match(value)
|
|
wip = wrong_ip.match(value)
|
|
|
|
if sym:
|
|
raise ValidationError(
|
|
_('Hostname must contain only numbers, or the domain name separated by "."')
|
|
)
|
|
elif wip:
|
|
raise ValidationError(_("Wrong IP address"))
|
|
|
|
|
|
def validate_name(value):
|
|
have_symbol = wrong_name.match("[^a-zA-Z0-9._-]+")
|
|
if have_symbol:
|
|
raise ValidationError(_("The hostname must not contain any special characters"))
|
|
|
|
|
|
_hostname = re.compile(r"[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*\.?")
|
|
|
|
|
|
def validate_migration_address(value):
|
|
"""An IP address (no IPv6 scope) or a host name: no scheme, port or brackets."""
|
|
try:
|
|
if not getattr(ip_address(value), "scope_id", None):
|
|
return
|
|
except ValueError:
|
|
if _hostname.fullmatch(value):
|
|
return
|
|
raise ValidationError(_("Enter an IP address or a host name, without a scheme or port"))
|