1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00

Merge pull request #220 from catborise/master

fix for dhcp fixed address
This commit is contained in:
Anatoliy Guskov 2019-01-28 11:14:24 +02:00 committed by GitHub
commit aea7545030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 335 additions and 243 deletions

View file

@ -136,12 +136,11 @@
{% trans "Resume" %} {% trans "Resume" %}
</a> </a>
</li> </li>
{% else %} <li role="presentation">
<li role="presentation" class="active"> <a href="#powerforce" aria-controls="powerforce" role="tab" data-toggle="tab">
<a href="#resume" aria-controls="resume" role="tab" data-toggle="tab"> {% trans "Force Off" %}
{% trans "Resume" %} </a>
</a> </li>
</li>
{% endif %} {% endif %}
{% endifequal %} {% endifequal %}
{% ifequal status 5 %} {% ifequal status 5 %}
@ -186,19 +185,31 @@
</div> </div>
{% endif %} {% endif %}
{% endifequal %} {% endifequal %}
{% ifequal status 3 %} {% ifequal status 3 %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resume"> {% if request.user.is_superuser %}
<form action="" method="post" role="form">{% csrf_token %} <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resume">
{% if request.user.is_superuser %}
<p>{% trans "This action restore the instance after suspend." %}</p> <p>{% trans "This action restore the instance after suspend." %}</p>
<input type="submit" name="resume" class="btn btn-lg btn-success pull-right" value="{% trans "Resume" %}"> <form action="" method="post" role="form">{% csrf_token %}
{% else %} <input type="submit" name="resume" class="btn btn-lg btn-success pull-right" value="{% trans "Resume" %}">
<div class="clearfix"></div>
</form>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="powerforce">
<p>{% trans "This action forcibly powers off the instance and may cause data corruption." %}</p>
<form action="" method="post" role="form">{% csrf_token %}
<input type="submit" name="powerforce" class="btn btn-lg btn-success pull-right" value="{% trans "Force Off" %}">
<div class="clearfix"></div>
</form>
</div>
{% else %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resume">
<p>{% trans "Administrator blocked your instance." %}</p> <p>{% trans "Administrator blocked your instance." %}</p>
<button class="btn btn-lg btn-success disabled pull-right">{% trans "Resume" %}</button> <form action="" method="post" role="form">{% csrf_token %}
{% endif %} <button class="btn btn-lg btn-success disabled pull-right">{% trans "Resume" %}</button>
<div class="clearfix"></div> <div class="clearfix"></div>
</form> </form>
</div> </div>
{% endif %}
{% endifequal %} {% endifequal %}
{% ifequal status 5 %} {% ifequal status 5 %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="boot"> <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="boot">
@ -605,7 +616,9 @@
<input type="submit" class="btn btn-danger" name="unset_bootmenu" title="Hide boot menu" value="{% trans "Disable" %}"> <input type="submit" class="btn btn-danger" name="unset_bootmenu" title="Hide boot menu" value="{% trans "Disable" %}">
{% endifequal %} {% endifequal %}
{% else %} {% else %}
<p>{% trans "**** Please shutdown instance to modify boot menu ****" %} {% ifequal bootmenu 0 %}
<p>{% trans "**** Please shutdown instance to modify boot menu ****" %}
{% endifequal %}
{% endifequal %} {% endifequal %}
</p> </p>
</div> </div>
@ -713,8 +726,12 @@
{% endif %} {% endif %}
</div> </div>
</form> </form>
{% empty %}
<div class="col-sm-offset-3 col-sm-6">
<div class="well well-sm">{% trans 'There is not any CD-ROM device.' %}</div>
</div>
{% endfor %} {% endfor %}
<div class="clearfix"></div>
<p style="font-weight:bold;"> <p style="font-weight:bold;">
{% trans "Instance Volume" %} {% trans "Instance Volume" %}
{% include 'add_instance_volume.html' %} {% include 'add_instance_volume.html' %}
@ -796,6 +813,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<label>eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label> <label>eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label>
<button class="btn btn-sm pull-right btn-danger" value="{{ network.mac }}" name="delete_network" title="{% trans "Delete Device" %}" onclick="return confirm('{% trans "Are you sure?" %}')">{% trans "Delete" %}</button>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="form-group form-inline"> <div class="form-group form-inline">
@ -810,10 +828,10 @@
<label class="control-label"><em>to</em></label> <label class="control-label"><em>to</em></label>
<select class="form-control" name="net-source-{{ forloop.counter0 }}"> <select class="form-control" name="net-source-{{ forloop.counter0 }}">
{% for c_net in compute_networks %} {% for c_net in compute_networks %}
<option value="net:{{ c_net }}" {% ifequal c_net network.nic %} selected {% endifequal %}>Network {{ c_net }}</option> <option value="net:{{ c_net }}" {% ifequal c_net network.nic %} selected {% endifequal %}>{% trans 'Network' %} {{ c_net }}</option>
{% endfor %} {% endfor %}
{% for c_iface in compute_interfaces %} {% for c_iface in compute_interfaces %}
<option value="iface:{{ c_iface }}" {% ifequal c_iface network.nic %} selected {% endifequal %}>Interface {{ c_iface }}</option> <option value="iface:{{ c_iface }}" {% ifequal c_iface network.nic %} selected {% endifequal %}>{% trans 'Interface' %} {{ c_iface }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -828,18 +846,13 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
</div> <button class="btn btn-sm btn-primary btn-block" name="change_network" title="{% trans "Apply Network Changes" %}">{% trans "Apply" %}</button>
<div class="panel-footer">
<button class="btn btn-sm btn-primary" name="change_network" title="{% trans "Change" %}">{% trans "Change" %}</button>
<button class="btn btn-sm pull-right btn-danger" value="{{ network.mac }}" name="delete_network" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">{% trans "Delete" %}</button>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
</form> </form>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="migrate"> <div role="tabpanel" class="tab-pane tab-pane-bordered" id="migrate">
<p>{% trans "For migration both host servers must have equal settings and OS type" %}</p> <p>{% trans "For migration both host servers must have equal settings and OS type" %}</p>
@ -1201,7 +1214,7 @@
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="graphs"> <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="graphs">
<div class="panel panel-success"> <div class="panel panel-success">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-long-arrow-right"></i> {% trans "CPU usage" %}</h3> <h3 class="panel-title"><i class="fa fa-long-arrow-right"></i> {% trans "CPU Usage" %}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="flot-chart"> <div class="flot-chart">
@ -1214,7 +1227,7 @@
{% for net in networks %} {% for net in networks %}
<div class="panel panel-info"> <div class="panel panel-info">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-long-arrow-right"></i> {% trans "Bandwidth device:" %} eth{{ forloop.counter0 }}</h3> <h3 class="panel-title"><i class="fa fa-long-arrow-right"></i> {% trans "Bandwidth Device" %}: eth{{ forloop.counter0 }}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="flot-chart"> <div class="flot-chart">
@ -1228,7 +1241,7 @@
{% for disk in disks %} {% for disk in disks %}
<div class="panel panel-warning"> <div class="panel panel-warning">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-long-arrow-right"></i> {% trans "Disk I/O device:" %} {{ disk.dev }}</h3> <h3 class="panel-title"><i class="fa fa-long-arrow-right"></i> {% trans "Disk I/O device" %}: {{ disk.dev }}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="flot-chart"> <div class="flot-chart">

View file

@ -622,6 +622,11 @@ def instance(request, compute_id, vname):
order_list[idx] = {"type": type, "dev": dev} order_list[idx] = {"type": type, "dev": dev}
conn.set_bootorder(order_list) conn.set_bootorder(order_list)
msg = _("Set boot order") msg = _("Set boot order")
if not conn.get_status() == 5:
messages.success(request, _("Boot menu changes applied. But it will be activated after shutdown"))
else:
messages.success(request, _("Boot order changed successfully."))
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#boot_opt') return HttpResponseRedirect(request.get_full_path() + '#boot_opt')

View file

@ -1,5 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Network" %} - {{ pool }}{% endblock %} {% block title %}{% trans "Network" %} - {{ pool }}{% endblock %}
{% block content %} {% block content %}
<!-- Page Heading --> <!-- Page Heading -->
@ -38,10 +39,10 @@
<div class="row"> <div class="row">
<div class="col-xs-6 col-sm-4"> <div class="col-xs-6 col-sm-4">
<p>{% trans "Network name:" %}</p> <p>{% trans "Network name" %}:</p>
<p>{% trans "Device:" %}</p> <p>{% trans "Device" %}:</p>
<p>{% trans "State" %}</p> <p>{% trans "State" %}:</p>
<p>{% trans "Autostart" %}</p> <p>{% trans "Autostart" %}:</p>
</div> </div>
<div class="col-xs-6 col-sm-6"> <div class="col-xs-6 col-sm-6">
<p>{{ pool }}</p> <p>{{ pool }}</p>
@ -67,11 +68,35 @@
</p> </p>
</div> </div>
</div> </div>
{#{% if state %}#} <div class="row">
<div class="row"> <h3 class="page-header"></h3>
<h3 class="page-header">{% trans "IPv4 Configuration" %}</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>
<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"> <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>
@ -122,75 +147,74 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% ifequal ipv4_forward.0 'nat' %} {% ifequal ipv4_forward.0 'nat' %}
{% if state %} {% if state %}
{% include 'modify_fixed_address.html' %} {% include 'modify_fixed_address.html' %}
{% endif %} {% endif %}
<div class="row"> <div class="row">
<h3 class="page-header">{% trans "Fixed Address" %}</h3> <h3 class="page-header">{% trans "Fixed Address" %}</h3>
</div> </div>
{% endifequal %} {% endifequal %}
{% if fixed_address %} {% if fixed_address %}
<div class="row"> <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="#collapseTwo">
{% trans 'Show' %} {% trans 'Show' %}
</a> </a>
</div> </div>
<div id="collapseOne" class="panel-collapse collapse"> <div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body"> <div class="panel-body">
<div class="input-append form-inline pull-right"> <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>
<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> </div>
<table class="table table-hover"> <input type="button" class="btn btn-default" id="filter_button" value="Filter">
<thead> <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> <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 %} <form method="post" role="form">{% csrf_token %}
<td><label class="form-control" disabled="true">{{ fix.mac }}</label></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.ip }}" name="address" /></td>
<td><input class="form-control" value="{{ fix.name }}" name="name" /></td> <td><input class="form-control" value="{{ fix.name }}" name="name" /></td>
<td> <td>
<input hidden name="mac" value="{{ fix.mac }}"/> <input hidden name="mac" value="{{ fix.mac }}"/>
<button type="submit" class="btn btn-sm btn-primary" <button type="submit" class="btn btn-sm btn-primary"
name="modify_fixed_address" name="modify_fixed_address"
title="Edit entry" onclick="return confirm('{% trans "Are you sure?" %}')"> title="Edit entry" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="glyphicon glyphicon-save"></i> <i class="glyphicon glyphicon-save"></i>
</button> </button>
<button type="submit" class="btn btn-sm btn-danger" <button type="submit" class="btn btn-sm btn-danger"
name="delete_fixed_address" name="delete_fixed_address"
title="Delete entry" onclick="return confirm('{% trans "Are you sure?" %}')"> title="Delete entry" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="glyphicon glyphicon-trash"></i> <i class="glyphicon glyphicon-trash"></i>
</button> </button>
</td> </td>
</form> </form>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{#{% endif %}#} </div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block script %} {% block script %}
@ -230,4 +254,14 @@
}); });
}); });
</script> </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 %} {% endblock %}

