mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
Fixed users instances
This commit is contained in:
parent
1e91fb303f
commit
2e976fc101
11 changed files with 135 additions and 30 deletions
|
@ -44,8 +44,8 @@ def instances(request):
|
|||
usr_inst.instance.compute.login,
|
||||
usr_inst.instance.compute.password,
|
||||
usr_inst.instance.compute.type)
|
||||
all_user_vms[usr_inst.instance.compute.id,
|
||||
usr_inst.instance.compute.name] = conn.get_user_instances(usr_inst.instance.name)
|
||||
all_user_vms[usr_inst] = conn.get_user_instances(usr_inst.instance.name)
|
||||
all_user_vms[usr_inst].update({'host_id': usr_inst.instance.compute.id})
|
||||
else:
|
||||
for compute in computes:
|
||||
if connection_manager.host_is_up(compute.type, compute.hostname):
|
||||
|
|
|
@ -82,4 +82,8 @@ body {
|
|||
|
||||
.search {
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.btn-header {
|
||||
margin-top: 5px;
|
||||
}
|
52
templates/base_auth.html
Normal file
52
templates/base_auth.html
Normal file
|
@ -0,0 +1,52 @@
|
|||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="WebVirtMgr panel for manage virtual machine">
|
||||
<meta name="author" content="anatoliy.guskov@gmail.com">
|
||||
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
|
||||
<!-- Bootstrap Core CSS -->
|
||||
<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet">
|
||||
|
||||
<!-- SB admin CSS -->
|
||||
<link href="{% static "css/sb-admin.css" %}" rel="stylesheet">
|
||||
|
||||
<!-- WebVirtCloud CSS -->
|
||||
<link href="{% static "css/webvirtcloud.css" %}" rel="stylesheet">
|
||||
|
||||
<!-- Aditional CSS -->
|
||||
{% block style %}{% endblock %}
|
||||
|
||||
<!-- Custom Fonts -->
|
||||
<link href="{% static "font-awesome/css/font-awesome.min.css" %}" rel="stylesheet" type="text/css">
|
||||
|
||||
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="{% static "js/jquery.js" %}"></script>
|
||||
|
||||
<!-- Bootstrap Core JavaScript -->
|
||||
<script src="{% static "js/bootstrap.min.js" %}"></script>
|
||||
|
||||
{% block script %}{% endblock %}
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,6 +1,6 @@
|
|||
{% load i18n %}
|
||||
{% if request.user.is_superuser %}
|
||||
<a href="#AddInstance" type="button" class="btn btn-success pull-right" data-toggle="modal">
|
||||
<a href="#AddInstance" type="button" class="btn btn-success btn-header pull-right" data-toggle="modal">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
</a>
|
||||
|
||||
|
|
|
@ -212,6 +212,7 @@
|
|||
</div>
|
||||
{% else %}
|
||||
<div class="col-lg-12">
|
||||
<h3 class="page-header">{% trans "Create from flover" %}</h3>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
|
|
|
@ -1,5 +1,36 @@
|
|||
{% load i18n %}
|
||||
{% if request.user.is_superuser %}
|
||||
<button type="button" class="btn btn-success pull-right">
|
||||
<a href="#addUserInst" type="button" class="btn btn-success pull-right" data-toggle="modal">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
</button>
|
||||
</a>
|
||||
|
||||
<!-- Modal pool -->
|
||||
<div class="modal fade" id="addUserInst" tabindex="-1" role="dialog" aria-labelledby="addUserInstLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">{% trans "Add Instance for User" %}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">{% trans "Host / Instance" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select class="form-control" name="inst_id">
|
||||
{% for inst in instances %}
|
||||
<option value="{{ inst.id }}">{{ inst.compute.name }} / {{ inst.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
|
||||
<button type="submit" class="btn btn-primary" name="add">{% trans "Add" %}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div> <!-- /.modal-content -->
|
||||
</div> <!-- /.modal-dialog -->
|
||||
</div> <!-- /.modal -->
|
||||
{% endif %}
|
|
@ -9,6 +9,9 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
{% include 'create_inst_block.html' %}
|
||||
<div class="pull-right search">
|
||||
<input id="filter" class="form-control" type="text" placeholder="Search">
|
||||
</div>
|
||||
<h1 class="page-header">{% trans "Instances" %}</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -19,9 +22,6 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="table-responsive">
|
||||
<div class="pull-right search">
|
||||
<input id="filter" class="form-control" type="text" placeholder="Search">
|
||||
</div>
|
||||
{% if request.user.is_superuser %}
|
||||
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
|
||||
<thead>
|
||||
|
@ -108,30 +108,27 @@
|
|||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="pull-right search">
|
||||
<input id="filter" class="form-control" type="text" placeholder="Search">
|
||||
</div>
|
||||
<table class="table table-hover table-striped">
|
||||
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Status</th>
|
||||
<th>VCPU</th>
|
||||
<th>Memory</th>
|
||||
<th>Actions</th>
|
||||
<th data-sortable="false" style="width: 165px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="searchable">
|
||||
{% for host, vm in all_user_vms.items %}
|
||||
{% for inst, vm in all_user_vms.items %}
|
||||
<tr>
|
||||
<td><a href="{% url 'instance' host.0 vm.name %}">{{ vm.name }}</a></td>
|
||||
<td><a href="{% url 'instance' vm.host_id vm.name %}">{{ vm.name }}</a></td>
|
||||
<td>{% ifequal vm.status 1 %}
|
||||
<p class="text-success">{% trans "Active" %}</p>
|
||||
{% endifequal %}
|
||||
{% ifequal info.status 5 %}
|
||||
{% ifequal vm.status 5 %}
|
||||
<p class="text-danger">{% trans "Off" %}</p>
|
||||
{% endifequal %}
|
||||
{% ifequal info.status 3 %}
|
||||
{% ifequal vm.status 3 %}
|
||||
<p class="text-warning">{% trans "Suspend" %}</p>
|
||||
{% endifequal %}
|
||||
</td>
|
||||
|
@ -139,7 +136,7 @@
|
|||
<td>{{ vm.memory }} {% trans "MB" %}</td>
|
||||
<td><form action="" method="post" role="form">{% csrf_token %}
|
||||
<input type="hidden" name="name" value="{{ vm.name }}"/>
|
||||
<input type="hidden" name="compute" value="{{ host.0 }}"/>
|
||||
<input type="hidden" name="compute" value="{{ vm.host_id }}"/>
|
||||
{% ifequal vm.status 5 %}
|
||||
<button class="btn btn-sm btn-default" type="submit" name="start" title="Start">
|
||||
<span class="glyphicon glyphicon-play"></span>
|
||||
|
@ -204,12 +201,6 @@
|
|||
window.open("{% url 'console' %}?token=" + uuid, "", "width=850,height=485");
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function goto_compute() {
|
||||
var compute = $("#compute_select").val();
|
||||
window.location = "/create/" + compute + "/";
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
(function ($) {
|
||||
|
@ -223,4 +214,12 @@
|
|||
}(jQuery));
|
||||
});
|
||||
</script>
|
||||
{% if request.user.is_superuser %}
|
||||
<script>
|
||||
function goto_compute() {
|
||||
var compute = $("#compute_select").val();
|
||||
window.location = "/create/" + compute + "/";
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "base.html" %}
|
||||
{% extends "base_auth.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Sign In" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "base.html" %}
|
||||
{% extends "base_auth.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Sign Out" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
|
|
@ -77,16 +77,19 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
{% if state %}
|
||||
<h3 class="page-header">{% trans "Volumes" %}</h3>
|
||||
{% if volumes %}
|
||||
<div class="table-responsive">
|
||||
<div class="row">
|
||||
<div class="pull-right search">
|
||||
<input id="filter" class="form-control" type="text" placeholder="Search">
|
||||
</div>
|
||||
<h3 class="page-header">{% trans "Volumes" %}</h3>
|
||||
|
||||
</div>
|
||||
{% if volumes %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped sortable-theme-bootstrap" data-sortable>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:35px;">#</th>
|
||||
<th style="width: 45px;">#</th>
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th>{% trans "Size" %}</th>
|
||||
<th>{% trans "Format" %}</th>
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
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 users.models import UserInstance
|
||||
from instances.models import Instance
|
||||
from users.forms import UserAddForm
|
||||
|
||||
|
||||
|
@ -36,6 +38,7 @@ def users(request):
|
|||
|
||||
return render(request, 'users.html', locals())
|
||||
|
||||
|
||||
def user(request, user_id):
|
||||
"""
|
||||
:param request:
|
||||
|
@ -48,8 +51,10 @@ def user(request, user_id):
|
|||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
error_messages = []
|
||||
user = User.objects.get(id=user_id)
|
||||
user_insts = UserInstance.objects.filter(user_id=user_id)
|
||||
instances = Instance.objects.all()
|
||||
|
||||
if request.method == 'POST':
|
||||
if 'delete' in request.POST:
|
||||
|
@ -68,5 +73,15 @@ def user(request, user_id):
|
|||
edit_user_inst.is_delete = bool(inst_delete)
|
||||
edit_user_inst.save()
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
if 'add' in request.POST:
|
||||
inst_id = request.POST.get('inst_id', '')
|
||||
try:
|
||||
check_inst = UserInstance.objects.get(instance_id=int(inst_id))
|
||||
msg = _("Instance already added")
|
||||
error_messages.append(msg)
|
||||
except UserInstance.DoesNotExist:
|
||||
add_user_inst = UserInstance(instance_id=int(inst_id), user_id=user_id)
|
||||
add_user_inst.save()
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
|
||||
return render(request, 'user.html', locals())
|
Loading…
Reference in a new issue