mirror of
				https://github.com/retspen/webvirtcloud
				synced 2025-07-31 12:41:08 +00:00 
			
		
		
		
	Add XML config editing option for a network
This commit is contained in:
		
							parent
							
								
									573df2acaa
								
							
						
					
					
						commit
						ead0414a4d
					
				
					 3 changed files with 121 additions and 71 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
{% extends "base.html" %}
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
{% load staticfiles %}
 | 
			
		||||
{% block title %}{% trans "Network" %} - {{ pool }}{% endblock %}
 | 
			
		||||
{% block content %}
 | 
			
		||||
           <!-- Page Heading -->
 | 
			
		||||
| 
						 | 
				
			
			@ -38,10 +39,10 @@
 | 
			
		|||
 | 
			
		||||
            <div class="row">
 | 
			
		||||
                <div class="col-xs-6 col-sm-4">
 | 
			
		||||
                    <p>{% trans "Network name:" %}</p>
 | 
			
		||||
                    <p>{% trans "Device:" %}</p>
 | 
			
		||||
                    <p>{% trans "State" %}</p>
 | 
			
		||||
                    <p>{% trans "Autostart" %}</p>
 | 
			
		||||
                    <p>{% trans "Network name" %}:</p>
 | 
			
		||||
                    <p>{% trans "Device" %}:</p>
 | 
			
		||||
                    <p>{% trans "State" %}:</p>
 | 
			
		||||
                    <p>{% trans "Autostart" %}:</p>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="col-xs-6 col-sm-6">
 | 
			
		||||
                    <p>{{ pool }}</p>
 | 
			
		||||
