1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 03:54:15 +00:00
webvirtcloud/computes/views.py

70 lines
2.2 KiB
Python
Raw Normal View History

2015-02-27 08:53:51 +00:00
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.shortcuts import render
from computes.models import Compute
from vrtManager.hostdetails import wvmHostDetails
from vrtManager.connection import connection_manager
from libvirt import libvirtError
def computes(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
2015-02-27 09:28:22 +00:00
return HttpResponseRedirect(reverse('index'))
2015-02-27 08:53:51 +00:00
2015-03-03 09:34:09 +00:00
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
2015-02-27 08:53:51 +00:00
def get_hosts_status(computes):
"""
Function return all hosts all vds on host
"""
compute_data = []
for compute in computes:
compute_data.append({'id': compute.id,
2015-02-27 09:28:22 +00:00
'name': compute.name,
'hostname': compute.hostname,
'status': connection_manager.host_is_up(compute.type, compute.hostname),
'type': compute.type,
'login': compute.login,
'password': compute.password
})
2015-02-27 08:53:51 +00:00
return compute_data
computes = Compute.objects.filter()
computes_info = get_hosts_status(computes)
return render(request, 'computes.html', locals())
2015-03-04 13:43:29 +00:00
def overview(request, compute_id):
2015-02-27 08:53:51 +00:00
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
2015-02-27 09:28:22 +00:00
return HttpResponseRedirect(reverse('index'))
2015-02-27 08:53:51 +00:00
2015-03-03 09:34:09 +00:00
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
2015-02-27 08:53:51 +00:00
2015-03-03 09:34:09 +00:00
error_messages = []
2015-02-27 08:53:51 +00:00
compute = Compute.objects.get(id=compute_id)
try:
conn = wvmHostDetails(compute.hostname,
compute.login,
compute.password,
compute.type)
hostname, host_arch, host_memory, logical_cpu, model_cpu, uri_conn = conn.get_node_info()
hypervisor = conn.hypervisor_type()
mem_usage = conn.get_memory_usage()
conn.close()
2015-03-03 09:34:09 +00:00
except libvirtError as lib_err:
error_messages.append(lib_err)
2015-02-27 08:53:51 +00:00
2015-03-04 13:43:29 +00:00
return render(request, 'overview.html', locals())