mirror of
https://github.com/retspen/webvirtcloud
synced 2025-01-12 08:25:18 +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 -->
|
<!-- /.row -->
|
||||||
|
|
||||||
{% include 'errors_block.html' %}
|
{% include 'errors_block.html' %}
|
||||||
|
{% include 'messages_block.html' %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-6 col-sm-4">
|
<div class="col-xs-6 col-sm-4">
|
||||||
|
@ -66,9 +67,11 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if state %}
|
{#{% if state %}#}
|
||||||
|
<div class="row">
|
||||||
|
<h3 class="page-header">{% trans "IPv4 Configuration" %}</h3>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h3 class="page-header">{% trans "IPv4 configuration" %}</h3>
|
|
||||||
<div class="col-xs-6 col-sm-4">
|
<div class="col-xs-6 col-sm-4">
|
||||||
<p>{% trans "IPv4 Forwarding:" %}</p>
|
<p>{% trans "IPv4 Forwarding:" %}</p>
|
||||||
<p>{% trans "Network:" %}</p>
|
<p>{% trans "Network:" %}</p>
|
||||||
|
@ -102,43 +105,81 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% if ipv4_dhcp_range_start and ipv4_dhcp_range_end %}
|
{% if ipv4_dhcp_range_start and ipv4_dhcp_range_end %}
|
||||||
<p>{{ ipv4_dhcp_range_start }}</p>
|
<form method="post" role="form">{% csrf_token %}
|
||||||
<p>{{ ipv4_dhcp_range_end }}</p>
|
{% 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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if fixed_address %}
|
{% ifequal ipv4_forward.0 'nat' %}
|
||||||
|
{% if state %}
|
||||||
|
{% include 'modify_fixed_address.html' %}
|
||||||
|
{% endif %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h3 class="page-header">{% trans "Fixed Address" %}</h3>
|
<h3 class="page-header">{% trans "Fixed Address" %}</h3>
|
||||||
|
</div>
|
||||||
|
{% endifequal %}
|
||||||
|
{% if fixed_address %}
|
||||||
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div class="panel-group" id="accordion">
|
<div class="panel-group" id="accordion">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||||
Show
|
{% trans 'Show' %}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="collapseOne" class="panel-collapse collapse">
|
<div id="collapseOne" class="panel-collapse collapse">
|
||||||
<div class="panel-body">
|
<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">
|
<div class="form-group">
|
||||||
<input type="text" class="form-control" id="filter_input">
|
<input type="text" class="form-control" id="filter_input">
|
||||||
</div>
|
</div>
|
||||||
<input type="button" class="btn btn-default" id="filter_button" value="Filter">
|
<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>
|
</div>
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="text-align: center">{% trans "Address" %}</th>
|
|
||||||
<th style="text-align: center">{% trans "MAC" %}</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>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody style="text-align: center">
|
<tbody style="text-align: center">
|
||||||
{% for fix in fixed_address %}
|
{% for fix in fixed_address %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ fix.host }}</td>
|
<form method="post" role="form">{% csrf_token %}
|
||||||
<td>{{ fix.mac }}</td>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -149,7 +190,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{#{% endif %}#}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block script %}
|
{% block script %}
|
||||||
|
@ -175,7 +216,6 @@
|
||||||
$('tbody tr:not(:Contains(\'' + filter_val + '\'))').hide();
|
$('tbody tr:not(:Contains(\'' + filter_val + '\'))').hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// add event button labeled "clear"
|
// add event button labeled "clear"
|
||||||
$('#filter_clear').click(function (event) {
|
$('#filter_clear').click(function (event) {
|
||||||
$('#filter_input').val('');
|
$('#filter_input').val('');
|
||||||
|
|
|
@ -8,6 +8,7 @@ from networks.forms import AddNetPool
|
||||||
from vrtManager.network import wvmNetwork, wvmNetworks
|
from vrtManager.network import wvmNetwork, wvmNetworks
|
||||||
from vrtManager.network import network_size
|
from vrtManager.network import network_size
|
||||||
from libvirt import libvirtError
|
from libvirt import libvirtError
|
||||||
|
from django.contrib import messages
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -121,6 +122,33 @@ def network(request, compute_id, pool):
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err.message)
|
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()
|
conn.close()
|
||||||
|
|
||||||
|
|
|
@ -176,13 +176,14 @@ class wvmNetwork(wvmConnect):
|
||||||
def network(doc):
|
def network(doc):
|
||||||
result = []
|
result = []
|
||||||
for net in doc.xpath('/network/ip/dhcp/host'):
|
for net in doc.xpath('/network/ip/dhcp/host'):
|
||||||
host = net.xpath('@ip')[0]
|
ip = net.xpath('@ip')[0]
|
||||||
mac = net.xpath('@mac')[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 result
|
||||||
|
|
||||||
return util.get_xml_path(self._XMLDesc(0), func=network)
|
return util.get_xml_path(self._XMLDesc(0), func=network)
|
||||||
|
|
||||||
def modify_fixed_address(self, name, address, mac):
|
def modify_fixed_address(self, name, address, mac):
|
||||||
util.validate_macaddr(mac)
|
util.validate_macaddr(mac)
|
||||||
new_xml = '<host mac="{}" name="{}" ip="{}"/>'.format(mac, name, IP(address))
|
new_xml = '<host mac="{}" name="{}" ip="{}"/>'.format(mac, name, IP(address))
|
||||||
|
|
Loading…
Reference in a new issue