| 
						 | 
				
			
			@ -67,11 +68,35 @@
 | 
			
		|||
                    </p>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            {#{% if state %}#}
 | 
			
		||||
                <div class="row">
 | 
			
		||||
                    <h3 class="page-header">{% trans "IPv4 Configuration" %}</h3>
 | 
			
		||||
        <div class="row">
 | 
			
		||||
                <h3 class="page-header"></h3>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="panel-group" id="accordion">
 | 
			
		||||
                <div class="panel panel-default">
 | 
			
		||||
                    <div class="panel-heading">
 | 
			
		||||
                        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
 | 
			
		||||
                            {% trans 'XML' %}
 | 
			
		||||
                        </a>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div id="collapseOne" class="panel-collapse collapse">
 | 
			
		||||
                        <div class="panel-body">
 | 
			
		||||
                          <form class="form-inline" method="post" role="form">{% csrf_token %}
 | 
			
		||||
                             <div class="col-xs-12" id="xmlheight">
 | 
			
		||||
                                <input type="hidden" name="edit_xml"/>
 | 
			
		||||
                                <textarea id="edit_editor">{{ xml }}</textarea>
 | 
			
		||||
                             </div>
 | 
			
		||||
                             <button type="submit" class="btn btn-primary pull-right" name="edit_network">
 | 
			
		||||
                                {% trans "Edit" %}
 | 
			
		||||
                             </button>
 | 
			
		||||
                          </form>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="row">
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="row">
 | 
			
		||||
                <h3 class="page-header">{% trans "IPv4 Configuration" %}</h3>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="row">
 | 
			
		||||
                    <div class="col-xs-6 col-sm-4">
 | 
			
		||||
                        <p>{% trans "IPv4 Forwarding:" %}</p>
 | 
			
		||||
                        <p>{% trans "Network:" %}</p>
 | 
			
		||||
| 
						 | 
				
			
			@ -122,75 +147,74 @@
 | 
			
		|||
                        {% endif %}
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                {% ifequal ipv4_forward.0 'nat' %}
 | 
			
		||||
                    {% if state %}
 | 
			
		||||
                        {% include 'modify_fixed_address.html' %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                    <div class="row">
 | 
			
		||||
                        <h3 class="page-header">{% trans "Fixed Address" %}</h3>
 | 
			
		||||
                    </div>
 | 
			
		||||
                {% endifequal %}
 | 
			
		||||
                {% if fixed_address %}
 | 
			
		||||
                    <div class="row">
 | 
			
		||||
                        <div class="col-xs-12">
 | 
			
		||||
                            <div class="panel-group" id="accordion">
 | 
			
		||||
                                <div class="panel panel-default">
 | 
			
		||||
                                    <div class="panel-heading">
 | 
			
		||||
                                        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
 | 
			
		||||
                                            {% trans 'Show' %}
 | 
			
		||||
                                        </a>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <div id="collapseOne" class="panel-collapse collapse">
 | 
			
		||||
                                        <div class="panel-body">
 | 
			
		||||
            {% ifequal ipv4_forward.0 'nat' %}
 | 
			
		||||
                {% if state %}
 | 
			
		||||
                    {% include 'modify_fixed_address.html' %}
 | 
			
		||||
                {% endif %}
 | 
			
		||||
                <div class="row">
 | 
			
		||||
                    <h3 class="page-header">{% trans "Fixed Address" %}</h3>
 | 
			
		||||
                </div>
 | 
			
		||||
            {% endifequal %}
 | 
			
		||||
            {% if fixed_address %}
 | 
			
		||||
                <div class="row">
 | 
			
		||||
                    <div class="col-xs-12">
 | 
			
		||||
                        <div class="panel-group" id="accordion">
 | 
			
		||||
                            <div class="panel panel-default">
 | 
			
		||||
                                <div class="panel-heading">
 | 
			
		||||
                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
 | 
			
		||||
                                        {% trans 'Show' %}
 | 
			
		||||
                                    </a>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                <div id="collapseOne" class="panel-collapse collapse">
 | 
			
		||||
                                    <div class="panel-body">
 | 
			
		||||
 | 
			
		||||
                                            <div class="input-append form-inline pull-right">
 | 
			
		||||
                                                <div class="form-group">
 | 
			
		||||
                                                    <input type="text" class="form-control" id="filter_input">
 | 
			
		||||
                                                </div>
 | 
			
		||||
                                                <input type="button" class="btn btn-default" id="filter_button" value="Filter">
 | 
			
		||||
                                                <button type="button" class="btn btn-default" id="filter_clear">{% trans 'Clear' %}</button>
 | 
			
		||||
                                        <div class="input-append form-inline pull-right">
 | 
			
		||||
                                            <div class="form-group">
 | 
			
		||||
                                                <input type="text" class="form-control" id="filter_input">
 | 
			
		||||
                                            </div>
 | 
			
		||||
                                            <table class="table table-hover">
 | 
			
		||||
                                                <thead>
 | 
			
		||||
                                                <tr>
 | 
			
		||||
                                                    <th style="text-align: center">{% trans "MAC" %}</th>
 | 
			
		||||
                                                    <th style="text-align: center">{% trans "Address" %}</th>
 | 
			
		||||
                                                    <th style="text-align: center">{% trans "Name" %}</th>
 | 
			
		||||
                                                    <th style="text-align: center">{% trans "Action" %}</th>
 | 
			
		||||
                                                </tr>
 | 
			
		||||
                                                </thead>
 | 
			
		||||
                                                <tbody style="text-align: center">
 | 
			
		||||
                                                {% for fix in fixed_address %}
 | 
			
		||||
                                                    <tr>
 | 
			
		||||
                                                    <form method="post" role="form">{% csrf_token %}
 | 
			
		||||
                                                        <td><label class="form-control" disabled="true">{{ fix.mac }}</label></td>
 | 
			
		||||
                                                        <td><input class="form-control" value="{{ fix.ip }}" name="address" /></td>
 | 
			
		||||
                                                        <td><input class="form-control" value="{{ fix.name }}" name="name" /></td>
 | 
			
		||||
                                                            <td>
 | 
			
		||||
                                                                <input hidden name="mac" value="{{ fix.mac }}"/>
 | 
			
		||||
                                                                <button type="submit" class="btn btn-sm btn-primary"
 | 
			
		||||
                                                                        name="modify_fixed_address"
 | 
			
		||||
                                                                        title="Edit entry" onclick="return confirm('{% trans "Are you sure?" %}')">
 | 
			
		||||
                                                                    <i class="glyphicon glyphicon-save"></i>
 | 
			
		||||
                                                                </button>
 | 
			
		||||
                                                                <button type="submit" class="btn btn-sm btn-danger"
 | 
			
		||||
                                                                        name="delete_fixed_address"
 | 
			
		||||
                                                                        title="Delete entry" onclick="return confirm('{% trans "Are you sure?" %}')">
 | 
			
		||||
                                                                    <i class="glyphicon glyphicon-trash"></i>
 | 
			
		||||
                                                                </button>
 | 
			
		||||
                                                            </td>
 | 
			
		||||
                                                        </form>
 | 
			
		||||
                                                    </tr>
 | 
			
		||||
                                                {% endfor %}
 | 
			
		||||
                                                </tbody>
 | 
			
		||||
                                            </table>
 | 
			
		||||
                                            <input type="button" class="btn btn-default" id="filter_button" value="Filter">
 | 
			
		||||
                                            <button type="button" class="btn btn-default" id="filter_clear">{% trans 'Clear' %}</button>
 | 
			
		||||
                                        </div>
 | 
			
		||||
                                        <table class="table table-hover">
 | 
			
		||||
                                            <thead>
 | 
			
		||||
                                            <tr>
 | 
			
		||||
                                                <th style="text-align: center">{% trans "MAC" %}</th>
 | 
			
		||||
                                                <th style="text-align: center">{% trans "Address" %}</th>
 | 
			
		||||
                                                <th style="text-align: center">{% trans "Name" %}</th>
 | 
			
		||||
                                                <th style="text-align: center">{% trans "Action" %}</th>
 | 
			
		||||
                                            </tr>
 | 
			
		||||
                                            </thead>
 | 
			
		||||
                                            <tbody style="text-align: center">
 | 
			
		||||
                                            {% for fix in fixed_address %}
 | 
			
		||||
                                                <tr>
 | 
			
		||||
                                                <form method="post" role="form">{% csrf_token %}
 | 
			
		||||
                                                    <td><label class="form-control" disabled="true">{{ fix.mac }}</label></td>
 | 
			
		||||
                                                    <td><input class="form-control" value="{{ fix.ip }}" name="address" /></td>
 | 
			
		||||
                                                    <td><input class="form-control" value="{{ fix.name }}" name="name" /></td>
 | 
			
		||||
                                                        <td>
 | 
			
		||||
                                                            <input hidden name="mac" value="{{ fix.mac }}"/>
 | 
			
		||||
                                                            <button type="submit" class="btn btn-sm btn-primary"
 | 
			
		||||
                                                                    name="modify_fixed_address"
 | 
			
		||||
                                                                    title="Edit entry" onclick="return confirm('{% trans "Are you sure?" %}')">
 | 
			
		||||
                                                                <i class="glyphicon glyphicon-save"></i>
 | 
			
		||||
                                                            </button>
 | 
			
		||||
                                                            <button type="submit" class="btn btn-sm btn-danger"
 | 
			
		||||
                                                                    name="delete_fixed_address"
 | 
			
		||||
                                                                    title="Delete entry" onclick="return confirm('{% trans "Are you sure?" %}')">
 | 
			
		||||
                                                                <i class="glyphicon glyphicon-trash"></i>
 | 
			
		||||
                                                            </button>
 | 
			
		||||
                                                        </td>
 | 
			
		||||
                                                    </form>
 | 
			
		||||
                                                </tr>
 | 
			
		||||
                                            {% endfor %}
 | 
			
		||||
                                            </tbody>
 | 
			
		||||
                                        </table>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                {#{% endif %}#}
 | 
			
		||||
                </div>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
{% block script %}
 | 
			
		||||
| 
						 | 
				
			
			@ -230,4 +254,14 @@
 | 
			
		|||
        });
 | 
			
		||||
    });
 | 
			
		||||
</script>
 | 
			
		||||
<script src="{% static "js/ace.js" %}"></script>
 | 
			
		||||
<script>
 | 
			
		||||
    var editor = ace.edit("edit_editor");
 | 
			
		||||
    editor.getSession().setMode("ace/mode/xml");
 | 
			
		||||
 | 
			
		||||
    var edit_input = $('input[name="edit_xml"]');
 | 
			
		||||
    editor.getSession().on("change", function () {
 | 
			
		||||
        edit_input.val(editor.getSession().getValue());
 | 
			
		||||
    });
 | 
			
		||||
</script>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue