mirror of
https://github.com/retspen/webvirtcloud
synced 2024-10-31 19:44:16 +00:00
fix network add and change methods to handle bridge/mavctap differentation correctly.
This commit is contained in:
parent
2f1b11b3ca
commit
fa4a3149c9
2 changed files with 60 additions and 17 deletions
|
@ -25,6 +25,7 @@ from logs.views import addlogmsg
|
||||||
from vrtManager import util
|
from vrtManager import util
|
||||||
from vrtManager.create import wvmCreate
|
from vrtManager.create import wvmCreate
|
||||||
from vrtManager.instance import wvmInstances
|
from vrtManager.instance import wvmInstances
|
||||||
|
from vrtManager.interface import wvmInterface
|
||||||
from vrtManager.storage import wvmStorage
|
from vrtManager.storage import wvmStorage
|
||||||
from vrtManager.util import randomPasswd
|
from vrtManager.util import randomPasswd
|
||||||
|
|
||||||
|
@ -121,6 +122,7 @@ def instance(request, pk):
|
||||||
memory_host = instance.proxy.get_max_memory()
|
memory_host = instance.proxy.get_max_memory()
|
||||||
bus_host = instance.proxy.get_disk_bus_types(instance.arch, instance.machine)
|
bus_host = instance.proxy.get_disk_bus_types(instance.arch, instance.machine)
|
||||||
networks_host = sorted(instance.proxy.get_networks())
|
networks_host = sorted(instance.proxy.get_networks())
|
||||||
|
interfaces_host = sorted(instance.proxy.get_ifaces())
|
||||||
nwfilters_host = instance.proxy.get_nwfilters()
|
nwfilters_host = instance.proxy.get_nwfilters()
|
||||||
storages_host = sorted(instance.proxy.get_storages(True))
|
storages_host = sorted(instance.proxy.get_storages(True))
|
||||||
net_models_host = instance.proxy.get_network_models()
|
net_models_host = instance.proxy.get_network_models()
|
||||||
|
@ -904,6 +906,16 @@ def change_network(request, pk):
|
||||||
(source, source_type) = utils.get_network_tuple(request.POST.get(post))
|
(source, source_type) = utils.get_network_tuple(request.POST.get(post))
|
||||||
network_data[post] = source
|
network_data[post] = source
|
||||||
network_data[post + "-type"] = source_type
|
network_data[post + "-type"] = source_type
|
||||||
|
|
||||||
|
if source_type == 'iface':
|
||||||
|
iface = wvmInterface(
|
||||||
|
instance.compute.hostname,
|
||||||
|
instance.compute.login,
|
||||||
|
instance.compute.password,
|
||||||
|
instance.compute.type,
|
||||||
|
source,
|
||||||
|
)
|
||||||
|
network_data[post + "-type"] = iface.get_type()
|
||||||
elif post.startswith("net-"):
|
elif post.startswith("net-"):
|
||||||
network_data[post] = request.POST.get(post, "")
|
network_data[post] = request.POST.get(post, "")
|
||||||
|
|
||||||
|
@ -923,6 +935,16 @@ def add_network(request, pk):
|
||||||
nwfilter = request.POST.get("add-net-nwfilter")
|
nwfilter = request.POST.get("add-net-nwfilter")
|
||||||
(source, source_type) = utils.get_network_tuple(request.POST.get("add-net-network"))
|
(source, source_type) = utils.get_network_tuple(request.POST.get("add-net-network"))
|
||||||
|
|
||||||
|
if source_type == 'iface':
|
||||||
|
iface = wvmInterface(
|
||||||
|
instance.compute.hostname,
|
||||||
|
instance.compute.login,
|
||||||
|
instance.compute.password,
|
||||||
|
instance.compute.type,
|
||||||
|
source,
|
||||||
|
)
|
||||||
|
source_type = iface.get_type()
|
||||||
|
|
||||||
instance.proxy.add_network(mac, source, source_type, nwfilter=nwfilter)
|
instance.proxy.add_network(mac, source, source_type, nwfilter=nwfilter)
|
||||||
msg = _("Add network: %(mac)s") % {"mac": mac}
|
msg = _("Add network: %(mac)s") % {"mac": mac}
|
||||||
addlogmsg(request.user.username, instance.name, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
|
|
@ -1366,19 +1366,15 @@ class wvmInstance(wvmConnect):
|
||||||
return bridge_name
|
return bridge_name
|
||||||
|
|
||||||
def add_network(self, mac_address, source, source_type="net", model="virtio", nwfilter=None):
|
def add_network(self, mac_address, source, source_type="net", model="virtio", nwfilter=None):
|
||||||
forward_mode = ""
|
|
||||||
if source_type != "iface":
|
if source_type == "net":
|
||||||
forward_mode = self.get_network_forward(source)
|
|
||||||
|
|
||||||
if forward_mode in ["nat", "isolated", "routed"]:
|
|
||||||
interface_type = "network"
|
interface_type = "network"
|
||||||
elif forward_mode == "":
|
elif source_type == "bridge":
|
||||||
interface_type = "direct"
|
interface_type = "bridge"
|
||||||
else:
|
else:
|
||||||
if self.get_bridge_name(source, source_type) is None:
|
interface_type = "direct"
|
||||||
interface_type = "network"
|
|
||||||
else:
|
# network modes not handled: default is bridge
|
||||||
interface_type = "bridge"
|
|
||||||
|
|
||||||
xml_iface = f"""
|
xml_iface = f"""
|
||||||
<interface type='{interface_type}'>
|
<interface type='{interface_type}'>
|
||||||
|
@ -1386,13 +1382,11 @@ class wvmInstance(wvmConnect):
|
||||||
if interface_type == "network":
|
if interface_type == "network":
|
||||||
xml_iface += f"""<source network='{source}'/>"""
|
xml_iface += f"""<source network='{source}'/>"""
|
||||||
elif interface_type == "direct":
|
elif interface_type == "direct":
|
||||||
if source_type == "net":
|
xml_iface += f"""<source dev='{source}' mode='bridge'/>"""
|
||||||
xml_iface += f"""<source network='{source}' mode='bridge'/>"""
|
elif interface_type == "bridge":
|
||||||
else:
|
xml_iface += f"""<source bridge='{source}'/>"""
|
||||||
xml_iface += f"""<source dev='{source}' mode='bridge'/>"""
|
|
||||||
else:
|
else:
|
||||||
bridge_name = self.get_bridge_name(source, source_type)
|
raise libvirtError(f"'{interface_type}' is an unexpected interface type.")
|
||||||
xml_iface += f"""<source bridge='{bridge_name}'/>"""
|
|
||||||
xml_iface += f"""<model type='{model}'/>"""
|
xml_iface += f"""<model type='{model}'/>"""
|
||||||
if nwfilter:
|
if nwfilter:
|
||||||
xml_iface += f"""<filterref filter='{nwfilter}'/>"""
|
xml_iface += f"""<filterref filter='{nwfilter}'/>"""
|
||||||
|
@ -1416,8 +1410,35 @@ class wvmInstance(wvmConnect):
|
||||||
self.instance.detachDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
self.instance.detachDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||||
if self.get_status() == 5:
|
if self.get_status() == 5:
|
||||||
self.instance.detachDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
self.instance.detachDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||||
|
return new_xml
|
||||||
|
return None
|
||||||
|
|
||||||
def change_network(self, network_data):
|
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)
|
||||||
|
try:
|
||||||
|
self.add_network(net_mac, net_source, net_source_type, net_model, net_filter)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
def change_network_oldway(self, network_data):
|
||||||
|
'''
|
||||||
|
change network firsh version...
|
||||||
|
will be removed if new one works as expected for all scenarios
|
||||||
|
'''
|
||||||
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||||
tree = ElementTree.fromstring(xml)
|
tree = ElementTree.fromstring(xml)
|
||||||
for num, interface in enumerate(tree.findall("devices/interface")):
|
for num, interface in enumerate(tree.findall("devices/interface")):
|
||||||
|
|
Loading…
Reference in a new issue