From 91f01d884b32304e446c35617ed404d0d9589019 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 16 Nov 2018 16:04:26 +0300 Subject: [PATCH] add get_volumes function to view. And Remove unused 'get' artifact. --- storages/views.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/storages/views.py b/storages/views.py index 4893a27..2b3910f 100644 --- a/storages/views.py +++ b/storages/views.py @@ -205,12 +205,23 @@ def storage(request, compute_id, pool): else: for msg_err in form.errors.values(): error_messages.append(msg_err.as_text()) - if request.method == 'GET': - if 'get_volumes' in request.GET: - conn.close() - return HttpResponse(json.dumps(sorted(volumes))) conn.close() return render(request, 'storage.html', locals()) + +@login_required +def get_volumes(request, compute_id, pool): + data = {} + compute = get_object_or_404(Compute, pk=compute_id) + try: + conn = wvmStorage(compute.hostname, + compute.login, + compute.password, + compute.type, + pool) + except libvirtError as liberr: + pass + data['vols'] = sorted(conn.get_volumes()) + return HttpResponse(json.dumps(data)) \ No newline at end of file