mirror of
https://github.com/dkmstr/openuds.git
synced 2025-10-14 15:33:43 +03:00
Fixed validator of host and port to allow FQDN
This commit is contained in:
@@ -263,7 +263,7 @@ def validate_host_port(host_port_pair: str, field_name: typing.Optional[str] = N
|
|||||||
dj_validators.validate_ipv46_address(host)
|
dj_validators.validate_ipv46_address(host)
|
||||||
return host, validate_port(port)
|
return host, validate_port(port)
|
||||||
except Exception:
|
except Exception:
|
||||||
return validate_hostname(host, 255, False), validate_port(port)
|
return validate_hostname(host, 255, True), validate_port(port)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise exceptions.ui.ValidationError(_('{} is not a valid host:port pair').format(host_port_pair + field_name)) from None
|
raise exceptions.ui.ValidationError(_('{} is not a valid host:port pair').format(host_port_pair + field_name)) from None
|
||||||
|
|
||||||
|
@@ -670,25 +670,29 @@ class ProxmoxClient:
|
|||||||
def set_vm_net_mac(
|
def set_vm_net_mac(
|
||||||
self,
|
self,
|
||||||
vmid: int,
|
vmid: int,
|
||||||
mac: str,
|
macaddr: str,
|
||||||
netid: typing.Optional[str] = None,
|
netid: typing.Optional[str] = None, # net0, net1, ...
|
||||||
node: typing.Optional[str] = None,
|
node: typing.Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
node = node or self.get_vm_info(vmid).node
|
node = node or self.get_vm_info(vmid).node
|
||||||
# First, read current configuration and extract network configuration
|
|
||||||
config = self.do_get(f'nodes/{node}/qemu/{vmid}/config', node=node)['data']
|
net: types.NetworkConfiguration = types.NetworkConfiguration.null()
|
||||||
if netid not in config:
|
|
||||||
# Get first network interface (netX where X is a number)
|
cfg = self.get_vm_config(vmid, node)
|
||||||
netid = next((k for k in config if k.startswith('net') and k[3:].isdigit()), None)
|
|
||||||
if not netid:
|
if netid is None:
|
||||||
raise exceptions.ProxmoxError('No network interface found')
|
net = cfg.networks[0]
|
||||||
|
else:
|
||||||
|
for i in cfg.networks:
|
||||||
|
if i.net == netid:
|
||||||
|
net = i
|
||||||
|
break
|
||||||
|
|
||||||
|
# net should be the reference to the network we want to update
|
||||||
|
if net.is_null():
|
||||||
|
raise exceptions.ProxmoxError(f'Network {netid} not found for VM {vmid}')
|
||||||
|
|
||||||
netdata = config[netid]
|
logger.debug('Updating mac address for VM %s: %s=%s', vmid, netid, net.macaddr)
|
||||||
|
|
||||||
# Update mac address, that is the first field <model>=<mac>,<other options>
|
|
||||||
netdata = re.sub(r'^([^=]+)=([^,]+),', r'\1={},'.format(mac), netdata)
|
|
||||||
|
|
||||||
logger.debug('Updating mac address for VM %s: %s=%s', vmid, netid, netdata)
|
|
||||||
|
|
||||||
self.do_post(
|
self.do_post(
|
||||||
f'nodes/{node}/qemu/{vmid}/config',
|
f'nodes/{node}/qemu/{vmid}/config',
|
||||||
|
@@ -221,17 +221,30 @@ class TaskStatus:
|
|||||||
class NetworkConfiguration:
|
class NetworkConfiguration:
|
||||||
net: str
|
net: str
|
||||||
type: str
|
type: str
|
||||||
mac: str
|
macaddr: str
|
||||||
|
|
||||||
|
netdata: str # Original data
|
||||||
|
|
||||||
|
def is_null(self) -> bool:
|
||||||
|
return self.net == ''
|
||||||
|
|
||||||
|
def set_mac_address(self, macaddr: str) -> None:
|
||||||
|
self.macaddr = macaddr
|
||||||
|
# Replace mac address in netdata
|
||||||
|
self.netdata = re.sub(r'^([^=]+)=([^,]+),', r'\1={},'.format(macaddr), self.netdata)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_str(net: str, value: str) -> 'NetworkConfiguration':
|
def from_str(net: str, netdata: str) -> 'NetworkConfiguration':
|
||||||
v = NETWORK_RE.match(value)
|
v = NETWORK_RE.match(netdata)
|
||||||
type = mac = ''
|
type = mac = ''
|
||||||
if v:
|
if v:
|
||||||
type, mac = v.group(1), v.group(2)
|
type, mac = v.group(1), v.group(2)
|
||||||
|
|
||||||
return NetworkConfiguration(net=net, type=type, mac=mac)
|
return NetworkConfiguration(net=net, type=type, macaddr=mac, netdata=netdata)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def null() -> 'NetworkConfiguration':
|
||||||
|
return NetworkConfiguration(net='', type='', macaddr='', netdata='')
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class HAInfo:
|
class HAInfo:
|
||||||
|
@@ -213,7 +213,7 @@ class ProxmoxServiceFixed(FixedService): # pylint: disable=too-many-public-meth
|
|||||||
|
|
||||||
def get_mac(self, vmid: str) -> str:
|
def get_mac(self, vmid: str) -> str:
|
||||||
config = self.provider().api.get_vm_config(int(vmid))
|
config = self.provider().api.get_vm_config(int(vmid))
|
||||||
return config.networks[0].mac.lower()
|
return config.networks[0].macaddr.lower()
|
||||||
|
|
||||||
def get_ip(self, vmid: str) -> str:
|
def get_ip(self, vmid: str) -> str:
|
||||||
return self.provider().api.get_guest_ip_address(int(vmid))
|
return self.provider().api.get_guest_ip_address(int(vmid))
|
||||||
|
@@ -265,7 +265,7 @@ class ProxmoxServiceLinked(DynamicService):
|
|||||||
# If vmid is empty, we are requesting a new mac
|
# If vmid is empty, we are requesting a new mac
|
||||||
if not vmid:
|
if not vmid:
|
||||||
return self.mac_generator().get(self.get_macs_range())
|
return self.mac_generator().get(self.get_macs_range())
|
||||||
return self.provider().api.get_vm_config(int(vmid)).networks[0].mac.lower()
|
return self.provider().api.get_vm_config(int(vmid)).networks[0].macaddr.lower()
|
||||||
|
|
||||||
def start(self, caller_instance: typing.Optional['DynamicUserService | DynamicPublication'], vmid: str) -> None:
|
def start(self, caller_instance: typing.Optional['DynamicUserService | DynamicPublication'], vmid: str) -> None:
|
||||||
if isinstance(caller_instance, ProxmoxUserserviceLinked):
|
if isinstance(caller_instance, ProxmoxUserserviceLinked):
|
||||||
|
Reference in New Issue
Block a user