View file

@ -88,6 +88,7 @@ def network(request, compute_id, pool):
ipv4_dhcp_range_end = conn.get_ipv4_dhcp_range_end() ipv4_dhcp_range_end = conn.get_ipv4_dhcp_range_end()
ipv4_network = conn.get_ipv4_network() ipv4_network = conn.get_ipv4_network()
fixed_address = conn.get_mac_ipaddr() fixed_address = conn.get_mac_ipaddr()
xml = conn._XMLDesc(0)
except libvirtError as lib_err: except libvirtError as lib_err:
error_messages.append(lib_err) error_messages.append(lib_err)
@ -139,7 +140,6 @@ def network(request, compute_id, pool):
conn.delete_fixed_address(mac) conn.delete_fixed_address(mac)
messages.success(request, "Fixed Address is Deleted.") messages.success(request, "Fixed Address is Deleted.")
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'modify_dhcp_range' in request.POST: if 'modify_dhcp_range' in request.POST:
range_start = request.POST.get('range_start', '') range_start = request.POST.get('range_start', '')
range_end = request.POST.get('range_end', '') range_end = request.POST.get('range_end', '')
@ -149,6 +149,22 @@ 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 '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() conn.close()

View file

@ -0,0 +1,33 @@
{% load i18n %}
{% if request.user.is_superuser %}
<a href="#AddNWFilterRule" type="button" class="btn btn-success pull-right" data-toggle="modal">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<!-- Modal Secret -->
<div class="modal fade" id="AddNWFilterRule" tabindex="-1" role="dialog" aria-labelledby="AddNWFilterRule" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Add New NWFilter Rule" %}</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<div class="col-xs-12" id="xmlheight">
<input type="hidden" name="nwfilterrule_xml"/>
<textarea id="rule_editor"></textarea>
</div>
<p><small><em>{% trans 'If there is a rule which has same attributes it replaces that rule' %}...</em></small></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary" name="add_nwfilter_rule">{% trans "Add" %}</button>
</div>
</form>
</div> <!-- /.modal-content -->
</div>
</div> <!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endif %}

