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

Merge pull request #255 from catborise/master

Some Updates & Rearrange/fix
This commit is contained in:
Anatoliy Guskov 2019-10-24 14:08:28 +03:00 committed by GitHub
commit fb26a002c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 3380 additions and 3223 deletions

View file

@ -30,11 +30,11 @@
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Username</th>
<th>Status</th>
<th>Staff</th>
<th>Superuser</th>
<th>Clone</th>
<th>{% trans "Username" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Staff" %}</th>
<th>{% trans "Superuser" %}</th>
<th>{% trans "Clone" %}</th>
</tr>
</thead>
<tbody class="searchable">

View file

@ -2,7 +2,6 @@ from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from accounts.models import *
from instances.models import Instance
@ -11,7 +10,6 @@ from django.conf import settings
from django.core.validators import ValidationError
@login_required
def profile(request):
"""
@ -70,6 +68,7 @@ def profile(request):
return HttpResponseRedirect(request.get_full_path())
return render(request, 'profile.html', locals())
@login_required
def accounts(request):
"""
@ -154,6 +153,7 @@ def accounts(request):
def account(request, user_id):
"""
:param request:
:param user_id:
:return:
"""

View file

@ -37,7 +37,7 @@
<div class="panel-body">
<div class="row">
<div class="col-xs-4 col-sm-4">
<p><strong>{% trans "Status:" %}</strong></p>
<p><strong>{% trans "Status" %}:</strong></p>
</div>
<div class="col-xs-4 col-sm-6">
{% if compute.status %}
@ -235,7 +235,6 @@
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
</div>
</div>
@ -244,7 +243,7 @@
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "Hypervisor doesn't have any Computes" %}
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "Hypervisor doesn't have any Computes" %}
</div>
</div>
{% endif %}

View file

@ -62,9 +62,9 @@
</p>
<p>{{ emulator }}</p>
<p>
<span class="label label-default">{% trans 'Qemu' %} </span>
<span class="label label-default">Qemu</span>
<span class="label label-primary">{{ version }}</span> &nbsp;
<span class="label label-default">{% trans 'Libvirt' %} </span>
<span class="label label-default">Libvirt</span>
<span class="label label-primary">{{ lib_version }}</span> &nbsp;
</p>
<p>{{ host_memory|filesizeformat }}</p>

View file

@ -1,4 +1,3 @@
import time
import json
from django.utils import timezone
from django.http import HttpResponse, HttpResponseRedirect
@ -140,6 +139,7 @@ def computes(request):
def overview(request, compute_id):
"""
:param request:
:param compute_id:
:return:
"""
@ -171,6 +171,7 @@ def overview(request, compute_id):
def compute_graph(request, compute_id):
"""
:param request:
:param compute_id:
:return:
"""
compute = get_object_or_404(Compute, pk=compute_id)
@ -207,17 +208,16 @@ def get_compute_disk_buses(request, compute_id, disk):
compute.type)
disk_device_types = conn.get_disk_device_types()
disk_bus_types = conn.get_disk_bus_types()
if disk in disk_device_types:
if disk == 'disk':
data['bus'] = sorted(disk_device_types)
elif disk == 'cdrom':
data['bus'] = ['ide', 'sata', 'scsi',]
data['bus'] = ['ide', 'sata', 'scsi']
elif disk == 'floppy':
data['bus'] = ['fdc',]
data['bus'] = ['fdc']
elif disk == 'lun':
data['bus'] = ['scsi',]
data['bus'] = ['scsi']
except libvirtError:
pass

View file

