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

56 lines
1.5 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 index(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('login'))
else:
return HttpResponseRedirect(reverse('instances'))
def instances(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-02-27 09:51:33 +00:00
error_messages = []
2015-02-27 08:53:51 +00:00
all_host_vms = {}
2015-02-27 09:51:33 +00:00
computes = Compute.objects.filter()
2015-02-27 08:53:51 +00:00
for compute in computes:
if connection_manager.host_is_up(compute.type, compute.hostname):
try:
conn = wvmHostDetails(compute, compute.login, compute.password, compute.type)
all_host_vms[compute.id, compute.name] = conn.get_host_instances()
conn.close()
2015-02-27 09:51:33 +00:00
except libvirtError as lib_err:
error_messages.append(lib_err)
2015-02-27 08:53:51 +00:00
return render(request, 'instances.html', locals())
def instance(request, comptes_id, vname):
"""
: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
return render(request, 'instances.html', locals())