View file

@ -6,7 +6,6 @@
<!-- Page Heading --> <!-- Page Heading -->
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
{% include 'create_nwfilter_block.html' %}
<h1 class="page-header">{% trans "NWFilter:" %} {{ name }}</h1> <h1 class="page-header">{% trans "NWFilter:" %} {{ name }}</h1>
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="active"> <li class="active">
@ -38,152 +37,126 @@
{% include 'errors_block.html' %} {% include 'errors_block.html' %}
{% include 'messages_block.html' %} {% include 'messages_block.html' %}
<div class="row">
<div class="col-xs-6 col-sm-4">
<p>{% trans "UUID:" %}</p>
<p>{% trans "Name:" %}</p>
</div>
<div class="col-xs-6 col-sm-8">
<p>{{ uuid }}</p>
<p>{{ name }}</p>
</div>
</div>
<div class="row"> <div class="row">
<p><strong>{% trans "XML:" %}</strong></p> <div class="col-xs-6 col-sm-4">
<form class="form-inline" method="post" role="form">{% csrf_token %} <p>{% trans "UUID:" %}</p>
<div class="col-xs-12" id="xmlheight"> <p>{% trans "Name:" %}</p>
<input type="hidden" name="edit_xml"/> </div>
<textarea id="edit_editor">{{ xml }}</textarea> <div class="col-xs-6 col-sm-8">
</div> <p>{{ uuid }}</p>
<button type="submit" class="btn btn-primary pull-right" name="edit_nwfilter"> <p>{{ name }}</p>
{% trans "Edit" %} </div>
</button>
</form>
</div> </div>
<div class="row"> <div class="row">
<p><strong>{% trans "Filter References:" %}</strong></p> <h3 class="page-header"></h3>
<form class="form-inline pull-right" method="post" role="form">{% csrf_token %} </div>
<div class="form-group"> <div class="panel-group" id="accordion">
<label>{% trans "Filter:" %}</label> <div class="panel panel-default">
<select id="nwfilter_select" name="nwfilters_select" class="form-control"> <div class="panel-heading">
<option value="" selected>None</option> <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
{% for nwf in nwfilters_all %} {% trans 'XML' %}
<option value="{{ nwf.name }}">{{ nwf.name }}</option> </a>
{% endfor %}
</select>
<button type="submit" class="btn btn-success pull-right" name="add_nwfilter_ref">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</div> </div>
</form> <div id="collapseOne" class="panel-collapse collapse">
<div class="panel-body">
</div> <form class="form-inline" method="post" role="form">{% csrf_token %}
<div class="row"> <div class="col-xs-12" id="xmlheight">
<div class="table-responsive"> <input type="hidden" name="edit_xml"/>
<table class="table table-striped"> <textarea id="edit_editor">{{ xml }}</textarea>
<thead> </div>
<tr> <button type="submit" class="btn btn-primary pull-right" name="edit_nwfilter">
<th style="width: 45px;">#</th> {% trans "Edit" %}
<th>{% trans "Reference" %}</th> </button>
<th colspan="3">{% trans "Action" %}</th>
</tr>
</thead>
<tbody>
{% for ref in refs %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ ref }}</td>
<td style="width:30px;">
<form action="" method="post" style="height:10px" role="form">{% csrf_token %}
<input type="hidden" name="ref" value="{{ ref }}">
<button type="submit" class="btn btn-sm btn-default" name="del_nwfilter_ref" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="row">
<p><strong>{% trans "Rules:" %}</strong></p>
<a href="#AddNWFilterRule" type="button" class="btn btn-success pull-right" data-toggle="modal">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<!-- Modal Secret -->
<div class="modal fade" id="AddNWFilterRule" tabindex="-1" role="dialog" aria-labelledby="AddNWFilterRule" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Add New NWFilter Rule" %}</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<div class="col-xs-12" id="xmlheight">
<input type="hidden" name="nwfilterrule_xml"/>
<textarea id="rule_editor"></textarea>
</div>
<p><small><em>If there is a rule which has same attributes it replaces that rule...</em></small></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary" name="add_nwfilter_rule">{% trans "Add" %}</button>
</div>
</form> </form>
</div> <!-- /.modal-content --> </div>
</div> </div>
</div> <!-- /.modal-dialog --> </div>
</div><!-- /.modal -->
</div> </div>
<form class="form-inline pull-right" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label>{% trans "Filter" %}:</label>
<select id="nwfilter_select" name="nwfilters_select" class="form-control">
<option value="" selected>{% trans 'None' %}</option>
{% for nwf in nwfilters_all %}
<option value="{{ nwf.name }}">{{ nwf.name }}</option>
{% endfor %}
</select>
<button type="submit" class="btn btn-success pull-right" name="add_nwfilter_ref">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</div>
</form>
<div class="row"> <div class="row">
<div class="table-responsive"> <h3 class="page-header">{% trans "Filter References" %}</h3>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 45px;">{% trans "Rule" %}</th>
<th>{% trans "ActionType" %}</th>
<th>{% trans "Direction" %}</th>
<th>{% trans "Priority" %}</th>
<th>{% trans "Statematch" %}</th>
<th>{% trans "Directives" %}</th>
<th colspan="3">{% trans "Action" %}</th>
</tr>
</thead>
<tbody>
{% for rule in rules %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ rule.action }}</td>
<td>{{ rule.direction }}</td>
<td>{{ rule.priority }}</td>
<td>{{ rule.statematch }}</td>
<td>{{ rule.directives }}</td>
<td style="width:30px;">
<form action="" method="post" style="height:10px" role="form">{% csrf_token %}
<input type="hidden" name="action" value="{{ rule.action }}">
<input type="hidden" name="direction" value="{{ rule.direction }}">
<input type="hidden" name="priority" value="{{ rule.priority }}">
<button type="submit" class="btn btn-sm btn-default" name="del_nwfilter_rule" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div> </div>
<div class="col-xs-12 col-sm-12">
<table class="table table-hover">
<thead>
<th style="width: 45px;">#</th>
<th>{% trans "Reference" %}</th>
<th>{% trans "Action" %}</th>
</thead>
<tbody>
{% for ref in refs %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ ref }}</td>
<td style="width:30px;">
<form action="" method="post" role="form">{% csrf_token %}
<input type="hidden" name="ref" value="{{ ref }}">
<button type="submit" class="btn btn-sm btn-default" name="del_nwfilter_ref" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% include 'add_nwf_rule.html' %}
<div class="row">
<h3 class="page-header">{% trans "Rules" %}</h3>
</div>
<div class="col-xs-12 col-sm-12">
<table class="table table-hover">
<thead>
<th style="width:45px;">{% trans "Rule" %}</th>
<th>{% trans "ActionType" %}</th>
<th>{% trans "Direction" %}</th>
<th>{% trans "Priority" %}</th>
<th>{% trans "Statematch" %}</th>
<th>{% trans "Directives" %}</th>
<th style="width:100px;">{% trans "Action" %}</th>
</thead>
<tbody>
{% for rule in rules %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ rule.action }}</td>
<td>{{ rule.direction }}</td>
<td>{{ rule.priority }}</td>
<td>{{ rule.statematch }}</td>
<td>{{ rule.directives }}</td>
<td>
<form action="" method="post" role="form">{% csrf_token %}
<input type="hidden" name="action" value="{{ rule.action }}">
<input type="hidden" name="direction" value="{{ rule.direction }}">
<input type="hidden" name="priority" value="{{ rule.priority }}">
<button type="submit" class="btn btn-sm btn-default" name="del_nwfilter_rule" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %} {% endblock %}
{% block script %} {% block script %}
@ -209,7 +182,7 @@
var edit_input = $('input[name="edit_xml"]'); var edit_input = $('input[name="edit_xml"]');
editor.getSession().on("change",function () { editor.getSession().on("change",function () {
edit_input.val(editor.getSession().getValue()); edit_input.val(editor.getSession().getValue());
}) });
var rule_editor = ace.edit("rule_editor"); var rule_editor = ace.edit("rule_editor");
rule_editor.getSession().setMode("ace/mode/xml"); rule_editor.getSession().setMode("ace/mode/xml");
@ -217,7 +190,7 @@
var rule_input = $('input[name="nwfilterrule_xml"]'); var rule_input = $('input[name="nwfilterrule_xml"]');
rule_editor.getSession().on("change",function () { rule_editor.getSession().on("change",function () {
rule_input.val(rule_editor.getSession().getValue()); rule_input.val(rule_editor.getSession().getValue());
}) });
</script> </script>
{% endblock %} {% endblock %}