@ -120,7 +120,7 @@ def get_connection_infos(token):
console_host = conn.get_console_listen_addr()
console_port = conn.get_console_port()
console_socket = conn.get_console_socket()
except Exception, e:
except Exception as e:
logging.error('Fail to retrieve console connection infos for token %s : %s' % (token, e))
raise
return (connhost, connport, connuser, conntype, console_host,

View file

@ -1,7 +1,5 @@
import re
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from instances.models import Instance
from vrtManager.instance import wvmInstance

View file

@ -17,7 +17,6 @@
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="text" name="label" class="form-control" placeholder="Micro" maxlength="20"
required pattern="[a-zA-Z0-9]+">
@ -25,7 +24,6 @@
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "VCPU" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="vcpu" value="1" maxlength="1" required
pattern="[0-9]">
@ -33,7 +31,6 @@
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "RAM" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="memory" value="512" maxlength="5" required
pattern="[0-9]+">
@ -42,7 +39,6 @@
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "HDD" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="disk" value="10" maxlength="3" required
pattern="[0-9]+">

View file

@ -436,7 +436,6 @@
</div>
<label class="col-sm-1 control-label">{% trans "MB" %}</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "HDD" %}</label>
<input id="images" name="images" type="hidden" value=""/>
@ -582,8 +581,7 @@
</div>
<div class="clearfix"></div>
</div>
</div>
<!-- /Tab panes -->
</div><!-- /Tab panes -->
</div>
{% endblock %}
@ -607,7 +605,6 @@
}
$(document).ready(function () {
$('#image-control').multiselect({
disableIfEmpty: true,
enableCaseInsensitiveFiltering: true,
@ -716,7 +713,6 @@
function get_disk_bus_choices(compute_id, dev_idx, disk_type){
get_diskBus_url = "/computes/" + compute_id + "/disk/" + disk_type + "/buses";
$.getJSON(get_diskBus_url, function (data) {
$("#bus" + dev_idx).find('option').remove();
$.each(data['bus'], function(i, item) {

View file

@ -21,6 +21,7 @@ from logs.views import addlogmsg
def create_instance(request, compute_id):
"""
:param request:
:param compute_id:
:return:
"""
@ -41,9 +42,6 @@ def create_instance(request, compute_id):
compute.password,
compute.type)
storages = sorted(conn.get_storages(only_actives=True))
networks = sorted(conn.get_networks())
nwfilters = conn.get_nwfilters()
instances = conn.get_instances()
videos = conn.get_video()
cache_modes = sorted(conn.get_cache_modes().items())
@ -53,6 +51,9 @@ def create_instance(request, compute_id):
disk_devices = conn.get_disk_device_types()
disk_buses = conn.get_disk_bus_types()
default_bus = INSTANCE_VOLUME_DEFAULT_BUS
networks = sorted(conn.get_networks())
nwfilters = conn.get_nwfilters()
storages = sorted(conn.get_storages(only_actives=True))
except libvirtError as lib_err:
error_messages.append(lib_err)
@ -109,7 +110,7 @@ def create_instance(request, compute_id):
msg = _("A virtual machine with this name already exists")
error_messages.append(msg)
if Instance.objects.filter(name__exact=data['name']):
messages.warning(request,_("There is an instance with same name. Are you sure?"))
messages.warning(request, _("There is an instance with same name. Are you sure?"))
if not error_messages:
if data['hdd_size']:
if not data['mac']:
@ -148,7 +149,6 @@ def create_instance(request, compute_id):
else:
for idx, vol in enumerate(data['images'].split(',')):
try:
path = conn.get_volume_path(vol)
volume = dict()
volume['path'] = path
@ -175,7 +175,7 @@ def create_instance(request, compute_id):
addlogmsg(request.user.username, create_instance.name, msg)
return HttpResponseRedirect(reverse('instance', args=[compute_id, data['name']]))
except libvirtError as lib_err:
if data['hdd_size'] or volume_list.count() > 0:
if data['hdd_size'] or len(volume_list) > 0:
for vol in volume_list:
conn.delete_volume(vol['path'])
error_messages.append(lib_err)

View file

@ -26,7 +26,7 @@ def os_metadata_json(request, version):
if version == 'latest':
ip = get_client_ip(request)
hostname = get_hostname_by_ip(ip)
response = { 'uuid': OS_UUID, 'hostname': hostname }
response = {'uuid': OS_UUID, 'hostname': hostname}
return HttpResponse(json.dumps(response))
else:
err = 'Invalid version: {}'.format(version)
@ -70,8 +70,8 @@ def get_client_ip(request):
def get_hostname_by_ip(ip):
try:
addrs = socket.gethostbyaddr(ip)
except Exception:
addrs = [ip,]
except:
addrs = [ip]
return addrs[0]

View file

@ -24,10 +24,10 @@
<label class="col-sm-4 control-label">{% trans "Network" %}</label>
<div class="col-sm-6">
<select class="form-control" name="add-net-network">
{% for c_net in compute_networks %}
{% for c_net in networks_host %}
<option value="net:{{ c_net }}">Network {{ c_net }}</option>
{% endfor %}
{% for c_iface in compute_interfaces %}
{% for c_iface in interfaces_host %}
<option value="iface:{{ c_iface }}">Interface {{ c_iface }}</option>
{% endfor %}
</select>
@ -38,7 +38,7 @@
<div class="col-sm-6">
<select class="form-control" name="add-net-nwfilter">
<option value="">{% trans "None" %}</option>
{% for nwfilter in compute_nwfilters %}
{% for nwfilter in nwfilters_host %}
<option value="{{ nwfilter }}">{{ nwfilter }}</option>
{% endfor %}
</select>

View file

@ -1,11 +1,11 @@
{% load i18n %}
{% if request.user.is_superuser %}
<a href="#addvol" type="button" class="btn btn-success pull-right" data-toggle="modal" title="Add Volume">
<a href="#addvol" type="button" class="btn btn-success pull-right" data-toggle="modal" title="Add Volume">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
</a>
<!-- Modal pool -->
<div class="modal fade" id="addvol" tabindex="-1" role="dialog" aria-labelledby="addInstanceVolumeLabel" aria-hidden="true">
<!-- Modal pool -->
<div class="modal fade" id="addvol" tabindex="-1" role="dialog" aria-labelledby="addInstanceVolumeLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
@ -28,7 +28,7 @@
<label class="col-sm-3 control-label">{% trans "Storage" %}</label>
<div class="col-sm-4">
<select name="storage" class="form-control image-format">
{% for storage in storages %}
{% for storage in storages_host %}
<option value="{{ storage }}">{{ storage }}</option>
{% endfor %}
</select>
@ -147,5 +147,5 @@
</div> <!-- /.modal-body -->
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
</div> <!-- /.modal -->
{% endif %}

View file

@ -48,7 +48,7 @@
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "You don't have any Instance" %}
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "You don't have any Instance" %}
</div>
</div>
{% else %}

View file

@ -3,7 +3,7 @@
<thead>
<tr>
<th><a href="#" id="hide_all_instances" onclick="hide_all_host_instances()">#</a> </th>
<th>{% trans "Name" %}<br>{% trans "Description" %}</th></th>
<th>{% trans "Name" %}<br>{% trans "Description" %}</th>
<th>{% trans "User"%}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "VCPU" %}</th>
@ -71,16 +71,16 @@
<span class="glyphicon glyphicon-play"></span>
</button>
{% endif %}
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}" disabled>
<span class="glyphicon glyphicon-pause"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}" disabled>
<span class="glyphicon glyphicon-off"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}" disabled>
<span class="glyphicon glyphicon-refresh"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}" disabled>
<span class="glyphicon glyphicon-eye-open"></span>
</button>
{% endifequal %}
@ -88,21 +88,21 @@
<button class="btn btn-sm btn-default" type="submit" name="resume" title="{% trans "Resume" %}">
<span class="glyphicon glyphicon-play"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}" disabled>
<span class="glyphicon glyphicon-pause"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}">
<button class="btn btn-sm btn-default" type="submit" name="powerforce" title="{% trans "Force Off" %}" onclick="return confirm('Are you sure to force it down?')">
<span class="glyphicon glyphicon-off"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}" disabled>
<span class="glyphicon glyphicon-refresh"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}" disabled>
<span class="glyphicon glyphicon-eye-open"></span>
</button>
{% endifequal %}
{% ifequal info.status 1 %}
<button class="btn btn-sm btn-default disabled" title="{% trans "Power On" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power On" %}" disabled>
<span class="glyphicon glyphicon-play"></span>
</button>
<button class="btn btn-sm btn-default" type="submit" name="suspend" title="{% trans "Suspend" %}">
@ -114,9 +114,9 @@
<button class="btn btn-sm btn-default" type="submit" name="powercycle" title="{% trans "Power Cycle" %}" onclick="return confirm('Are you sure?')">
<span class="glyphicon glyphicon-refresh"></span>
</button>
<a href="#" class="btn btn-sm btn-default" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}">
<button class="btn btn-sm btn-default" type="button" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}">
<span class="glyphicon glyphicon-eye-open"></span>
</a>
</button>
{% endifequal %}
</form>
</td>

View file

@ -2,11 +2,11 @@
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
<thead>
<tr>
<th>Name<br>Description</th>
<th>Host<br>User</th>
<th>Status</th>
<th>VCPU</th>
<th>Memory</th>
<th>{% trans "Name" %}<br>{% trans "Description" %}</th>
<th>{% trans "Host" %}<br>{% trans "User"%}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "VCPU" %}</th>
<th>{% trans "Memory" %}</th>
<th data-sortable="false" style="width:205px;">{% trans "Actions" %}</th>
</tr>
</thead>
@ -23,7 +23,8 @@
</td>
<td>{{ info.vcpu }}</td>
<td>{{ info.memory|filesizeformat }}</td>
<td><form action="" method="post" role="form">{% csrf_token %}
<td>
<form action="" method="post" role="form">{% csrf_token %}
<input type="hidden" name="name" value="{{ vm }}"/>
<input type="hidden" name="compute_id" value="{{ host.0 }}"/>
{% ifequal info.status 5 %}
@ -36,16 +37,16 @@
<span class="glyphicon glyphicon-play"></span>
</button>
{% endif %}
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}" disabled>
<span class="glyphicon glyphicon-pause"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}" disabled>
<span class="glyphicon glyphicon-off"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}" disabled>
<span class="glyphicon glyphicon-refresh"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}" disabled>
<span class="glyphicon glyphicon-eye-open"></span>
</button>
{% endifequal %}
@ -53,21 +54,21 @@
<button class="btn btn-sm btn-default" type="submit" name="resume" title="{% trans "Resume" %}">
<span class="glyphicon glyphicon-play"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}" disabled>
<span class="glyphicon glyphicon-pause"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}">
<button class="btn btn-sm btn-default" type="submit" name="powerforce" title="{% trans "Force Off" %}" onclick="return confirm('Are you sure to force it down?')">
<span class="glyphicon glyphicon-off"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}" disabled>
<span class="glyphicon glyphicon-refresh"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}" disabled>
<span class="glyphicon glyphicon-eye-open"></span>
</button>
{% endifequal %}
{% ifequal info.status 1 %}
<button class="btn btn-sm btn-default disabled" title="{% trans "Power On" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power On" %}" disabled>
<span class="glyphicon glyphicon-play"></span>
</button>
<button class="btn btn-sm btn-default" type="submit" name="suspend" title="{% trans "Suspend" %}">
@ -79,9 +80,9 @@
<button class="btn btn-sm btn-default" type="submit" name="powercycle" title="{% trans "Power Cycle" %}" onclick="return confirm('Are you sure?')">
<span class="glyphicon glyphicon-refresh"></span>
</button>
<a href="#" class="btn btn-sm btn-default" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}">
<button class="btn btn-sm btn-default" type="button" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}">
<span class="glyphicon glyphicon-eye-open"></span>
</a>
</button>
{% endifequal %}
</form>
</td>

