mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Enabled instances buttons
This commit is contained in:
parent
bf5b0a9a42
commit
9b02c64ff4
2 changed files with 36 additions and 11 deletions
|
@ -5,6 +5,7 @@ from computes.models import Compute
|
|||
from instances.models import Instance
|
||||
from users.models import UserInstance
|
||||
from vrtManager.hostdetails import wvmHostDetails
|
||||
from vrtManager.instance import wvmInstance, wvmInstances
|
||||
from vrtManager.connection import connection_manager
|
||||
from libvirt import libvirtError
|
||||
|
||||
|
@ -45,25 +46,49 @@ def instances(request):
|
|||
usr_inst.instance.compute.password,
|
||||
usr_inst.instance.compute.type)
|
||||
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})
|
||||
all_user_vms[usr_inst].update({'compute_id': usr_inst.instance.compute.id})
|
||||
else:
|
||||
for compute in computes:
|
||||
if connection_manager.host_is_up(compute.type, compute.hostname):
|
||||
for comp in computes:
|
||||
if connection_manager.host_is_up(comp.type, comp.hostname):
|
||||
try:
|
||||
conn = wvmHostDetails(compute, compute.login, compute.password, compute.type)
|
||||
all_host_vms[compute.id, compute.name] = conn.get_host_instances()
|
||||
conn = wvmHostDetails(comp, comp.login, comp.password, comp.type)
|
||||
all_host_vms[comp.id, comp.name] = conn.get_host_instances()
|
||||
for vm, info in conn.get_host_instances().items():
|
||||
try:
|
||||
check_uuid = Instance.objects.get(compute_id=compute.id, name=vm)
|
||||
check_uuid = Instance.objects.get(compute_id=comp.id, name=vm)
|
||||
if check_uuid.uuid != info['uuid']:
|
||||
check_uuid.save()
|
||||
except Instance.DoesNotExist:
|
||||
check_uuid = Instance(compute_id=compute.id, name=vm, uuid=info['uuid'])
|
||||
check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid'])
|
||||
check_uuid.save()
|
||||
conn.close()
|
||||
except libvirtError as lib_err:
|
||||
error_messages.append(lib_err)
|
||||
|
||||
if request.method == 'POST':
|
||||
name = request.POST.get('name', '')
|
||||
compute_id = request.POST.get('compute_id', '')
|
||||
compute = Compute.objects.get(id=compute_id)
|
||||
try:
|
||||
conn = wvmInstances(compute.hostname,
|
||||
compute.login,
|
||||
compute.password,
|
||||
compute.type)
|
||||
if 'start' in request.POST:
|
||||
conn.start(name)
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
if 'destroy' in request.POST:
|
||||
conn.force_shutdown(name)
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
if 'suspend' in request.POST:
|
||||
conn.suspend(name)
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
if 'resume' in request.POST:
|
||||
conn.resume(name)
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
except libvirtError as lib_err:
|
||||
error_messages.append(lib_err)
|
||||
|
||||
return render(request, 'instances.html', locals())
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue