mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 15:15:22 +00:00
instance network page reconfigured. libxml2 artifacts cleaned. Some minor makeups
This commit is contained in:
parent
8b2451284f
commit
b178bad93e
4 changed files with 48 additions and 22 deletions
|
@ -35,6 +35,7 @@
|
|||
{{ disk.size|filesizeformat }} {% trans "Disk" %} |
|
||||
{% endfor %}
|
||||
<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>
|
||||
{% if user_quota_msg %}
|
||||
|
@ -318,7 +319,7 @@
|
|||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<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 %}
|
||||
<p style="font-weight:bold;">{% trans "Logical host CPUs:" %} {{ vcpu_host }}</p>
|
||||
<div class="form-group">
|
||||
|
@ -396,7 +397,7 @@
|
|||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<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 %}
|
||||
<p style="font-weight:bold;">{% trans "Volume parameters" %}</p>
|
||||
<div class="form-group">
|
||||
|
@ -588,7 +589,7 @@
|
|||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if request.user.is_superuser or userinstace.is_vnc %}
|
||||
{% if request.user.is_superuser or userinstance.is_vnc %}
|
||||
<li role="presentation">
|
||||
<a href="#vncsettings" aria-controls="vncsettings" role="tab" data-toggle="tab">
|
||||
{% trans "VNC" %}
|
||||
|
@ -689,7 +690,7 @@
|
|||
<div class="clearfix"></div>
|
||||
</div>
|
||||
{% 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">
|
||||
<p>{% trans "To set console's type, shutdown the instance." %}</p>
|
||||
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
|
||||
|
@ -811,19 +812,29 @@
|
|||
<p style="font-weight:bold;">{% trans "Network devices" %}</p>
|
||||
{% for network in networks %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="col-sm-3 control-label" style="font-weight:normal;">eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" class="form-control" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}"/>
|
||||
</div>
|
||||
<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>
|
||||
{% endfor %}
|
||||
{% 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 %}
|
||||
<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 %}
|
||||
</form>
|
||||
<div class="clearfix"></div>
|
||||
|
@ -1149,7 +1160,7 @@
|
|||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="destroy">
|
||||
<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 %}
|
||||
<button class="btn btn-lg btn-success disabled pull-right" name="delete">{% trans "Destroy" %}</button>
|
||||
{% else %}
|
||||
|
@ -1321,6 +1332,17 @@
|
|||
});
|
||||
});
|
||||
</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>
|
||||
$('#chartgraphs').on('shown.bs.tab', function (event) {
|
||||
|
|
|
@ -24,6 +24,7 @@ from vrtManager.util import randomPasswd
|
|||
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE
|
||||
from logs.views import addlogmsg
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -203,7 +204,7 @@ def instance(request, compute_id, vname):
|
|||
"""
|
||||
|
||||
error_messages = []
|
||||
messages = []
|
||||
#messages = []
|
||||
compute = get_object_or_404(Compute, pk=compute_id)
|
||||
computes = Compute.objects.all().order_by('name')
|
||||
computes_count = computes.count()
|
||||
|
@ -325,7 +326,7 @@ def instance(request, compute_id, vname):
|
|||
compute.password,
|
||||
compute.type,
|
||||
vname)
|
||||
|
||||
compute_networks = sorted(conn.get_networks())
|
||||
status = conn.get_status()
|
||||
autostart = conn.get_autostart()
|
||||
vcpu = conn.get_vcpu()
|
||||
|
@ -451,7 +452,7 @@ def instance(request, compute_id, vname):
|
|||
addlogmsg(request.user.username, instance.name, msg)
|
||||
|
||||
if result['return'] == 'success':
|
||||
messages.append(msg)
|
||||
messages.success(request, msg)
|
||||
else:
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
|
@ -473,7 +474,7 @@ def instance(request, compute_id, vname):
|
|||
addlogmsg(request.user.username, instance.name, msg)
|
||||
|
||||
if result['return'] == 'success':
|
||||
messages.append(msg)
|
||||
messages.success(request, msg)
|
||||
else:
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
|
@ -569,7 +570,7 @@ def instance(request, compute_id, vname):
|
|||
conn.snapshot_revert(snap_name)
|
||||
msg = _("Successful revert snapshot: ")
|
||||
msg += snap_name
|
||||
messages.append(msg)
|
||||
messages.success(request, msg)
|
||||
msg = _("Revert snapshot")
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
|
||||
|
@ -690,6 +691,8 @@ def instance(request, compute_id, vname):
|
|||
conn.change_network(network_data)
|
||||
msg = _("Edit network")
|
||||
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')
|
||||
|
||||
if 'add_owner' in request.POST:
|
||||
|
|
|
@ -217,13 +217,14 @@ class wvmInstance(wvmConnect):
|
|||
result = []
|
||||
for net in ctx.xpath('/domain/devices/interface'):
|
||||
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:
|
||||
net = self.get_network(nic_host)
|
||||
net = self.get_network(network_host)
|
||||
ip = get_mac_ipaddr(net, mac_host)
|
||||
except:
|
||||
except libvirtError as e:
|
||||
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 util.get_xml_path(self._XMLDesc(0), func=networks)
|
||||
|
@ -746,12 +747,13 @@ class wvmInstance(wvmConnect):
|
|||
tree = ElementTree.fromstring(xml)
|
||||
|
||||
for num, interface in enumerate(tree.findall('devices/interface')):
|
||||
net = self.get_network(network_data['net-source-' + str(num)])
|
||||
if interface.get('type') == 'bridge':
|
||||
source = interface.find('mac')
|
||||
source.set('address', network_data['net-mac-' + str(num)])
|
||||
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)
|
||||
self._defineXML(new_xml)
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ def get_xml_path(xml, path=None, func=None):
|
|||
doc = etree.fromstring(xml)
|
||||
if path:
|
||||
result = get_xpath(doc, path)
|
||||
|
||||
elif func:
|
||||
result = func(doc)
|
||||
|
||||
|
|
Loading…
Reference in a new issue