From ead0414a4d276dc4ab9a72878062082613222a7e Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 24 Jan 2019 15:02:19 +0300 Subject: [PATCH] Add XML config editing option for a network --- networks/templates/network.html | 172 +++++++++++++++++++------------- networks/views.py | 18 +++- vrtManager/network.py | 2 +- 3 files changed, 121 insertions(+), 71 deletions(-) diff --git a/networks/templates/network.html b/networks/templates/network.html index 450c393..e3af02c 100644 --- a/networks/templates/network.html +++ b/networks/templates/network.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load i18n %} +{% load staticfiles %} {% block title %}{% trans "Network" %} - {{ pool }}{% endblock %} {% block content %} @@ -38,10 +39,10 @@
-

{% trans "Network name:" %}

-

{% trans "Device:" %}

-

{% trans "State" %}

-

{% trans "Autostart" %}

+

{% trans "Network name" %}:

+

{% trans "Device" %}:

+

{% trans "State" %}:

+

{% trans "Autostart" %}:

{{ pool }}

@@ -67,11 +68,35 @@

- {#{% if state %}#} -
- +
+ +
+
+
+ +
+
+
{% csrf_token %} +
+ + +
+ +
+
+
-
+
+
+ +
+

{% trans "IPv4 Forwarding:" %}

{% trans "Network:" %}

@@ -122,75 +147,74 @@ {% endif %}
- {% ifequal ipv4_forward.0 'nat' %} - {% if state %} - {% include 'modify_fixed_address.html' %} - {% endif %} -
- -
- {% endifequal %} - {% if fixed_address %} -
-
-
-
- -
-
+ {% ifequal ipv4_forward.0 'nat' %} + {% if state %} + {% include 'modify_fixed_address.html' %} + {% endif %} +
+ +
+ {% endifequal %} + {% if fixed_address %} +
+
+
+
+ +
+
-
-
- -
- - +
+
+
- - - - - - - - - - - {% for fix in fixed_address %} - - {% csrf_token %} - - - - - - - {% endfor %} - -
{% trans "MAC" %}{% trans "Address" %}{% trans "Name" %}{% trans "Action" %}
- - - -
+ +
+ + + + + + + + + + + {% for fix in fixed_address %} + + {% csrf_token %} + + + + + + + {% endfor %} + +
{% trans "MAC" %}{% trans "Address" %}{% trans "Name" %}{% trans "Action" %}
+ + + +
- {#{% endif %}#} +
{% endif %} {% endblock %} {% block script %} @@ -230,4 +254,14 @@ }); }); + + {% endblock %} \ No newline at end of file diff --git a/networks/views.py b/networks/views.py index ee61043..29fb802 100644 --- a/networks/views.py +++ b/networks/views.py @@ -88,6 +88,7 @@ def network(request, compute_id, pool): ipv4_dhcp_range_end = conn.get_ipv4_dhcp_range_end() ipv4_network = conn.get_ipv4_network() fixed_address = conn.get_mac_ipaddr() + xml = conn._XMLDesc(0) except libvirtError as lib_err: error_messages.append(lib_err) @@ -139,7 +140,6 @@ def network(request, compute_id, pool): conn.delete_fixed_address(mac) messages.success(request, "Fixed Address is Deleted.") return HttpResponseRedirect(request.get_full_path()) - if 'modify_dhcp_range' in request.POST: range_start = request.POST.get('range_start', '') range_end = request.POST.get('range_end', '') @@ -149,6 +149,22 @@ def network(request, compute_id, pool): return HttpResponseRedirect(request.get_full_path()) except libvirtError as lib_err: error_messages.append(lib_err.message) + if 'edit_network' in request.POST: + edit_xml = request.POST.get('edit_xml', '') + if edit_xml: + try: + new_conn = wvmNetworks(compute.hostname, + compute.login, + compute.password, + compute.type) + conn.define_network(edit_xml) + if conn.is_active(): + messages.success(request, _("Network XML is changed. Stop and start network to activate new config.")) + else: + messages.success(request, _("Network XML is changed.")) + return HttpResponseRedirect(request.get_full_path()) + except libvirtError as lib_err: + error_messages.append(lib_err.message) conn.close() diff --git a/vrtManager/network.py b/vrtManager/network.py index 8b430c6..d3c67f3 100644 --- a/vrtManager/network.py +++ b/vrtManager/network.py @@ -2,7 +2,7 @@ from vrtManager import util from vrtManager.IPy import IP from vrtManager.connection import wvmConnect from xml.etree import ElementTree -from libvirt import VIR_NETWORK_SECTION_IP_DHCP_HOST, VIR_NETWORK_SECTION_IP_DHCP_RANGE +from libvirt import VIR_NETWORK_SECTION_IP_DHCP_HOST from libvirt import VIR_NETWORK_UPDATE_COMMAND_ADD_LAST, VIR_NETWORK_UPDATE_COMMAND_DELETE, VIR_NETWORK_UPDATE_COMMAND_MODIFY from libvirt import VIR_NETWORK_UPDATE_AFFECT_LIVE, VIR_NETWORK_UPDATE_AFFECT_CONFIG