View file

@ -40,12 +40,12 @@
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<div class="row">
<div class="pull-right">
<input id="filter" class="form-control" type="text" placeholder="Search">
</div>
<h3 class="page-header">{% trans "NWFilters" %}</h3>
<div class="pull-right">
<input id="filter" class="form-control" type="text" placeholder="Search">
</div>
<div class="row">
<h3 class="page-header">{% trans "NWFilters" %}</h3>
</div> </div>
{% if nwfilters %} {% if nwfilters %}
<div class="table-responsive"> <div class="table-responsive">
@ -166,6 +166,4 @@
input.val(editor.getSession().getValue()); input.val(editor.getSession().getValue());
}) })
</script> </script>
{% endblock %} {% endblock %}

View file

@ -986,6 +986,21 @@ class wvmInstance(wvmConnect):
source.set('bridge', bridge_name) source.set('bridge', bridge_name)
source = interface.find('filterref') source = interface.find('filterref')
if net_filter:
if source is not None: source.set('filter', net_filter)
else:
element = ElementTree.Element("filterref")
element.attrib['filter'] = net_filter
interface.append(element)
else:
if source is not None: interface.remove(source)
elif interface.get('type') == 'network':
source = interface.find('mac')
source.set('address', net_mac)
source = interface.find('source')
source.set('network', net_source)
source = interface.find('filterref')
if net_filter: if net_filter:
if source is not None: source.set('filter', net_filter) if source is not None: source.set('filter', net_filter)
else: else:

