mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 04:06:47 +00:00
fix(networks): a DHCP range change is reported only when it was made
On a running network the change did nothing, yet the page said the range was changed; a network without a range or an unknown address family ended in a server error. Each is refused now with the reason: stop the network first, or the network has no such range. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
887b807451
commit
39933fce7f
2 changed files with 75 additions and 9 deletions
|
|
@ -267,15 +267,17 @@ class wvmNetwork(wvmConnect):
|
|||
return result
|
||||
|
||||
def modify_dhcp_range(self, range_start, range_end, family="ipv4"):
|
||||
if not self.is_active():
|
||||
tree = etree.fromstring(self._XMLDesc(0))
|
||||
if family == "ipv4":
|
||||
dhcp_range = tree.xpath("./ip[not(@family='ipv6')]/dhcp/range")
|
||||
if family == "ipv6":
|
||||
dhcp_range = tree.xpath("./ip[@family='ipv6']/dhcp/range")
|
||||
dhcp_range[0].set("start", range_start)
|
||||
dhcp_range[0].set("end", range_end)
|
||||
self.wvm.networkDefineXML(etree.tostring(tree).decode())
|
||||
"""Refused while the network runs: the running network would keep the old range."""
|
||||
if self.is_active():
|
||||
raise util.OperationError(f"Stop network {self.net.name()} to change its DHCP range")
|
||||
tree = etree.fromstring(self._XMLDesc(0))
|
||||
ip = {"ipv4": "ip[not(@family='ipv6')]", "ipv6": "ip[@family='ipv6']"}.get(family)
|
||||
dhcp_range = tree.xpath(f"{ip}/dhcp/range") if ip else []
|
||||
if not dhcp_range:
|
||||
raise util.OperationError(f"Network {self.net.name()} has no {family} DHCP range")
|
||||
dhcp_range[0].set("start", range_start)
|
||||
dhcp_range[0].set("end", range_end)
|
||||
self.wvm.networkDefineXML(etree.tostring(tree).decode())
|
||||
|
||||
def delete_fixed_address(self, ip, family="ipv4"):
|
||||
tree = etree.fromstring(self._XMLDesc(0))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue