mirror of
https://github.com/retspen/webvirtcloud
synced 2024-10-31 19:44:16 +00:00
Live network interface add remove capability is added. No need to shutdown to add/remove network interfaces
This commit is contained in:
parent
edd4887a2d
commit
a3e7a5472f
3 changed files with 20 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
|||
{% load i18n %}
|
||||
{% if request.user.is_superuser and status == 5 %}
|
||||
{% if request.user.is_superuser %}
|
||||
<a href="#addInstanceNetwork" type="button" class="btn btn-success pull-right" data-toggle="modal">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
</a>
|
||||
|
|
|
@ -718,7 +718,7 @@ def instance(request, compute_id, vname):
|
|||
|
||||
conn.change_network(network_data)
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
msg = _("Network Devices are changed. Please reboot instance to activate.")
|
||||
msg = _("Network Device Config is changed. Please shutdown instance to activate.")
|
||||
if conn.get_status() != 5: messages.success(request, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
|
@ -729,11 +729,7 @@ def instance(request, compute_id, vname):
|
|||
(source, source_type) = get_network_tuple(request.POST.get('add-net-network'))
|
||||
|
||||
conn.add_network(mac, source, source_type, nwfilter=nwfilter)
|
||||
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
msg = _("Network Device is added. Please reboot instance to activate.")
|
||||
if conn.get_status() != 5: messages.success(request, msg)
|
||||
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
if 'delete_network' in request.POST:
|
||||
|
@ -742,8 +738,6 @@ def instance(request, compute_id, vname):
|
|||
|
||||
conn.delete_network(mac_address)
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
msg = _("Network Device is deleted. Please reboot instance to activate.")
|
||||
if conn.get_status() != 5: messages.success(request, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||
|
||||
if 'add_owner' in request.POST:
|
||||
|
|
|
@ -970,12 +970,18 @@ class wvmInstance(wvmConnect):
|
|||
""" % nwfilter
|
||||
xml_interface += """</interface>"""
|
||||
|
||||
# if self.get_status() == 5:
|
||||
# devices = tree.find('devices')
|
||||
# elm_interface = ElementTree.fromstring(xml_interface)
|
||||
# devices.append(elm_interface)
|
||||
# xmldom = ElementTree.tostring(tree)
|
||||
# self._defineXML(xmldom)
|
||||
|
||||
if self.get_status() == 1:
|
||||
self.instance.attachDeviceFlags(xml_interface, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.instance.attachDeviceFlags(xml_interface, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
if self.get_status() == 5:
|
||||
devices = tree.find('devices')
|
||||
elm_interface = ElementTree.fromstring(xml_interface)
|
||||
devices.append(elm_interface)
|
||||
xmldom = ElementTree.tostring(tree)
|
||||
self._defineXML(xmldom)
|
||||
self.instance.attachDeviceFlags(xml_interface, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
|
||||
def delete_network(self, mac_address):
|
||||
tree = ElementTree.fromstring(self._XMLDesc(0))
|
||||
|
@ -983,10 +989,13 @@ class wvmInstance(wvmConnect):
|
|||
for interface in tree.findall('devices/interface'):
|
||||
source = interface.find('mac')
|
||||
if source.get('address', '') == mac_address:
|
||||
source = None
|
||||
devices.remove(interface)
|
||||
new_xml = ElementTree.tostring(tree)
|
||||
self._defineXML(new_xml)
|
||||
new_xml = ElementTree.tostring(interface)
|
||||
|
||||
if self.get_status() == 1:
|
||||
self.instance.detachDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.instance.detachDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
if self.get_status() == 5:
|
||||
self.instance.detachDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
|
||||
def change_network(self, network_data):
|
||||
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
|
|
Loading…
Reference in a new issue