mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +00:00
Add Fixed Network Address operations. Add Modify dhcp range for stopped networks.
This commit is contained in:
parent
b812a05cdc
commit
bd63e3e4e6
3 changed files with 85 additions and 16 deletions
|
@ -34,6 +34,7 @@
|
|||
<!-- /.row -->
|
||||
|
||||
{% include 'errors_block.html' %}
|
||||
{% include 'messages_block.html' %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-6 col-sm-4">
|
||||
|
@ -66,9 +67,11 @@
|
|||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% if state %}
|
||||
{#{% if state %}#}
|
||||
<div class="row">
|
||||
<h3 class="page-header">{% trans "IPv4 Configuration" %}</h3>
|
||||
</div>
|
||||
<div class="row">
|
||||
<h3 class="page-header">{% trans "IPv4 configuration" %}</h3>
|
||||
<div class="col-xs-6 col-sm-4">
|
||||
<p>{% trans "IPv4 Forwarding:" %}</p>
|
||||
<p>{% trans "Network:" %}</p>
|
||||
|
@ -102,43 +105,81 @@
|
|||
{% endif %}
|
||||
</p>
|
||||
{% if ipv4_dhcp_range_start and ipv4_dhcp_range_end %}
|
||||
<form method="post" role="form">{% csrf_token %}
|
||||
{% if state %}
|
||||
<p>{{ ipv4_dhcp_range_start }}</p>
|
||||
<p>{{ ipv4_dhcp_range_end }}</p>
|
||||
{% else %}
|
||||
<p><input name="range_start" value="{{ ipv4_dhcp_range_start }}"/></p>
|
||||
<p><input name="range_end" value="{{ ipv4_dhcp_range_end }}"/></p>
|
||||
<div class="col-xs-10 col-sm-8">
|
||||
<input type="submit" class="btn btn-primary btn-block" value="Apply"
|
||||
name="modify_dhcp_range"
|
||||
title="Edit DHCP Range" onclick="return confirm('{% trans "Are you sure?" %}')"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% if fixed_address %}
|
||||
{% 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">
|
||||
Show
|
||||
{% trans 'Show' %}
|
||||
</a>
|
||||
</div>
|
||||
<div id="collapseOne" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<div class="input-append form-inline pull-right" style="">
|
||||
|
||||
<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">Clear</button>
|
||||
<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 "Address" %}</th>
|
||||
<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>
|
||||
<td>{{ fix.host }}</td>
|
||||
<td>{{ fix.mac }}</td>
|
||||
<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>
|
||||
|
@ -149,7 +190,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{#{% endif %}#}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block script %}
|
||||
|
@ -175,7 +216,6 @@
|
|||
$('tbody tr:not(:Contains(\'' + filter_val + '\'))').hide();
|
||||
}
|
||||
});
|
||||
|
||||
// add event button labeled "clear"
|
||||
$('#filter_clear').click(function (event) {
|
||||
$('#filter_input').val('');
|
||||
|
|
|
@ -8,6 +8,7 @@ from networks.forms import AddNetPool
|
|||
from vrtManager.network import wvmNetwork, wvmNetworks
|
||||
from vrtManager.network import network_size
|
||||
from libvirt import libvirtError
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -121,6 +122,33 @@ def network(request, compute_id, pool):
|
|||
return HttpResponseRedirect(request.get_full_path())
|
||||
except libvirtError as lib_err:
|
||||
error_messages.append(lib_err.message)
|
||||
if 'modify_fixed_address' in request.POST:
|
||||
name = request.POST.get('name', '')
|
||||
address = request.POST.get('address', '')
|
||||
mac = request.POST.get('mac', '')
|
||||
try:
|
||||
ret_val = conn.modify_fixed_address(name, address, mac)
|
||||
messages.success(request, "Fixed Address Operation Completed.")
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
except libvirtError as lib_err:
|
||||
error_messages.append(lib_err.message)
|
||||
except ValueError as val_err:
|
||||
error_messages.append(val_err.message)
|
||||
if 'delete_fixed_address' in request.POST:
|
||||
mac = request.POST.get('mac', '')
|
||||
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', '')
|
||||
try:
|
||||
conn.modify_dhcp_range(range_start, range_end)
|
||||
messages.success(request, "DHCP Range is Changed.")
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
except libvirtError as lib_err:
|
||||
error_messages.append(lib_err.message)
|
||||
|
||||
conn.close()
|
||||
|
||||
|
|
|
@ -176,9 +176,10 @@ class wvmNetwork(wvmConnect):
|
|||
def network(doc):
|
||||
result = []
|
||||
for net in doc.xpath('/network/ip/dhcp/host'):
|
||||
host = net.xpath('@ip')[0]
|
||||
ip = net.xpath('@ip')[0]
|
||||
mac = net.xpath('@mac')[0]
|
||||
result.append({'host': host, 'mac': mac})
|
||||
name = net.xpath('@name')[0]
|
||||
result.append({'ip': ip, 'mac': mac, 'name': name})
|
||||
return result
|
||||
|
||||
return util.get_xml_path(self._XMLDesc(0), func=network)
|
||||
|
|
Loading…
Reference in a new issue