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

Add Qos functions and Edit network with xml function

This commit is contained in:
catborise 2019-11-15 11:29:16 +03:00
parent 930cef24be
commit 79abcd460b
3 changed files with 138 additions and 0 deletions

View file

@ -0,0 +1,41 @@
{% load i18n %}
{% if request.user.is_superuser %}
<a href="#AddInboundQos" type="button" class="btn btn-success pull-right" data-toggle="modal">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<!-- Modal pool -->
<div class="modal fade" id="AddInboundQos" tabindex="-1" role="dialog" aria-labelledby="AddInboundQosLabel" 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 Inbound Qos for Network" %}</h4>
</div>
<form class="form-horizontal" method="post" action="" role="form" novalidate>{% csrf_token %}
<div class="modal-body">
<div class="form-group col-sm-4 ">
<label for="qos_inbound_av">{% trans "Average" %}:</label>
<input id="qos_inbound_av" class="form-control" name="qos_inbound_average" value="{{ att.average }}"/>
</div>
<div class="form-group col-sm-4">
<label for="qos_inbound_peak">{% trans "Peak" %}:</label>
<input id="qos_inbound_peak" class="form-control" name="qos_inbound_peak" value="{{ att.peak }}"/>
</div>
<div class="form-group col-sm-4">
<label for="qos_inbound_burst">{% trans "Burst" %}:</label>
<input id="qos_inbound_burst" class="form-control" name="qos_inbound_burst" value="{{ att.burst }}"/></p>
</div>
</div> <!-- /.modal-content -->
<div class="modal-footer">
<input name="qos_direction" value="inbound" hidden/>
<div class="col-sm-6">
<button class="btn btn-primary btn-block" name="set_qos">{% trans 'Save' %}</button>
</div>
</div>
</form>
</div>
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
{% endif %}

View file

@ -0,0 +1,40 @@
{% load i18n %}
{% if request.user.is_superuser %}
<a href="#AddInboundQos" type="button" class="btn btn-success pull-right" data-toggle="modal">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<!-- Modal pool -->
<div class="modal fade" id="AddInboundQos" tabindex="-1" role="dialog" aria-labelledby="AddInboundQosLabel" 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 Inbound Qos for Network" %}</h4>
</div>
<form class="form-horizontal" method="post" action="" role="form" novalidate>{% csrf_token %}
<div class="modal-body">
<div class="form-group col-sm-4 ">
<label for="qos_inbound_av">{% trans "Average" %}:</label>
<input id="qos_inbound_av" class="form-control" name="qos_inbound_average" value="{{ att.average }}"/>
</div>
<div class="form-group col-sm-4">
<label for="qos_inbound_peak">{% trans "Peak" %}:</label>
<input id="qos_inbound_peak" class="form-control" name="qos_inbound_peak" value="{{ att.peak }}"/>
</div>
<div class="form-group col-sm-4">
<label for="qos_inbound_burst">{% trans "Burst" %}:</label>
<input id="qos_inbound_burst" class="form-control" name="qos_inbound_burst" value="{{ att.burst }}"/></p>
</div>
</div> <!-- /.modal-content -->
<div class="modal-footer">
<input name="qos_direction" value="inbound" hidden/>
<div class="col-sm-6">
<button class="btn btn-primary btn-block" name="set_qos">{% trans 'Save' %}</button>
</div>
</div>
</form>
</div>
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
{% endif %}

View file

@ -290,3 +290,60 @@ class wvmNetwork(wvmConnect):
parent_index, parent_index,
VIR_NETWORK_UPDATE_AFFECT_LIVE | VIR_NETWORK_UPDATE_AFFECT_CONFIG) VIR_NETWORK_UPDATE_AFFECT_LIVE | VIR_NETWORK_UPDATE_AFFECT_CONFIG)
def get_qos(self):
qos_values = dict()
tree = etree.fromstring(self._XMLDesc(0))
qos = tree.xpath("/network/bandwidth")
if qos:
qos = qos[0]
in_qos = qos.find('inbound')
if in_qos is not None:
in_av = in_qos.get('average')
in_peak = in_qos.get('peak')
in_burst = in_qos.get('burst')
qos_values['inbound'] = {'average': in_av, 'peak': in_peak, 'burst': in_burst}
out_qos = qos.find('outbound')
if out_qos is not None:
out_av = out_qos.get('average')
out_peak = out_qos.get('peak')
out_burst = out_qos.get('burst')
qos_values['outbound'] = {'average': out_av, 'peak': out_peak, 'burst': out_burst}
return qos_values
def set_qos(self, direction, average, peak, burst):
if direction == "inbound":
xml = "<inbound average='{}' peak='{}' burst='{}'/>".format(average, peak, burst)
elif direction == "outbound":
xml = "<outbound average='{}' peak='{}' burst='{}'/>".format(average, peak, burst)
else:
raise Exception('Direction must be inbound or outbound')
tree = etree.fromstring(self._XMLDesc(0))
band = tree.xpath("/network/bandwidth")
if len(band) == 0:
xml = "<bandwidth>" + xml + "</bandwidth>"
tree.append(etree.fromstring(xml))
else:
direct = band[0].find(direction)
if direct is not None:
parent = direct.getparent()
parent.remove(direct)
parent.append(etree.fromstring(xml))
else:
band[0].append(etree.fromstring(xml))
new_xml = etree.tostring(tree)
self.wvm.networkDefineXML(new_xml)
def unset_qos(self, direction):
tree = etree.fromstring(self._XMLDesc(0))
for direct in tree.xpath("/network/bandwidth/{}".format(direction)):
parent = direct.getparent()
parent.remove(direct)
self.wvm.networkDefineXML(etree.tostring(tree))
def edit_network(self, new_xml):
self.wvm.networkDefineXML(new_xml)