1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

instance network revamped. Qos config for instance net is added

This commit is contained in:
catborise 2019-11-20 08:37:59 +03:00
parent 718388ffef
commit ddd3dd5f65
4 changed files with 314 additions and 90 deletions

View file

@ -851,53 +851,139 @@
</p>
<div class="col-xs-12 col-sm-12">
<form method="post" role="form">{% csrf_token %}
{% for network in networks %}
{% if forloop.first %}
<p><strong>{% trans "Network Devices" %}</strong></p>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
<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 class="panel-body">
<div class="form-group form-inline">
<label class="col-sm-2 col-sm-offset-1 control-label">{% trans "MAC" %} </label>
<input class="form-control" type="text" value="{{ network.mac }}" readonly/>
<label class="control-label"><em>to</em></label>
<input class="form-control" type="text" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
</div>
<div class="form-group form-inline">
<label class="col-sm-2 col-sm-offset-1 control-label">{% trans "NIC" %} </label>
<input class="form-control" type="text" value="{{ network.nic }}" readonly/>
<label class="control-label"><em>to</em></label>
<select class="form-control" name="net-source-{{ forloop.counter0 }}">
{% for c_net in networks_host %}
<option value="net:{{ c_net }}" {% ifequal c_net network.nic %} selected {% endifequal %}>{% trans 'Network' %} {{ c_net }}</option>
{% endfor %}
{% for c_iface in interfaces_host %}
<option value="iface:{{ c_iface }}" {% ifequal c_iface network.nic %} selected {% endifequal %}>{% trans 'Interface' %} {{ c_iface }}</option>
{% endfor %}
</select>
</div>
<div class="form-group form-inline">
<label class="col-sm-2 col-sm-offset-1">{% trans "Filter" %} </label>
<input class="form-control" type="text" value="{{ network.filterref }}" readonly/>
<label class="control-label"><em>to</em></label>
<select class="form-control" name="net-nwfilter-{{ forloop.counter0 }}">
<option value="">{% trans "None" %}</option>
{% for c_filters in nwfilters_host %}
<option value="{{ c_filters }}" {% ifequal c_filters network.filterref %} selected {% endifequal %}>{{ c_filters }}</option>
{% endfor %}
</select>
</div>
<button class="btn btn-sm btn-primary btn-block" name="change_network" title="{% trans "Apply Network Changes" %}">{% trans "Apply" %}</button>
</div>
</div>
{% endfor %}
</form>
<p><strong>{% trans "Network Devices" %}</strong></p>
<table class="table table-hover">
<thead>
<tr>
<th>{% trans 'Name' %}</th>
<th>{% trans 'MAC' %}</th>
<th>{% trans 'NIC' %}</th>
<th>{% trans 'Filter' %}</th>
<th>{% trans 'Actions' %}</th>
</tr>
</thead>
<tbody>
{% for network in networks %}
<tr>
<td class="col-sm-2"><label>eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label></td>
<td><input class="form-control" type="text" value="{{ network.mac }}" readonly/></td>
<td><input class="form-control" type="text" value="{{ network.nic }}" readonly/></td>
<td><input class="form-control" type="text" value="{{ network.filterref }}" readonly/></td>
<td class="col-sm-2">
<form class="form-horizontal" method="post" name="set_qos{{ forloop.counter0 }}" role="form">{% csrf_token %}
<button data-target="#editInstanceNetwork{{ forloop.counter0 }}" type="button" class="btn btn-sm btn-primary"
title="Edit NIC" data-toggle="modal">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>
<div class="modal fade" id="editInstanceNetwork{{ forloop.counter0 }}" role="dialog" aria-labelledby="editInstanceNetworkLabel" 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 "Edit Instance Network" %}</h4>
</div>
<div class="modal-body">
<div class="form-group form-inline">
<label class="col-sm-2 control-label">{% trans "MAC" %} </label>
<input class="form-control" type="text" value="{{ network.mac }}" readonly/>
<label class="control-label"><em>to</em></label>
<input class="form-control" type="text" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
</div>
<div class="form-group form-inline">
<label class="col-sm-2 control-label">{% trans "NIC" %} </label>
<input class="form-control" type="text" value="{{ network.nic }}" readonly/>
<label class="control-label"><em>to</em></label>
<select class="form-control" name="net-source-{{ forloop.counter0 }}">
{% for c_net in networks_host %}
<option value="net:{{ c_net }}" {% ifequal c_net network.nic %} selected {% endifequal %}>{% trans 'Network' %} {{ c_net }}</option>
{% endfor %}
{% for c_iface in interfaces_host %}
<option value="iface:{{ c_iface }}" {% ifequal c_iface network.nic %} selected {% endifequal %}>{% trans 'Interface' %} {{ c_iface }}</option>
{% endfor %}
</select>
</div>
<div class="form-group form-inline">
<label class="col-sm-2 control-label">{% trans "Filter" %} </label>
<input class="form-control" type="text" value="{{ network.filterref }}" readonly/>
<label class="control-label"><em>to</em></label>
<select class="form-control" name="net-nwfilter-{{ forloop.counter0 }}">
<option value="">{% trans "None" %}</option>
{% for c_filters in nwfilters_host %}
<option value="{{ c_filters }}" {% ifequal c_filters network.filterref %} selected {% endifequal %}>{{ c_filters }}</option>
{% endfor %}
</select>
</div>
<button class="btn btn-sm btn-primary btn-block" name="change_network" title="{% trans "Apply Network Changes" %}">{% trans "Apply" %}</button>
</div>
</div>
</div>
</div>
<button class="btn btn-sm btn-danger" value="{{ network.mac }}" name="delete_network" title="{% trans "Delete Device" %}"
onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="glyphicon glyphicon-trash"></i>
</button>
{% include 'add_network_qos.html' with id=forloop.counter0 %}
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if qos %}
<div class="col-xs-10 col-sm-10">
<p><strong>{% trans "Qos Configuration" %}</strong></p>
</div>
<div class="col-xs-12 col-sm-12">
<table class="table table-hover">
<thead>
<tr>
<th>{% trans "Direction" %}</th>
<th>{% trans "Average" %}</th>
<th>{% trans "Peak" %}</th>
<th>{% trans "Burst" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
{% for q, attrs in qos.items %}
{% for att in attrs %}
<form method="post" role="form">{% csrf_token %}
<tr>
<td><label class="control-label">{{ q }} {{ att.direction | capfirst }}</label></td>
<td><input id="qos_average" class="form-control" name="qos_average"
value="{{ att.average|default:'' }}"/></td>
<td><input id="qos_peak" class="form-control" name="qos_peak"
value="{{ att.peak|default:'' }}"/></td>
<td><input id="qos_burst" class="form-control" name="qos_burst"
value="{{ att.burst|default:'' }}"/></td>
<td class="col-sm-2">
<input name="qos_direction" value="{{ att.direction }}" hidden/>
<input name="net-mac" value="{{ q }}" hidden/>
<button type="submit" class="btn btn-sm btn-primary"
name="set_qos" data-toggle="modal"
title="Edit Qos" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="glyphicon glyphicon-save"></i>
</button>
<button type="submit" class="btn btn-sm btn-danger"
name="unset_qos"
title="Delete Qos" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="glyphicon glyphicon-trash"></i>
</button>
</td>
</tr>
</form>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="migrate">

View file

@ -272,6 +272,7 @@ def instance(request, compute_id, vname):
title = conn.get_title()
description = conn.get_description()
networks = conn.get_net_device()
qos = conn.get_all_qos()
disks = conn.get_disk_devices()
media = conn.get_media_devices()
if len(media) != 0:
@ -482,8 +483,9 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#resize')
if 'resizevm_mem' in request.POST and (
request.user.is_superuser or request.user.is_staff or userinstance.is_change):
if 'resizevm_mem' in request.POST and (request.user.is_superuser or
request.user.is_staff or
userinstance.is_change):
new_memory = request.POST.get('memory', '')
new_memory_custom = request.POST.get('memory_custom', '')
if new_memory_custom:
@ -699,7 +701,8 @@ def instance(request, compute_id, vname):
msg = _("Set boot order")
if not conn.get_status() == 5:
messages.success(request, _("Boot menu changes applied. But it will be activated after shutdown"))
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)
@ -727,7 +730,8 @@ def instance(request, compute_id, vname):
error_messages.append(msg)
if not error_messages:
if not conn.set_console_passwd(passwd):
msg = _("Error setting console password. You should check that your instance have an graphic device.")
msg = _("Error setting console password. " +
"You should check that your instance have an graphic device.")
error_messages.append(msg)
else:
msg = _("Set VNC password")
@ -808,6 +812,40 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#network')
if 'set_qos' in request.POST:
qos_dir = request.POST.get('qos_direction', '')
average = request.POST.get('qos_average') or 0
peak = request.POST.get('qos_peak') or 0
burst = request.POST.get('qos_burst') or 0
keys = request.POST.keys()
mac_key = [key for key in keys if 'mac' in key]
if mac_key: mac = request.POST.get(mac_key[0])
try:
conn.set_qos(mac, qos_dir, average, peak, burst)
if conn.get_status() == 5:
messages.success(request, "{} Qos is set".format(qos_dir.capitalize()))
else:
messages.success(request,
"{} Qos is set. Network XML is changed.".format(qos_dir.capitalize()) +
"Stop and start network to activate new config")
except libvirtError as le:
messages.error(request, le.message)
return HttpResponseRedirect(request.get_full_path() + '#network')
if 'unset_qos' in request.POST:
qos_dir = request.POST.get('qos_direction', '')
mac = request.POST.get('net-mac')
conn.unset_qos(mac, qos_dir)
if conn.get_status() == 5:
messages.success(request, "{} Qos is deleted".format(qos_dir.capitalize()))
else:
messages.success(request,
"{} Qos is deleted. Network XML is changed. ".format(qos_dir.capitalize()) +
"Stop and start network to activate new config.")
return HttpResponseRedirect(request.get_full_path() + '#network')
if 'add_owner' in request.POST:
user_id = int(request.POST.get('user_id', ''))