diff --git a/instances/templates/add_instance_network_block.html b/instances/templates/add_instance_network_block.html
new file mode 100644
index 0000000..b990eec
--- /dev/null
+++ b/instances/templates/add_instance_network_block.html
@@ -0,0 +1,42 @@
+{% load i18n %}
+{% if request.user.is_superuser and status == 5 %}
+
+
+
+
+
+
+{% endif %}
diff --git a/instances/templates/instance.html b/instances/templates/instance.html
index 04e67da..f569297 100644
--- a/instances/templates/instance.html
+++ b/instances/templates/instance.html
@@ -827,7 +827,10 @@
{% endif %}
{% if request.user.is_superuser %}
-
{% trans "Assign network device to bridge" %}
+
+ {% trans "Assign network device to bridge" %}
+ {% include 'add_instance_network_block.html' %}
+
@@ -898,7 +901,7 @@
+ onclick="random_mac('clone-net-mac-{{ forloop.counter0 }}')" style="margin-top: 2px;">{% trans "Random" %}
@@ -1230,7 +1233,7 @@
@@ -1339,7 +1342,8 @@
});
{% if request.user.is_superuser %}
$(document).ready(function () {
- random_mac(0);
+ random_mac('clone-net-mac-0');
+ random_mac('add-net-mac');
});
{% else %}
$('#select_clone_name').on('change', function () {
diff --git a/instances/views.py b/instances/views.py
index d479bfe..4159c7d 100644
--- a/instances/views.py
+++ b/instances/views.py
@@ -696,6 +696,17 @@ def instance(request, compute_id, vname):
messages.success(request, msg)
return HttpResponseRedirect(request.get_full_path() + '#network')
+ if 'add_network' in request.POST:
+ mac = request.POST.get('add-net-mac')
+ network = request.POST.get('add-net-network')
+
+ conn.add_network(mac, network)
+ msg = _("Edit network")
+ addlogmsg(request.user.username, instance.name, msg)
+ msg = _("Network Devices are changed. Please reboot instance to activate.")
+ messages.success(request, msg)
+ return HttpResponseRedirect(request.get_full_path() + '#network')
+
if 'add_owner' in request.POST:
user_id = int(request.POST.get('user_id', ''))
diff --git a/vrtManager/instance.py b/vrtManager/instance.py
index 5cb9390..42bf19f 100644
--- a/vrtManager/instance.py
+++ b/vrtManager/instance.py
@@ -742,6 +742,23 @@ class wvmInstance(wvmConnect):
return self.get_instance(clone_data['name']).UUIDString()
+ def add_network(self, mac_address, network, interface_type='bridge', model='virtio'):
+ tree = ElementTree.fromstring(self._XMLDesc(0))
+ net = self.get_network(network)
+ xml_interface = """
+
+
+
+
+
+ """ % (interface_type, mac_address, net.bridgeName(), model)
+ 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)
+
def change_network(self, network_data):
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
tree = ElementTree.fromstring(xml)