View file

@ -2,7 +2,7 @@ from vrtManager import util
from vrtManager.IPy import IP from vrtManager.IPy import IP
from vrtManager.connection import wvmConnect from vrtManager.connection import wvmConnect
from xml.etree import ElementTree 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_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 from libvirt import VIR_NETWORK_UPDATE_AFFECT_LIVE, VIR_NETWORK_UPDATE_AFFECT_CONFIG
@ -178,7 +178,9 @@ class wvmNetwork(wvmConnect):
for net in doc.xpath('/network/ip/dhcp/host'): for net in doc.xpath('/network/ip/dhcp/host'):
ip = net.xpath('@ip')[0] ip = net.xpath('@ip')[0]
mac = net.xpath('@mac')[0] mac = net.xpath('@mac')[0]
name = net.xpath('@name')[0] name = net.xpath('@name')
name = name[0] if name else ""
result.append({'ip': ip, 'mac': mac, 'name': name}) result.append({'ip': ip, 'mac': mac, 'name': name})
return result return result
@ -186,7 +188,10 @@ class wvmNetwork(wvmConnect):
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)) if name:
new_xml = '<host mac="{}" name="{}" ip="{}"/>'.format(mac, name, IP(address))
else:
new_xml = '<host mac="{}" ip="{}"/>'.format(mac, IP(address))
new_host_xml = ElementTree.fromstring(new_xml) new_host_xml = ElementTree.fromstring(new_xml)
tree = ElementTree.fromstring(self._XMLDesc(0)) tree = ElementTree.fromstring(self._XMLDesc(0))