mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 03:36:48 +00:00
fix(instances): change the edited NIC instead of adding a new one
The edit form posts net-*-<n> fields for NIC n and carries only the new MAC. The backend read index 0 and looked the NIC up by the new MAC, so editing a MAC detached nothing and attached a second NIC, and edits of any NIC but the first were applied with empty values. The form now also posts the current MAC (net-old-mac-<n>). The view reads the submitted NIC's fields, validates the new MAC and reports errors. The backend replaces the NIC with the old MAC, refuses an unknown one, and on a failed attach restores the old NIC and raises instead of reporting success. The view crashed with a TypeError without a Referer header; it now returns to the instance page, and a Referer from another site is ignored.
This commit is contained in:
parent
9e92d208db
commit
fbc6c4976f
6 changed files with 216 additions and 40 deletions
|
|
@ -1707,27 +1707,20 @@ class wvmInstance(wvmConnect):
|
|||
return new_xml
|
||||
return None
|
||||
|
||||
def change_network(self, network_data):
|
||||
net_mac = network_data.get("net-mac-0")
|
||||
net_source = network_data.get("net-source-0")
|
||||
net_source_type = network_data.get("net-source-0-type")
|
||||
net_filter = network_data.get("net-nwfilter-0")
|
||||
net_model = network_data.get("net-model-0")
|
||||
|
||||
# Remove interface first, but keep network interface XML definition
|
||||
# If there is an error happened while adding changed one, then add removed one to back.
|
||||
status = self.delete_network(net_mac)
|
||||
def change_network(self, old_mac, mac, source, source_type, model, nwfilter):
|
||||
"""Replace the NIC with old_mac; put it back if the new one cannot be added."""
|
||||
old_xml = self.delete_network(old_mac)
|
||||
if old_xml is None:
|
||||
raise libvirtError(f"No network interface with MAC {old_mac}")
|
||||
try:
|
||||
self.add_network(
|
||||
net_mac, net_source, net_source_type, net_model, net_filter
|
||||
)
|
||||
self.add_network(mac, source, source_type, model, nwfilter)
|
||||
except libvirtError:
|
||||
if status is not None:
|
||||
if self.get_status() == 1:
|
||||
self.instance.attachDeviceFlags(status, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.instance.attachDeviceFlags(status, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
if self.get_status() == 5:
|
||||
self.instance.attachDeviceFlags(status, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
if self.get_status() == 1:
|
||||
self.instance.attachDeviceFlags(old_xml, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.instance.attachDeviceFlags(old_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
if self.get_status() == 5:
|
||||
self.instance.attachDeviceFlags(old_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
raise
|
||||
|
||||
def change_network_oldway(self, network_data):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue