1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-10-31 19:44:16 +00:00

Add logs and block for templates

This commit is contained in:
Retspen 2015-03-03 11:34:09 +02:00
parent 55e93a9087
commit 5960e94da5
35 changed files with 183 additions and 29 deletions

View file

@ -16,6 +16,9 @@ def computes(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
def get_hosts_status(computes):
"""
Function return all hosts all vds on host
@ -46,8 +49,10 @@ def compute(request, compute_id):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
errors = []
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
error_messages = []
compute = Compute.objects.get(id=compute_id)
try:
@ -59,7 +64,7 @@ def compute(request, compute_id):
hypervisor = conn.hypervisor_type()
mem_usage = conn.get_memory_usage()
conn.close()
except libvirtError as err:
errors.append(err)
except libvirtError as lib_err:
error_messages.append(lib_err)
return render(request, 'compute.html', locals())

View file

@ -20,6 +20,9 @@ def create_instance(request, compute_id):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
conn = None
error_messages = []
storages = []

View file

@ -16,6 +16,9 @@ def interfaces(request, compute_id):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
ifaces_all = []
error_messages = []
compute = Compute.objects.get(id=compute_id)
@ -60,6 +63,9 @@ def interface(request, compute_id, iface):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
ifaces_all = []
error_messages = []
compute = Compute.objects.get(id=compute_id)

0
logs/__init__.py Normal file
View file

3
logs/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('instances', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Logs',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('message', models.CharField(max_length=255)),
('date', models.DateTimeField()),
('instance', models.ForeignKey(to='instances.Instance')),
],
options={
},
bases=(models.Model,),
),
]

View file

11
logs/models.py Normal file
View file

@ -0,0 +1,11 @@
from django.db import models
from instances.models import Instance
class Logs(models.Model):
instance = models.ForeignKey(Instance)
message = models.CharField(max_length=255)
date = models.DateTimeField()
def __unicode__(self):
return self.instance

3
logs/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

8
logs/views.py Normal file
View file

@ -0,0 +1,8 @@
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from logs.models import Logs
def showlogs(request):
return render(request, 'showlogs.html', locals())

View file

@ -18,6 +18,9 @@ def networks(request, compute_id):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser():
return HttpResponseRedirect(reverse('index'))
error_messages = []
compute = Compute.objects.get(id=compute_id)
@ -63,6 +66,9 @@ def network(request, compute_id, pool):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
error_messages = []
compute = Compute.objects.get(id=compute_id)

View file

@ -16,6 +16,9 @@ def secrets(request, compute_id):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
secrets_all = []
error_messages = []
compute = Compute.objects.get(id=compute_id)

View file

@ -17,6 +17,9 @@ def storages(request, compute_id):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
error_messages = []
compute = Compute.objects.get(id=compute_id)

View file

@ -8,10 +8,12 @@
{% include 'sidebar.html' %}
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
{% include 'create_comp_block.html' %}
<h1 class="page-header">{{ compute.name }}</h1>
{% include 'errors.html' %}
{% include 'errors_block.html' %}
<h4>{% trans "Basic details" %}</h4>

View file

@ -8,10 +8,12 @@
{% include 'sidebar.html' %}
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
{% include 'create_comp_block.html' %}
<h1 class="page-header">Computes</h1>
{% include 'errors.html' %}
{% include 'errors_block.html' %}
<div class="row">
{% if computes_info %}

View file

@ -0,0 +1,5 @@
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
{% endif %}

View file

@ -0,0 +1,5 @@
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
{% endif %}

View file

@ -0,0 +1,5 @@
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
{% endif %}

View file

@ -11,7 +11,7 @@
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
<h1 class="page-header">{{ compute.name }}</h1>
{% include 'errors.html' %}
{% include 'errors_block.html' %}
</div>

View file

@ -0,0 +1,5 @@
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
{% endif %}

View file

@ -0,0 +1,5 @@
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
{% endif %}

View file

@ -0,0 +1,5 @@
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
{% endif %}

View file

@ -0,0 +1,5 @@
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
{% endif %}

View file

@ -1,8 +0,0 @@
{% if error_messages %}
{% for error in error_messages %}
<div class="alert alert-danger alert-dismissible" role="danger">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Error:</strong> {{ error }}
</div>
{% endfor %}
{% endif %}

View file

@ -0,0 +1,8 @@
{% if error_messages %}
{% for error in error_messages %}
<div class="alert alert-danger alert-dismissible" role="danger">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Error:</strong> {{ error }}
</div>
{% endfor %}
{% endif %}

View file

@ -8,12 +8,12 @@
{% include 'sidebar.html' %}
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
{% if request.user.is_superuser %}
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
{% endif %}
{% include 'create_inst_block.html' %}
<h1 class="page-header">{{ vname }}</h1>
{% include 'errors.html' %}
{% include 'errors_block.html' %}
</div>

View file

@ -8,11 +8,12 @@
{% include 'sidebar.html' %}
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
{% include 'create_inst_block.html' %}
<h1 class="page-header">Instances</h1>
{% include 'errors.html' %}
{% include 'errors_block.html' %}
<div class="table-responsive">
{% if request.user.is_superuser %}
@ -24,7 +25,7 @@
<th>VCPU</th>
<th>Memory</th>
<th>Status</th>
<th style="width:164px;">Actions</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@ -38,7 +39,7 @@
<span class="glyphicon glyphicon-tasks" aria-hidden="true"></span> <a href="{% url 'compute' host.0 %}">{{ host.1 }}</a>
</td>
<td>{{ info.vcpu }}</td>
<td>{{ info.memory }}</td>
<td>{{ info.memory }} {% trans "MB" %}</td>
<td>{% ifequal info.status 1 %}
<span class="label label-success">{% trans "Running" %}</span>
{% endifequal %}
@ -115,7 +116,7 @@
<th>VCPU</th>
<th>Memory</th>
<th>Status</th>
<th style="width:164px;">Actions</th>
<th>Actions</th>
</tr>
</thead>
<tbody>

20
templates/showlogs.html Normal file
View file

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Logs" %}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
{% include 'sidebar.html' %}
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">{% trans "Logs" %}</h1>
{% include 'errors_block.html' %}
</div>
</div>
</div>
{% endblock %}

View file

@ -8,6 +8,7 @@
{% if request.user.is_superuser %}
<li {% active request "^/compute" %}><a href="{% url 'computes' %}"><span class="glyphicon glyphicon-tasks" aria-hidden="true"></span></a></li>
<li {% active request "^/user" %}><a href="{% url 'users' %}"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a></li>
<li {% active request "^/showlogs" %}><a href="{% url 'showlogs' %}"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></a></li>
{% endif %}
<li class="bottom-sticky">
<a href="#"><span class="glyphicon glyphicon-cog" aria-hidden="true"></span></a>

View file

@ -11,7 +11,7 @@
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
<h1 class="page-header">{{ user.username }}</h1>
{% include 'errors.html' %}
{% include 'errors_block.html' %}
{{ user }}

View file

@ -11,7 +11,7 @@
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
<h1 class="page-header">{% trans "Accounts" %}</h1>
{% include 'errors.html' %}
{% include 'errors_block.html' %}
{% for user in users %}
<div id="{{ user.username }}" class="col-xs-6 col-sm-4">

View file

@ -1,4 +1,6 @@
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
@ -8,6 +10,12 @@ def users(request):
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
users = User.objects.filter(is_staff=False, is_superuser=False)
return render(request, 'users.html', locals())
@ -18,6 +26,12 @@ def user(request, user_id):
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
user = User.objects.get(id=user_id)
return render(request, 'user.html', locals())

View file

@ -436,7 +436,7 @@ class wvmConnect(object):
for name in self.get_instances():
dom = self.get_instance(name)
mem = util.get_xml_path(dom.XMLDesc(0), "/domain/currentMemory")
mem = int(mem) * 1024
mem = int(mem) / 1024
cur_vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu/@current")
if cur_vcpu:
vcpu = cur_vcpu

View file

@ -25,6 +25,7 @@ INSTALLED_APPS = (
'instances',
'users',
'create',
'logs',
)
MIDDLEWARE_CLASSES = (

View file

@ -31,5 +31,6 @@ urlpatterns = patterns('',
url(r'^console/$', 'console.views.console', name='console'),
url(r'^create/(\d+)/$', 'create.views.create_instance', name='create_instance'),
url(r'^logs/$', 'logs.views.showlogs', name='showlogs'),
(r'^admin/', include(admin.site.urls)),
)