:param request: :return:
(request)
| 13 | |
| 14 | |
| 15 | def computes(request): |
| 16 | """ |
| 17 | :param request: |
| 18 | :return: |
| 19 | """ |
| 20 | |
| 21 | if not request.user.is_authenticated(): |
| 22 | return HttpResponseRedirect(reverse('index')) |
| 23 | |
| 24 | if not request.user.is_superuser: |
| 25 | return HttpResponseRedirect(reverse('index')) |
| 26 | |
| 27 | def get_hosts_status(computes): |
| 28 | """ |
| 29 | Function return all hosts all vds on host |
| 30 | """ |
| 31 | compute_data = [] |
| 32 | for compute in computes: |
| 33 | compute_data.append({'id': compute.id, |
| 34 | 'name': compute.name, |
| 35 | 'hostname': compute.hostname, |
| 36 | 'status': connection_manager.host_is_up(compute.type, compute.hostname), |
| 37 | 'type': compute.type, |
| 38 | 'login': compute.login, |
| 39 | 'password': compute.password |
| 40 | }) |
| 41 | return compute_data |
| 42 | |
| 43 | error_messages = [] |
| 44 | computes = Compute.objects.filter() |
| 45 | computes_info = get_hosts_status(computes) |
| 46 | |
| 47 | if request.method == 'POST': |
| 48 | if 'host_del' in request.POST: |
| 49 | compute_id = request.POST.get('host_id', '') |
| 50 | try: |
| 51 | del_user_inst_on_host = UserInstance.objects.filter(instance__compute_id=compute_id) |
| 52 | del_user_inst_on_host.delete() |
| 53 | finally: |
| 54 | try: |
| 55 | del_inst_on_host = Instance.objects.filter(compute_id=compute_id) |
| 56 | del_inst_on_host.delete() |
| 57 | finally: |
| 58 | del_host = Compute.objects.get(id=compute_id) |
| 59 | del_host.delete() |
| 60 | return HttpResponseRedirect(request.get_full_path()) |
| 61 | if 'host_tcp_add' in request.POST: |
| 62 | form = ComputeAddTcpForm(request.POST) |
| 63 | if form.is_valid(): |
| 64 | data = form.cleaned_data |
| 65 | new_tcp_host = Compute(name=data['name'], |
| 66 | hostname=data['hostname'], |
| 67 | type=CONN_TCP, |
| 68 | login=data['login'], |
| 69 | password=data['password']) |
| 70 | new_tcp_host.save() |
| 71 | return HttpResponseRedirect(request.get_full_path()) |
| 72 | else: |
nothing calls this directly
no test coverage detected