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

instance network page reconfigured. libxml2 artifacts cleaned. Some minor makeups

This commit is contained in:
catborise 2018-07-24 13:52:47 +03:00
parent 8b2451284f
commit b178bad93e
4 changed files with 48 additions and 22 deletions

View file

@ -35,6 +35,7 @@
{{ disk.size|filesizeformat }} {% trans "Disk" %} | {{ disk.size|filesizeformat }} {% trans "Disk" %} |
{% endfor %} {% endfor %}
<a href="{% url 'instance' compute.id vname %}" type="button" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-refresh"></span></a> <a href="{% url 'instance' compute.id vname %}" type="button" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-refresh"></span></a>
<small><em>on {{ compute.name}} - {{ compute.hostname }}</em></small>
</div> </div>
</div> </div>
{% if user_quota_msg %} {% if user_quota_msg %}
@ -318,7 +319,7 @@
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resizevm"> <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resizevm">
{% if request.user.is_superuser or request.user.is_staff or userinstace.is_change %} {% if request.user.is_superuser or request.user.is_staff or userinstance.is_change %}
<form class="form-horizontal" method="post" role="form">{% csrf_token %} <form class="form-horizontal" method="post" role="form">{% csrf_token %}
<p style="font-weight:bold;">{% trans "Logical host CPUs:" %} {{ vcpu_host }}</p> <p style="font-weight:bold;">{% trans "Logical host CPUs:" %} {{ vcpu_host }}</p>
<div class="form-group"> <div class="form-group">
@ -396,7 +397,7 @@
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="addvolume"> <div role="tabpanel" class="tab-pane tab-pane-bordered" id="addvolume">
{% if request.user.is_superuser or userinstace.is_change %} {% if request.user.is_superuser or userinstance.is_change %}
<form class="form-horizontal" method="post" role="form">{% csrf_token %} <form class="form-horizontal" method="post" role="form">{% csrf_token %}
<p style="font-weight:bold;">{% trans "Volume parameters" %}</p> <p style="font-weight:bold;">{% trans "Volume parameters" %}</p>
<div class="form-group"> <div class="form-group">
@ -588,7 +589,7 @@
</a> </a>
</li> </li>
{% endif %} {% endif %}
{% if request.user.is_superuser or userinstace.is_vnc %} {% if request.user.is_superuser or userinstance.is_vnc %}
<li role="presentation"> <li role="presentation">
<a href="#vncsettings" aria-controls="vncsettings" role="tab" data-toggle="tab"> <a href="#vncsettings" aria-controls="vncsettings" role="tab" data-toggle="tab">
{% trans "VNC" %} {% trans "VNC" %}
@ -689,7 +690,7 @@
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
{% endif %} {% endif %}
{% if request.user.is_superuser or userinstace.is_vnc %} {% if request.user.is_superuser or userinstance.is_vnc %}
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="vncsettings"> <div role="tabpanel" class="tab-pane tab-pane-bordered" id="vncsettings">
<p>{% trans "To set console's type, shutdown the instance." %}</p> <p>{% trans "To set console's type, shutdown the instance." %}</p>
<form class="form-horizontal" method="post" role="form">{% csrf_token %} <form class="form-horizontal" method="post" role="form">{% csrf_token %}
@ -811,19 +812,29 @@
<p style="font-weight:bold;">{% trans "Network devices" %}</p> <p style="font-weight:bold;">{% trans "Network devices" %}</p>
{% for network in networks %} {% for network in networks %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}</label> <label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label>
<div class="col-sm-4"> <div class="col-sm-3">
<input type="text" class="form-control" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/> <input type="text" class="form-control" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<input type="text" class="form-control" name="net-source-{{ forloop.counter0 }}" value="{{ network.nic }}"/> <input type="text" class="form-control" name="net-source-{{ forloop.counter0 }}" value="{{ network.nic }}" disabled/>
</div>
<div class="col-sm-3">
<select name="net-source-{{ forloop.counter0 }}" class="form-control" id="network_select" onchange="network_select_enable()">
{% for c_nets in compute_networks %}
{% if forloop.counter0 == 0 %}
<option value="{{ network.nic }}" selected hidden>{% trans "to Change" %}</option>
{% endif %}
<option value="{{ c_nets }}">{{ c_nets }}</option>
{% endfor %}
</select>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{% ifequal status 5 %} {% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="change_network">{% trans "Change" %}</button> <button type="submit" class="btn btn-lg btn-success pull-right" id="ali" name="change_network" disabled>{% trans "Change" %}</button>
{% else %} {% else %}
<button class="btn btn-lg btn-success pull-right disabled" name="change_network">{% trans "Change" %}</button> <button type="submit"class="btn btn-lg btn-success pull-right" id="ali" name="change_network" disabled>{% trans "Change" %}</button>
{% endifequal %} {% endifequal %}
</form> </form>
<div class="clearfix"></div> <div class="clearfix"></div>
@ -1149,7 +1160,7 @@
<div class="tab-content"> <div class="tab-content">
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="destroy"> <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="destroy">
<p>{% trans "Delete storage for instance?" %}</p> <p>{% trans "Delete storage for instance?" %}</p>
{% if request.user.is_superuser or userinstace.is_delete %} {% if request.user.is_superuser or userinstance.is_delete %}
{% ifequal status 3 %} {% ifequal status 3 %}
<button class="btn btn-lg btn-success disabled pull-right" name="delete">{% trans "Destroy" %}</button> <button class="btn btn-lg btn-success disabled pull-right" name="delete">{% trans "Destroy" %}</button>
{% else %} {% else %}
@ -1321,6 +1332,17 @@
}); });
}); });
</script> </script>
<script>
function network_select_enable(){
// set network button enabled
var selected = $('network_select').val();
if (selected != "to Change") {
$('button[name="change_network"]').removeAttr('disabled');
}
}
</script>
<script src="{% static "js/Chart.min.js" %}"></script> <script src="{% static "js/Chart.min.js" %}"></script>
<script> <script>
$('#chartgraphs').on('shown.bs.tab', function (event) { $('#chartgraphs').on('shown.bs.tab', function (event) {

View file

@ -24,6 +24,7 @@ from vrtManager.util import randomPasswd
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE
from logs.views import addlogmsg from logs.views import addlogmsg
from django.conf import settings from django.conf import settings
from django.contrib import messages
@login_required @login_required
@ -203,7 +204,7 @@ def instance(request, compute_id, vname):
""" """
error_messages = [] error_messages = []
messages = [] #messages = []
compute = get_object_or_404(Compute, pk=compute_id) compute = get_object_or_404(Compute, pk=compute_id)
computes = Compute.objects.all().order_by('name') computes = Compute.objects.all().order_by('name')
computes_count = computes.count() computes_count = computes.count()
@ -325,7 +326,7 @@ def instance(request, compute_id, vname):
compute.password, compute.password,
compute.type, compute.type,
vname) vname)
compute_networks = sorted(conn.get_networks())
status = conn.get_status() status = conn.get_status()
autostart = conn.get_autostart() autostart = conn.get_autostart()
vcpu = conn.get_vcpu() vcpu = conn.get_vcpu()
@ -451,7 +452,7 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
if result['return'] == 'success': if result['return'] == 'success':
messages.append(msg) messages.success(request, msg)
else: else:
error_messages.append(msg) error_messages.append(msg)
else: else:
@ -473,7 +474,7 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
if result['return'] == 'success': if result['return'] == 'success':
messages.append(msg) messages.success(request, msg)
else: else:
error_messages.append(msg) error_messages.append(msg)
else: else:
@ -569,7 +570,7 @@ def instance(request, compute_id, vname):
conn.snapshot_revert(snap_name) conn.snapshot_revert(snap_name)
msg = _("Successful revert snapshot: ") msg = _("Successful revert snapshot: ")
msg += snap_name msg += snap_name
messages.append(msg) messages.success(request, msg)
msg = _("Revert snapshot") msg = _("Revert snapshot")
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
@ -690,6 +691,8 @@ def instance(request, compute_id, vname):
conn.change_network(network_data) conn.change_network(network_data)
msg = _("Edit network") msg = _("Edit network")
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
msg = _("Network Devices are changed. Please reboot instance to activate.")
messages.success(request, msg)
return HttpResponseRedirect(request.get_full_path() + '#network') return HttpResponseRedirect(request.get_full_path() + '#network')
if 'add_owner' in request.POST: if 'add_owner' in request.POST:

View file

@ -217,13 +217,14 @@ class wvmInstance(wvmConnect):
result = [] result = []
for net in ctx.xpath('/domain/devices/interface'): for net in ctx.xpath('/domain/devices/interface'):
mac_host = net.xpath('mac/@address')[0] mac_host = net.xpath('mac/@address')[0]
nic_host = net.xpath('source/@network|source/@bridge|source/@dev|target/@dev')[0] network_host = net.xpath('source/@network|source/@bridge|source/@dev')[0]
target_host = '' if not net.xpath('target/@dev') else net.xpath('target/@dev')[0]
try: try:
net = self.get_network(nic_host) net = self.get_network(network_host)
ip = get_mac_ipaddr(net, mac_host) ip = get_mac_ipaddr(net, mac_host)
except: except libvirtError as e:
ip = None ip = None
result.append({'mac': mac_host, 'nic': nic_host, 'ip': ip}) result.append({'mac': mac_host, 'nic': network_host, 'target': target_host,'ip': ip})
return result return result
return util.get_xml_path(self._XMLDesc(0), func=networks) return util.get_xml_path(self._XMLDesc(0), func=networks)
@ -746,12 +747,13 @@ class wvmInstance(wvmConnect):
tree = ElementTree.fromstring(xml) tree = ElementTree.fromstring(xml)
for num, interface in enumerate(tree.findall('devices/interface')): for num, interface in enumerate(tree.findall('devices/interface')):
net = self.get_network(network_data['net-source-' + str(num)])
if interface.get('type') == 'bridge': if interface.get('type') == 'bridge':
source = interface.find('mac') source = interface.find('mac')
source.set('address', network_data['net-mac-' + str(num)]) source.set('address', network_data['net-mac-' + str(num)])
source = interface.find('source') source = interface.find('source')
source.set('bridge', network_data['net-source-' + str(num)]) source.set('bridge', net.bridgeName())
source.set('network', net.name())
new_xml = ElementTree.tostring(tree) new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml) self._defineXML(new_xml)

View file

@ -91,7 +91,6 @@ def get_xml_path(xml, path=None, func=None):
doc = etree.fromstring(xml) doc = etree.fromstring(xml)
if path: if path:
result = get_xpath(doc, path) result = get_xpath(doc, path)
elif func: elif func:
result = func(doc) result = func(doc)