View file

@ -48,7 +48,6 @@
{% include 'errors_block.html' %}
{% include 'messages_block.html' %}
<div class="row" id="max-width-page">
<div class="col-lg-12">
<div role="tabpanel">
@ -345,14 +344,24 @@
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#resizevm" aria-controls="resizevm" role="tab" data-toggle="tab">
{% trans "Resize Instance" %}
<a href="#resizevm_cpu" aria-controls="resizevm_cpu" role="tab" data-toggle="tab">
{% trans "CPU" %}
</a>
</li>
<li role="presentation">
<a href="#resizevm_mem" aria-controls="resizevm_mem" role="tab" data-toggle="tab">
{% trans "Memory" %}
</a>
</li>
<li role="presentation">
<a href="#resizevm_disk" aria-controls="resizevm_disk" role="tab" data-toggle="tab">
{% trans "Disk" %}
</a>
</li>
</ul>
<!-- Tab panes -->
<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_cpu">
{% 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>
@ -380,6 +389,22 @@
</select>
</div>
</div>
{% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="resizevm_cpu">{% trans "Resize" %}</button>
{% else %}
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
{% endifequal %}
</form>
{% else %}
{% trans "You don't have permission for resizing instance" %}
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
{% endif %}
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="resizevm_mem">
{% 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 "Total host memory:" %} {{ memory_host|filesizeformat }}</p>
<div class="form-group">
<label class="col-sm-4 control-label" style="font-weight:normal;">{% trans "Current allocation" %} ({% trans "MB" %})</label>
@ -407,6 +432,21 @@
<small><input type="checkbox" class="js-custom__checkbox" /> {% trans "Custom value" %}</small>
</div>
</div>
{% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="resizevm_mem">{% trans "Resize" %}</button>
{% else %}
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
{% endifequal %}
</form>
{% else %}
{% trans "You don't have permission for resizing instance" %}
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
{% endif %}
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="resizevm_disk">
{% 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 "Disk allocation (B):" %}</p>
{% for disk in disks %}
<div class="form-group">
@ -417,9 +457,9 @@
</div>
{% endfor %}
{% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="resize">{% trans "Resize" %}</button>
<button type="submit" class="btn btn-lg btn-success pull-right" name="resizevm_disk">{% trans "Resize" %}</button>
{% else %}
<button class="btn btn-lg btn-success pull-right disabled" name="resize">{% trans "Resize" %}</button>
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
{% endifequal %}
</form>
{% else %}
@ -833,10 +873,10 @@
<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 compute_networks %}
{% 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 compute_interfaces %}
{% 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>
@ -847,7 +887,7 @@
<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 compute_nwfilters %}
{% for c_filters in nwfilters_host %}
<option value="{{ c_filters }}" {% ifequal c_filters network.filterref %} selected {% endifequal %}>{{ c_filters }}</option>
{% endfor %}
</select>
@ -1501,11 +1541,11 @@
{% endif %}
</script>
<script>
$(document).ready(function(){
$(document).ready(function(){
$('[data-toggle="popover"]').popover({
placement : 'top'
});
});
});
</script>
<script>
function set_orderlist(obj){
@ -1516,7 +1556,7 @@ $(document).ready(function(){
});
obj.val(result);
}
$(document).ready(function () {
$(document).ready(function () {
{# Boot Order Arragements #}
jQuery.fn.multiselect = function() {
$(this).each(function() {
@ -1567,7 +1607,6 @@ $(document).ready(function () {
});
set_orderlist($("#bootorder"));
});
});
</script>
<script>
@ -1582,7 +1621,6 @@ $(document).ready(function () {
<script src="{% static "js/Chart.bundle.min.js" %}"></script>
<script>
$('#chartgraphs').on('shown.bs.tab', function (event) {
var cpu_ctx = $("#cpuChart").get(0).getContext("2d");
var cpuChart = new Chart(cpu_ctx, {
type: 'line',
@ -1803,7 +1841,6 @@ $(document).ready(function () {
$.getJSON('{% url 'inst_graph' compute_id vname %}', function (data) {
cpuChart.data.labels.push(data.timeline);
cpuChart.data.datasets[0].data.push(data.cpudata);
if (cpuChart.data.datasets[0].data.length > 10){
cpuChart.data.labels.shift();
@ -1812,8 +1849,6 @@ $(document).ready(function () {
cpuChart.update();
memChart.data.labels.push(data.timeline);
memChart.options.scales.yAxes[0].ticks.max = parseInt(data.memdata.total / 1024);
memChart.options.scales.yAxes[0].ticks.stepSize = parseInt(data.memdata.total / (1024 * 5));
memChart.data.datasets[0].data.push(data.memdata.used / 1024);
@ -1823,7 +1858,6 @@ $(document).ready(function () {
}
memChart.update();
for (let j = 0; j < data.blkdata.length; j++) {
diskChart[data.blkdata[j].dev].data.labels.push(data.timeline);
@ -1874,7 +1908,7 @@ $(document).ready(function () {
}
});
}
if (~$.inArray(hash, ['#resize'])) {
if (~$.inArray(hash, ['#resize', "resizevm_cpu", "resizevm_mem", "resizevm_disk"])) {
var btnsect = $('#navbtn>li>a');
$(btnsect).each(function () {
if ($(this).attr('href') === '#resize') {

View file

@ -24,7 +24,6 @@
</div>
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li class="active">
<i class="fa fa-dashboard"></i> <a href="{% url 'overview' compute.id %}">{% trans "Overview" %}</a>
@ -51,14 +50,13 @@
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not all_host_vms %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "Hypervisor doesn't have any instances" %}
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "Hypervisor doesn't have any instances" %}
</div>
</div>
{% else %}
@ -67,7 +65,7 @@
<thead>
<tr>
<th>{% trans 'Name' %}<br>{% trans 'Description' %}</th>
<th>{% trans 'Host' %}<br>{% trans 'User' %}</th>
<th>{% trans 'User' %}</th>
<th>{% trans 'Status' %}</th>
<th>{% trans 'VCPU' %}</th>
<th>{% trans 'Memory' %}</th>
@ -79,7 +77,7 @@
{% for vm, info in inst.items %}
<tr>
<td><a href="{% url 'instance' host.0 vm %}">{{ vm }}</a><br><small><em>{{ info.title }}</em></small></td>
<td><a href="{% url 'overview' host.0 %}">{{ host.1 }}</a><br><small><em>{% if info.userinstances.count > 0 %}{{ info.userinstances.first_user.user.username }}{% if info.userinstances.count > 1 %} (+{{ info.userinstances.count|add:"-1" }}){% endif %}{% endif %}</em></small></td>
<td><em>{% if info.userinstances.count > 0 %}{{ info.userinstances.first_user.user.username }}{% if info.userinstances.count > 1 %} (+{{ info.userinstances.count|add:"-1" }}){% endif %}{% endif %}</em></td>
<td>
{% ifequal info.status 1 %}<span class="text-success">{% trans "Active" %}</span>{% endifequal %}
{% ifequal info.status 5 %}<span class="text-danger">{% trans "Off" %}</span>{% endifequal %}
@ -87,7 +85,8 @@
</td>
<td>{{ info.vcpu }}</td>
<td>{{ info.memory|filesizeformat }}</td>
<td><form action="" method="post" role="form">{% csrf_token %}
<td>
<form action="" method="post" role="form">{% csrf_token %}
<input type="hidden" name="name" value="{{ vm }}"/>
<input type="hidden" name="compute_id" value="{{ host.0 }}"/>
{% ifequal info.status 5 %}
@ -100,16 +99,16 @@
<span class="glyphicon glyphicon-play"></span>
</button>
{% endif %}
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}" disabled>
<span class="glyphicon glyphicon-pause"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}" disabled>
<span class="glyphicon glyphicon-off"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}" disabled>
<span class="glyphicon glyphicon-refresh"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}" disabled>
<span class="glyphicon glyphicon-eye-open"></span>
</button>
{% endifequal %}
@ -117,21 +116,21 @@
<button class="btn btn-sm btn-default" type="submit" name="resume" title="{% trans "Resume" %}">
<span class="glyphicon glyphicon-play"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}" disabled>
<span class="glyphicon glyphicon-pause"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Off" %}">
<button class="btn btn-sm btn-default" type="submit" name="powerforce" title="{% trans "Force Off" %}" onclick="return confirm('Are you sure to force it down?')">
<span class="glyphicon glyphicon-off"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}" disabled>
<span class="glyphicon glyphicon-refresh"></span>
</button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}" disabled>
<span class="glyphicon glyphicon-eye-open"></span>
</button>
{% endifequal %}
{% ifequal info.status 1 %}
<button class="btn btn-sm btn-default disabled" title="{% trans "Power On" %}">
<button class="btn btn-sm btn-default disabled" title="{% trans "Power On" %}" disabled>
<span class="glyphicon glyphicon-play"></span>
</button>
<button class="btn btn-sm btn-default" type="submit" name="suspend" title="{% trans "Suspend" %}">
@ -143,9 +142,9 @@
<button class="btn btn-sm btn-default" type="submit" name="powercycle" title="{% trans "Power Cycle" %}" onclick="return confirm('Are you sure?')">
<span class="glyphicon glyphicon-refresh"></span>
</button>
<a href="#" class="btn btn-sm btn-default" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}">
<button class="btn btn-sm btn-default" type="button" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}">
<span class="glyphicon glyphicon-eye-open"></span>
</a>
</button>
{% endifequal %}
</form>
</td>

View file

@ -27,6 +27,7 @@ from logs.views import addlogmsg
from django.conf import settings
from django.contrib import messages
@login_required
def index(request):
"""
@ -100,11 +101,12 @@ def instances(request, compute_id):
def instance(request, compute_id, vname):
"""
:param request:
:param compute_id:
:param vname:
:return:
"""
error_messages = []
# messages = []
compute = get_object_or_404(Compute, pk=compute_id)
computes = Compute.objects.all().order_by('name')
computes_count = computes.count()
@ -257,9 +259,6 @@ def instance(request, compute_id, vname):
compute.password,
compute.type,
vname)
compute_networks = sorted(conn.get_networks())
compute_interfaces = sorted(conn.get_ifaces())
compute_nwfilters = conn.get_nwfilters()
status = conn.get_status()
autostart = conn.get_autostart()
bootmenu = conn.get_bootmenu()
@ -271,13 +270,13 @@ def instance(request, compute_id, vname):
cur_memory = conn.get_cur_memory()
title = conn.get_title()
description = conn.get_description()
networks = conn.get_net_device()
disks = conn.get_disk_devices()
media = conn.get_media_devices()
if len(media) != 0:
media_iso = sorted(conn.get_iso_media())
else:
media_iso = []
networks = conn.get_net_device()
vcpu_range = conn.get_max_cpus()
memory_range = [256, 512, 768, 1024, 2048, 3072, 4096, 6144, 8192, 16384]
@ -285,8 +284,6 @@ def instance(request, compute_id, vname):
insort(memory_range, memory)
if cur_memory not in memory_range:
insort(memory_range, cur_memory)
memory_host = conn.get_max_memory()
vcpu_host = len(vcpu_range)
telnet_port = conn.get_telnet_port()
console_type = conn.get_console_type()
console_port = conn.get_console_port()
@ -298,18 +295,16 @@ def instance(request, compute_id, vname):
console_passwd = conn.get_console_passwd()
clone_free_names = get_clone_free_names()
user_quota_msg = check_user_quota(0, 0, 0, 0)
storages = sorted(conn.get_storages())
cache_modes = sorted(conn.get_cache_modes().items())
default_cache = settings.INSTANCE_VOLUME_DEFAULT_CACHE
default_format = settings.INSTANCE_VOLUME_DEFAULT_FORMAT
default_owner = settings.INSTANCE_VOLUME_DEFAULT_OWNER
formats = conn.get_image_formats()
busses = conn.get_disk_bus_types()
default_bus = settings.INSTANCE_VOLUME_DEFAULT_BUS
show_access_root_password = settings.SHOW_ACCESS_ROOT_PASSWORD
show_access_ssh_keys = settings.SHOW_ACCESS_SSH_KEYS
clone_instance_auto_name = settings.CLONE_INSTANCE_AUTO_NAME
default_bus = settings.INSTANCE_VOLUME_DEFAULT_BUS
try:
instance = Instance.objects.get(compute_id=compute_id, name=vname)
@ -327,6 +322,15 @@ def instance(request, compute_id, vname):
userinstances = UserInstance.objects.filter(instance=instance).order_by('user__username')
allow_admin_or_not_template = request.user.is_superuser or request.user.is_staff or not instance.is_template
# Host resources
vcpu_host = len(vcpu_range)
memory_host = conn.get_max_memory()
bus_host = conn.get_disk_bus_types()
networks_host = sorted(conn.get_networks())
interfaces_host = sorted(conn.get_ifaces())
nwfilters_host = conn.get_nwfilters()
storages_host = sorted(conn.get_storages(True))
if request.method == 'POST':
if 'poweron' in request.POST:
if instance.is_template:
@ -460,8 +464,67 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#resize')
if 'resizevm_cpu' in request.POST and (
request.user.is_superuser or request.user.is_staff or userinstance.is_change):
new_vcpu = request.POST.get('vcpu', '')
new_cur_vcpu = request.POST.get('cur_vcpu', '')
quota_msg = check_user_quota(0, int(new_vcpu) - vcpu, 0, 0)
if not request.user.is_superuser and quota_msg:
msg = _("User %s quota reached, cannot resize CPU of '%s'!" % (quota_msg, instance.name))
error_messages.append(msg)
else:
cur_vcpu = new_cur_vcpu
vcpu = new_vcpu
conn.resize_cpu(cur_vcpu, vcpu)
msg = _("Resize CPU")
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):
new_memory = request.POST.get('memory', '')
new_memory_custom = request.POST.get('memory_custom', '')
if new_memory_custom:
new_memory = new_memory_custom
new_cur_memory = request.POST.get('cur_memory', '')
new_cur_memory_custom = request.POST.get('cur_memory_custom', '')
if new_cur_memory_custom:
new_cur_memory = new_cur_memory_custom
quota_msg = check_user_quota(0, 0, int(new_memory) - memory, 0)
if not request.user.is_superuser and quota_msg:
msg = _("User %s quota reached, cannot resize memory of '%s'!" % (quota_msg, instance.name))
error_messages.append(msg)
else:
cur_memory = new_cur_memory
memory = new_memory
conn.resize_mem(cur_memory, memory)
msg = _("Resize Memory")
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#resize')
if 'resizevm_disk' in request.POST and (
request.user.is_superuser or request.user.is_staff or userinstance.is_change):
disks_new = list()
for disk in disks:
input_disk_size = filesizefstr(request.POST.get('disk_size_' + disk['dev'], ''))
if input_disk_size > disk['size'] + (64 << 20):
disk['size_new'] = input_disk_size
disks_new.append(disk)
disk_sum = sum([disk['size'] >> 30 for disk in disks_new])
disk_new_sum = sum([disk['size_new'] >> 30 for disk in disks_new])
quota_msg = check_user_quota(0, 0, 0, disk_new_sum - disk_sum)
if not request.user.is_superuser and quota_msg:
msg = _("User %s quota reached, cannot resize disks of '%s'!" % (quota_msg, instance.name))
error_messages.append(msg)
else:
conn.resize_disk(disks_new)
msg = _("Resize")
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#resize')
if 'add_new_vol' in request.POST and allow_admin_or_not_template:
connCreate = wvmCreate(compute.hostname,
conn_create = wvmCreate(compute.hostname,
compute.login,
compute.password,
compute.type)
@ -474,7 +537,7 @@ def instance(request, compute_id, vname):
cache = request.POST.get('cache', default_cache)
target = get_new_disk_dev(media, disks, bus)
path = connCreate.create_volume(storage, name, size, format, meta_prealloc, default_owner)
path = conn_create.create_volume(storage, name, size, format, meta_prealloc, default_owner)
conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus)
msg = _('Attach new disk {} ({})'.format(name, format))
addlogmsg(request.user.username, instance.name, msg)
@ -486,16 +549,16 @@ def instance(request, compute_id, vname):
bus = request.POST.get('bus', default_bus)
cache = request.POST.get('cache', default_cache)
connCreate = wvmStorage(compute.hostname,
conn_create = wvmStorage(compute.hostname,
compute.login,
compute.password,
compute.type,
storage)
format = connCreate.get_volume_type(name)
path = connCreate.get_target_path()
format = conn_create.get_volume_type(name)
path = conn_create.get_target_path()
target = get_new_disk_dev(media, disks, bus)
source = path + "/" + name;
source = path + "/" + name
conn.attach_disk(source, target, subdriver=format, cache=cache, targetbus=bus)
msg = _('Attach Existing disk: ' + target)
@ -504,7 +567,7 @@ def instance(request, compute_id, vname):
if 'delete_vol' in request.POST and allow_admin_or_not_template:
storage = request.POST.get('storage', '')
connDelete = wvmStorage(compute.hostname,
conn_delete = wvmStorage(compute.hostname,
compute.login,
compute.password,
compute.type,
@ -514,7 +577,7 @@ def instance(request, compute_id, vname):
name = request.POST.get('name', '')
conn.detach_disk(dev)
connDelete.del_volume(name)
conn_delete.del_volume(name)
msg = _('Delete disk: ' + dev)
addlogmsg(request.user.username, instance.name, msg)
@ -625,8 +688,8 @@ def instance(request, compute_id, vname):
if bootorder:
order_list = {}
for idx, val in enumerate(bootorder.split(',')):
type, dev = val.split(':', 1)
order_list[idx] = {"type": type, "dev": dev}
dev_type, dev = val.split(':', 1)
order_list[idx] = {"type": dev_type, "dev": dev}
conn.set_bootorder(order_list)
msg = _("Set boot order")
@ -796,7 +859,7 @@ def instance(request, compute_id, vname):
elif not re.match(r'^[a-zA-Z0-9-]+$', clone_data['name']):
msg = _("Instance name '%s' contains invalid characters!" % clone_data['name'])
error_messages.append(msg)
elif not re.match(r'^([0-9A-F]{2})(\:?[0-9A-F]{2}){5}$', clone_data['clone-net-mac-0'],
elif not re.match(r'^([0-9A-F]{2})(:?[0-9A-F]{2}){5}$', clone_data['clone-net-mac-0'],
re.IGNORECASE):
msg = _("Instance mac '%s' invalid format!" % clone_data['clone-net-mac-0'])
error_messages.append(msg)
@ -847,6 +910,8 @@ def instance(request, compute_id, vname):
def inst_status(request, compute_id, vname):
"""
:param request:
:param compute_id:
:param vname:
:return:
"""
@ -988,6 +1053,12 @@ def instances_actions(request):
conn.shutdown(name)
return HttpResponseRedirect(request.get_full_path())
if 'powerforce' in request.POST:
conn.force_shutdown(name)
msg = _("Force Off")
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path())
if 'powercycle' in request.POST:
msg = _("Power Cycle")
conn.force_shutdown(name)
@ -1027,7 +1098,7 @@ def instances_actions(request):
addlogmsg(request.user.username, instance.name, msg)
conn.resume(name)
return HttpResponseRedirect(request.get_full_path())
return HttpResponseRedirect(request.get_full_path())
@login_required
def inst_graph(request, compute_id, vname):
@ -1174,7 +1245,7 @@ def _get_clone_disks(disks, vname=''):
def sshkeys(request, vname):
"""
:param request:
:param vm:
:param vname:
:return:
"""
@ -1213,7 +1284,7 @@ def delete_instance(instance, delete_disk=False):
print("Forcing shutdown")
conn.force_shutdown()
if delete_disk:
snapshots = sorted(conn.get_snapshot(), reverse=True, key=lambda k:k['date'])
snapshots = sorted(conn.get_snapshot(), reverse=True, key=lambda k: k['date'])
for snap in snapshots:
print("Deleting snapshot {}".format(snap['name']))
conn.snapshot_delete(snap['name'])

View file

@ -37,16 +37,16 @@
<div class="row">
<div class="col-xs-6 col-sm-4">
<p>{% trans "Interface:" %}</p>
<p>{% trans "IPv4:" %} ({% ifequal ipv4 None %}None{% else %}{{ ipv4_type }}{% endifequal %})</p>
<p>{% trans "IPv6:" %} ({% ifequal ipv6 None %}None{% else %}{{ ipv6_type }}{% endifequal %})</p>
<p>{% trans "MAC Adress:" %}</p>
<p>{% trans "Interface Type:" %}</p>
<p>{% trans "Interface" %}:</p>
<p>{% trans "IPv4" %}: ({% ifequal ipv4 None %}{% trans 'None' %}{% else %}{{ ipv4_type }}{% endifequal %})</p>
<p>{% trans "IPv6" %}: ({% ifequal ipv6 None %}{% trans 'None' %}{% else %}{{ ipv6_type }}{% endifequal %})</p>
<p>{% trans "MAC Adress" %}:</p>
<p>{% trans "Interface Type" %}:</p>
{% ifequal itype 'bridge' %}
<p>{% trans "Bridge device" %}</p>
{% endifequal %}
<p>{% trans "Boot Mode:" %}</p>
<p>{% trans "State:" %}</p>
<p>{% trans "Boot Mode" %}:</p>
<p>{% trans "State" %}:</p>
</div>
<div class="col-xs-6 col-sm-6">
<p><strong>{{ iface }}</strong></p>

View file

@ -12,6 +12,7 @@ from libvirt import libvirtError
def interfaces(request, compute_id):
"""
:param request:
:param compute_id:
:return:
"""
@ -60,6 +61,7 @@ def interfaces(request, compute_id):
def interface(request, compute_id, iface):
"""
:param request:
:param iface:
:return:
"""

View file

@ -18,7 +18,7 @@
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "You don't have any Logs" %}
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "You don't have any Logs" %}
</div>
</div>
{% else %}
@ -39,8 +39,8 @@
<tr>
<td>{{ log.id }}</td>
<td style="width:130px;">{{ log.date|date:"M d H:i:s" }}</td>
<td>{{ log.user }}</a></td>
<td>{{ log.instance }}</a></td>
<td>{{ log.user }}</td>
<td>{{ log.instance }}</td>
<td>{{ log.message }}</td>
</tr>
{% endfor %}

View file

@ -10,7 +10,9 @@ import json
def addlogmsg(user, instance, message):
"""
:param request:
:param user:
:param instance:
:param message:
:return:
"""
add_log_msg = Logs(user=user, instance=instance, message=message)
@ -21,6 +23,7 @@ def addlogmsg(user, instance, message):
def showlogs(request, page=1):
"""
:param request:
:param page:
:return:
"""
@ -36,11 +39,12 @@ def showlogs(request, page=1):
return render(request, 'showlogs.html', locals())
@login_required
def vm_logs(request, vname):
"""
:param request:
:param vm:
:param vname:
:return:
"""
@ -51,7 +55,7 @@ def vm_logs(request, vname):
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by('-date')
logs = []
for l in logs_:
log = {}
log = dict()
log['user'] = l.user
log['instance'] = l.instance
log['message'] = l.message

View file

@ -39,7 +39,6 @@
<input type="text" class="form-control" name="mac" required pattern="[0-9\/\:]+">
</div>
</div>
</div>
</div>
<div class="modal-footer">

View file

@ -41,7 +41,7 @@
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "Hypervisor doesn't have any Networks" %}
<i class="fa fa-exclamation-triangle"></i><strong>{% trans "Warning:" %}</strong> {% trans "Hypervisor doesn't have any Networks" %}
</div>
</div>
{% else %}

View file

@ -15,6 +15,7 @@ from django.contrib import messages
def networks(request, compute_id):
"""
:param request:
:param compute_id:
:return:
"""
@ -64,6 +65,8 @@ def networks(request, compute_id):
def network(request, compute_id, pool):
"""
:param request:
:param compute_id:
:param pool:
:return:
"""
@ -91,6 +94,7 @@ def network(request, compute_id, pool):
xml = conn._XMLDesc(0)
except libvirtError as lib_err:
error_messages.append(lib_err)
return HttpResponseRedirect(reverse('networks', args=compute_id))
if request.method == 'POST':
if 'start' in request.POST:

View file

@ -35,10 +35,10 @@
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
{% include 'messages_block.html' %}
{% include 'errors_block.html' %}
{% include 'messages_block.html' %}
<div class="row">
<div class="row">
<div class="col-lg-12">
<div class="pull-right">
@ -137,12 +137,12 @@
</div>
{% endif %}
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script src="{% static "js/sortable.min.js" %}"></script>
<script>
<script src="{% static "js/sortable.min.js" %}"></script>
<script>
$(document).ready(function () {
(function ($) {
$('#filter').keyup(function () {
@ -154,7 +154,7 @@
})
}(jQuery));
});
</script>
</script>
<script src="{% static "js/ace.js" %}"></script>
<script>

View file

@ -7,8 +7,8 @@
{% endblock %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_stg_vol_block.html' %}
<h1 class="page-header">{% trans "Storage:" %} {{ pool }}</h1>
@ -36,28 +36,28 @@
</li>
</ol>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
{% include 'messages_block.html' %}
{% include 'errors_block.html' %}
{% include 'messages_block.html' %}
<div class="row">
<div class="row">
<div class="col-xs-6 col-sm-6">
<p>{% trans "Pool name:" %}</p>
<p>{% trans "Pool type:" %}</p>
<p>{% trans "Pool path:" %}</p>
<p>{% trans "Pool status:" %}</p>
<p>{% trans "Size:" %} ({{ size|filesizeformat }} / {{ used|filesizeformat }})</p>
<p>{% trans "State:" %}</p>
<p>{% trans "Autostart:" %}</p>
<p>{% trans "Pool name" %}:</p>
<p>{% trans "Pool type" %}:</p>
<p>{% trans "Pool path" %}:</p>
<p>{% trans "Pool status" %}:</p>
<p>{% trans "Size" %}: ({{ size|filesizeformat }} / {{ used|filesizeformat }})</p>
<p>{% trans "State" %}:</p>
<p>{% trans "Autostart" %}:</p>
</div>
<div class="col-xs-6 col-sm-6">
<p>{{ pool }}</p>
<p>{% if not type %}{% trans "None" %}{% else %}{{ type }}{% endif %}</p>
<p>{% if not path %}{% trans "None" %}{% else %}{{ path }}{% endif %}</p>
<p>{% if not status %}{% trans "None" %}{% else %}{{ status }}{% endif %}</p>
<p>{% trans "Usage:" %} {{ percent }}%</p>
<p>{% trans "Usage" %}: {{ percent }}%</p>
<p>
<form action="" method="post" role="form">{% csrf_token %}
{% ifequal state 0 %}
@ -82,8 +82,8 @@
</form>
</p>
</div>
</div>
<div class="row">
</div>
<div class="row">
<div class="col-lg-12">
{% if state %}
<div class="row">
@ -187,14 +187,14 @@
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "Hypervisor doesn't have any Volumes" %}
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "Hypervisor doesn't have any Volumes" %}
</div>
</div>
{% endif %}
{% endif %}
</div>
</div>
{% include 'pleasewaitdialog.html' %}
</div>
{% include 'pleasewaitdialog.html' %}
{% endblock %}
{% block script %}
<script src="{% static "js/sortable.min.js" %}"></script>

View file

@ -10,10 +10,12 @@ from libvirt import libvirtError
from django.contrib import messages
import json
@login_required
def storages(request, compute_id):
"""
:param request:
:param compute_id:
:return:
"""
@ -72,6 +74,8 @@ def storages(request, compute_id):
def storage(request, compute_id, pool):
"""
:param request:
:param compute_id:
:param pool:
:return:
"""

View file

@ -6,7 +6,7 @@ Further Information might be available at:
https://github.com/haypo/python-ipy
"""
__version__ = '0.83'
__version__ = '1.00'
import bisect
import collections
@ -21,7 +21,7 @@ IPv4ranges = {
'00000000': 'PRIVATE', # 0/8
'00001010': 'PRIVATE', # 10/8
'0110010001': 'CARRIER_GRADE_NAT', # 100.64/10
'01111111': 'PRIVATE', # 127.0/8
'01111111': 'LOOPBACK', # 127.0/8
'1': 'PUBLIC', # fall back
'1010100111111110': 'PRIVATE', # 169.254/16
'101011000001': 'PRIVATE', # 172.16/12
@ -243,7 +243,7 @@ class IPint(object):
else:
raise ValueError("can't parse")
(self.ip, parsedVersion) = parseAddress(ip)
(self.ip, parsedVersion) = parseAddress(ip, ipversion)
if ipversion == 0:
ipversion = parsedVersion
if prefixlen == -1:
@ -473,7 +473,7 @@ class IPint(object):
"""Return a description of the IP type ('PRIVATE', 'RESERVED', etc).
>>> print(IP('127.0.0.1').iptype())
PRIVATE
LOOPBACK
>>> print(IP('192.168.1.1').iptype())
PRIVATE
>>> print(IP('195.185.1.2').iptype())
@ -553,6 +553,9 @@ class IPint(object):
"""
return True
def __bool__(self):
return self.__nonzero__()
def __len__(self):
"""
Return the length of a subnet.
@ -757,6 +760,9 @@ class IPint(object):
def __lt__(self, other):
return self.__cmp__(other) < 0
def __le__(self, other):
return self.__cmp__(other) <= 0
def __hash__(self):
"""Called for the key object for dictionary operations, and by
the built-in function hash(). Should return a 32-bit integer
@ -1328,7 +1334,7 @@ def _parseAddressIPv6(ipstr):
return value
def parseAddress(ipstr):
def parseAddress(ipstr, ipversion=0):
"""
Parse a string and return the corresponding IP address (as integer)
and a guess of the IP version.
@ -1397,7 +1403,7 @@ def parseAddress(ipstr):
# assume IPv6 in pure hexadecimal notation
return (hexval, 6)
elif ipstr.find('.') != -1 or (intval is not None and intval < 256):
elif ipstr.find('.') != -1 or (intval is not None and intval < 256 and ipversion != 6):
# assume IPv4 ('127' gets interpreted as '127.0.0.0')
bytes = ipstr.split('.')
if len(bytes) > 4:
@ -1415,7 +1421,7 @@ def parseAddress(ipstr):
# will be interpreted as IPv4 first byte
if intval > MAX_IPV6_ADDRESS:
raise ValueError("IP Address can't be larger than %x: %x" % (MAX_IPV6_ADDRESS, intval))
if intval <= MAX_IPV4_ADDRESS:
if intval <= MAX_IPV4_ADDRESS and ipversion != 6:
return (intval, 4)
else:
return (intval, 6)

View file

@ -2,7 +2,7 @@ import libvirt
import threading
import socket
from vrtManager import util
from rwlock import ReadWriteLock
from vrtManager.rwlock import ReadWriteLock
from django.conf import settings
from libvirt import libvirtError

View file

@ -2,7 +2,6 @@ import string
from vrtManager import util
from vrtManager.connection import wvmConnect
from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE
from webvirtcloud.settings import QEMU_CONSOLE_LISTEN_ADDRESSES
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_OWNER as default_owner
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_FORMAT
@ -39,7 +38,7 @@ class wvmCreate(wvmConnect):
except:
pass
for img in stg.listVolumes():
if img.endswith('.iso'):
if img.lower().endswith('.iso'):
pass
else:
images.append(img)
@ -107,7 +106,7 @@ class wvmCreate(wvmConnect):
if not pool:
storages = self.get_storages(only_actives=True)
else:
storages = [pool,]
storages = [pool]
for storage in storages:
stg = self.get_storage(storage)
if stg.info()[0] != 0:
@ -204,7 +203,6 @@ class wvmCreate(wvmConnect):
hd_disk_letters = list(string.lowercase)
sd_disk_letters = list(string.lowercase)
add_cd = True
#for image, img_type in images.items():
for volume in images:
stg = self.get_storage_by_vol_path(volume['path'])
stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
@ -283,8 +281,4 @@ class wvmCreate(wvmConnect):
<memballoon model='virtio'/>
</devices>
</domain>""" % video
self._defineXML(xml)

View file

@ -58,13 +58,13 @@ class wvmHostDetails(wvmConnect):
"""
Function return host server information: hostname, cpu, memory, ...
"""
info = []
info = list()
info.append(self.wvm.getHostname()) # hostname
info.append(self.wvm.getInfo()[0]) # architecture
info.append(self.wvm.getInfo()[1] * 1048576) # memory
info.append(self.wvm.getInfo()[2]) # cpu core count
info.append(get_xml_path(self.wvm.getSysinfo(0), func=cpu_version)) # cpu version
info.append(self.wvm.getURI()) #uri
info.append(self.wvm.getURI()) # uri
return info

View file

@ -237,9 +237,9 @@ class wvmInstance(wvmConnect):
try:
net = self.get_network(network_host)
ip = get_mac_ipaddr(net, mac_host)
except libvirtError as e:
except libvirtError:
ip = None
result.append({'mac': mac_host, 'nic': network_host, 'target': target_host,'ip': ip, 'filterref': filterref_host})
result.append({'mac': mac_host, 'nic': network_host, 'target': target_host, 'ip': ip, 'filterref': filterref_host})
return result
return util.get_xml_path(self._XMLDesc(0), func=networks)
@ -322,7 +322,7 @@ class wvmInstance(wvmConnect):
os = tree.find('os')
menu = os.find("bootmenu")
if menu == None:
if menu is None:
bootmenu = ElementTree.fromstring("<bootmenu enable='yes'/>")
os.append(bootmenu)
menu = os.find("bootmenu")
@ -365,7 +365,7 @@ class wvmInstance(wvmConnect):
for dev in devices:
dev_target = dev_type = dev_device = dev_alias = None
boot_dev = dev.find('boot')
if boot_dev != None:
if boot_dev is not None:
idx = boot_dev.get('order')
dev_type = dev.get('type')
dev_device = dev.get('device')
@ -398,7 +398,7 @@ class wvmInstance(wvmConnect):
# Remove rest of them
for dev in tree.find('devices'):
boot_dev = dev.find('boot')
if boot_dev != None:
if boot_dev is not None:
dev.remove(boot_dev)
return tree
@ -410,19 +410,19 @@ class wvmInstance(wvmConnect):
devices = tree.findall("./devices/disk[@device='disk']")
for d in devices:
device = d.find("./target[@dev='{}']".format(dev['dev']))
if device != None:
if device is not None:
d.append(order)
elif dev['type'] == 'cdrom':
devices = tree.findall("./devices/disk[@device='cdrom']")
for d in devices:
device = d.find("./target[@dev='{}']".format(dev['dev']))
if device != None:
if device is not None:
d.append(order)
elif dev['type'] == 'network':
devices = tree.findall("./devices/interface[@type='network']")
for d in devices:
device = d.find("mac[@address='{}']".format(dev['dev']))
if device != None:
if device is not None:
d.append(order)
else:
raise Exception('Invalid Device Type for boot order')
@ -478,7 +478,6 @@ class wvmInstance(wvmConnect):
self._defineXML(xmldom)
def attach_disk(self, source, target, sourcetype='file', device='disk', driver='qemu', subdriver='raw', cache='none', targetbus='ide'):
tree = ElementTree.fromstring(self._XMLDesc(0))
xml_disk = "<disk type='%s' device='%s'>" % (sourcetype, device)
if device == 'cdrom':
xml_disk += "<driver name='%s' type='%s'/>" % (driver, subdriver)
@ -656,7 +655,7 @@ class wvmInstance(wvmConnect):
return socket
def get_console_type(self):
console_type = util.get_xml_path(self._XMLDesc(0),"/domain/devices/graphics/@type")
console_type = util.get_xml_path(self._XMLDesc(0), "/domain/devices/graphics/@type")
return console_type
def set_console_type(self, console_type):
@ -741,7 +740,6 @@ class wvmInstance(wvmConnect):
"""
Function change ram and cpu on vds.
"""
memory = int(memory) * 1024
cur_memory = int(cur_memory) * 1024
# if dom is running change only ram
@ -769,6 +767,58 @@ class wvmInstance(wvmConnect):
new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml)
def resize_cpu(self, cur_vcpu, vcpu):
"""
Function change ram and cpu on vds.
"""
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
tree = ElementTree.fromstring(xml)
set_vcpu = tree.find('vcpu')
set_vcpu.text = vcpu
set_vcpu.set('current', cur_vcpu)
new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml)
def resize_mem(self, cur_memory, memory):
"""
Function change ram and cpu on vds.
"""
memory = int(memory) * 1024
cur_memory = int(cur_memory) * 1024
# if dom is running change only ram
if self.get_status() == VIR_DOMAIN_RUNNING:
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_LIVE)
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_CONFIG)
return
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
tree = ElementTree.fromstring(xml)
set_mem = tree.find('memory')
set_mem.text = str(memory)
set_cur_mem = tree.find('currentMemory')
set_cur_mem.text = str(cur_memory)
new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml)
def resize_disk(self, disks):
"""
Function change disks on vds.
"""
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
tree = ElementTree.fromstring(xml)
for disk in disks:
source_dev = disk['path']
vol = self.get_volume_by_path(source_dev)
vol.resize(disk['size_new'])
new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml)
def get_iso_media(self):
iso = []
storages = self.get_storages(only_actives=True)
@ -780,7 +830,7 @@ class wvmInstance(wvmConnect):
except:
pass
for img in stg.listVolumes():
if img.endswith('.iso'):
if img.lower().endswith('.iso'):
iso.append(img)
return iso
@ -956,7 +1006,6 @@ class wvmInstance(wvmConnect):
return bridge_name
def add_network(self, mac_address, source, source_type='net', interface_type='bridge', model='virtio', nwfilter=None):
tree = ElementTree.fromstring(self._XMLDesc(0))
bridge_name = self.get_bridge_name(source, source_type)
xml_interface = """
<interface type='%s'>
@ -978,7 +1027,6 @@ class wvmInstance(wvmConnect):
def delete_network(self, mac_address):
tree = ElementTree.fromstring(self._XMLDesc(0))
devices = tree.find('devices')
for interface in tree.findall('devices/interface'):
source = interface.find('mac')
if source.get('address', '') == mac_address:
@ -1038,7 +1086,7 @@ class wvmInstance(wvmConnect):
option = tree.find(o)
option_value = options.get(o, '').strip()
if not option_value:
if not option is None:
if option is not None:
tree.remove(option)
else:
if option is None:

View file

@ -22,6 +22,7 @@ def network_size(net, dhcp=None):
class wvmNetworks(wvmConnect):
def get_networks_info(self):
get_networks = self.get_networks()
networks = []
@ -166,7 +167,7 @@ class wvmNetwork(wvmConnect):
return dhcp[1]
def can_pxe(self):
xml = self.get_xml()
xml = self._XMLDesc(0)
forward = self.get_ipv4_forward()[0]
if forward and forward != "nat":
return True
@ -204,14 +205,14 @@ class wvmNetwork(wvmConnect):
break
if host is None:
self.update(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST, VIR_NETWORK_SECTION_IP_DHCP_HOST, -1, new_xml,
VIR_NETWORK_UPDATE_AFFECT_LIVE|VIR_NETWORK_UPDATE_AFFECT_CONFIG)
VIR_NETWORK_UPDATE_AFFECT_LIVE | VIR_NETWORK_UPDATE_AFFECT_CONFIG)
else:
# change the host
if host.get('name') == new_host_xml.get('name') and host.get('ip') == new_host_xml.get('ip'):
return False
else:
self.update(VIR_NETWORK_UPDATE_COMMAND_MODIFY, VIR_NETWORK_SECTION_IP_DHCP_HOST, -1, new_xml,
VIR_NETWORK_UPDATE_AFFECT_LIVE|VIR_NETWORK_UPDATE_AFFECT_CONFIG)
VIR_NETWORK_UPDATE_AFFECT_LIVE | VIR_NETWORK_UPDATE_AFFECT_CONFIG)
def delete_fixed_address(self, mac):
util.validate_macaddr(mac)
@ -222,7 +223,7 @@ class wvmNetwork(wvmConnect):
if h.get('mac') == mac:
new_xml = '<host mac="{}" name="{}" ip="{}"/>'.format(mac, h.get('name'), h.get('ip'))
self.update(VIR_NETWORK_UPDATE_COMMAND_DELETE, VIR_NETWORK_SECTION_IP_DHCP_HOST, -1, new_xml,
VIR_NETWORK_UPDATE_AFFECT_LIVE|VIR_NETWORK_UPDATE_AFFECT_CONFIG)
VIR_NETWORK_UPDATE_AFFECT_LIVE | VIR_NETWORK_UPDATE_AFFECT_CONFIG)
break
def modify_dhcp_range(self, range_start, range_end):

View file

@ -12,7 +12,7 @@ class wvmNWFilters(wvmConnect):
def create_nwfilter(self, xml):
self.wvm.nwfilterDefineXML(xml)
def clone_nwfilter(self,name, cln_name):
def clone_nwfilter(self, name, cln_name):
nwfilter = self.get_nwfilter(name)
if nwfilter:
tree = ElementTree.fromstring(nwfilter.XMLDesc(0))

View file

@ -7,11 +7,11 @@ class wvmSecrets(wvmConnect):
xml = """<secret ephemeral='%s' private='%s'>
<usage type='%s'>""" % (ephemeral, private, secret_type)
if secret_type == 'ceph':
xml += """<name>%s</name>""" % (data)
xml += """<name>%s</name>""" % data
if secret_type == 'volume':
xml += """<volume>%s</volume>""" % (data)
xml += """<volume>%s</volume>""" % data
if secret_type == 'iscsi':
xml += """<target>%s</target>""" % (data)
xml += """<target>%s</target>""" % data
xml += """</usage>
</secret>"""
self.wvm.secretDefineXML(xml)

View file

@ -110,7 +110,7 @@ def get_xpath(doc, path):
if ret is not None:
if type(ret) == list:
if len(ret) >= 1:
if hasattr(ret[0],'text'):
if hasattr(ret[0], 'text'):
result = ret[0].text
else:
result = ret[0]
@ -119,6 +119,7 @@ def get_xpath(doc, path):
return result
def pretty_mem(val):
val = int(val)
if val > (10 * 1024 * 1024):