:param request: :return:
(request)
| 33 | |
| 34 | |
| 35 | def instances(request): |
| 36 | """ |
| 37 | :param request: |
| 38 | :return: |
| 39 | """ |
| 40 | |
| 41 | if not request.user.is_authenticated(): |
| 42 | return HttpResponseRedirect(reverse('index')) |
| 43 | |
| 44 | error_messages = [] |
| 45 | all_host_vms = {} |
| 46 | all_user_vms = {} |
| 47 | computes = Compute.objects.all() |
| 48 | |
| 49 | if not request.user.is_superuser: |
| 50 | user_instances = UserInstance.objects.filter(user_id=request.user.id) |
| 51 | for usr_inst in user_instances: |
| 52 | if connection_manager.host_is_up(usr_inst.instance.compute.type, |
| 53 | usr_inst.instance.compute.hostname): |
| 54 | conn = wvmHostDetails(usr_inst.instance.compute, |
| 55 | usr_inst.instance.compute.login, |
| 56 | usr_inst.instance.compute.password, |
| 57 | usr_inst.instance.compute.type) |
| 58 | all_user_vms[usr_inst] = conn.get_user_instances(usr_inst.instance.name) |
| 59 | all_user_vms[usr_inst].update({'compute_id': usr_inst.instance.compute.id}) |
| 60 | else: |
| 61 | for comp in computes: |
| 62 | if connection_manager.host_is_up(comp.type, comp.hostname): |
| 63 | try: |
| 64 | conn = wvmHostDetails(comp, comp.login, comp.password, comp.type) |
| 65 | if conn.get_host_instances(): |
| 66 | all_host_vms[comp.id, comp.name] = conn.get_host_instances() |
| 67 | for vm, info in conn.get_host_instances().items(): |
| 68 | try: |
| 69 | check_uuid = Instance.objects.get(compute_id=comp.id, name=vm) |
| 70 | if check_uuid.uuid != info['uuid']: |
| 71 | check_uuid.save() |
| 72 | except Instance.DoesNotExist: |
| 73 | check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid']) |
| 74 | check_uuid.save() |
| 75 | conn.close() |
| 76 | except libvirtError as lib_err: |
| 77 | error_messages.append(lib_err) |
| 78 | |
| 79 | if request.method == 'POST': |
| 80 | name = request.POST.get('name', '') |
| 81 | compute_id = request.POST.get('compute_id', '') |
| 82 | instance = Instance.objects.get(compute_id=compute_id, name=name) |
| 83 | try: |
| 84 | conn = wvmInstances(instance.compute.hostname, |
| 85 | instance.compute.login, |
| 86 | instance.compute.password, |
| 87 | instance.compute.type) |
| 88 | if 'poweron' in request.POST: |
| 89 | msg = _("Power On") |
| 90 | addlogmsg(request.user.username, instance.name, msg) |
| 91 | conn.start(name) |
| 92 | return HttpResponseRedirect(request.get_full_path()) |
nothing calls this directly
no test coverage detected