diff --git a/computes/views.py b/computes/views.py index 2b6d36d..80c2327 100644 --- a/computes/views.py +++ b/computes/views.py @@ -2,7 +2,7 @@ import time import json from django.http import HttpResponse, HttpResponseRedirect from django.core.urlresolvers import reverse -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from computes.models import Compute from instances.models import Instance from accounts.models import UserInstance @@ -143,7 +143,7 @@ def overview(request, compute_id): return HttpResponseRedirect(reverse('index')) error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmHostDetails(compute.hostname, @@ -172,7 +172,7 @@ def compute_graph(request, compute_id): points = 5 datasets = {} cookies = {} - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) curent_time = time.strftime("%H:%M:%S") try: diff --git a/create/views.py b/create/views.py index 3b99328..60b4279 100644 --- a/create/views.py +++ b/create/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse @@ -29,7 +29,7 @@ def create_instance(request, compute_id): networks = [] meta_prealloc = False computes = Compute.objects.all() - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) flavors = Flavor.objects.filter().order_by('id') try: diff --git a/instances/views.py b/instances/views.py index 42722ac..f8fc024 100644 --- a/instances/views.py +++ b/instances/views.py @@ -5,7 +5,7 @@ from random import choice from bisect import insort from django.http import HttpResponse, HttpResponseRedirect from django.core.urlresolvers import reverse -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.utils.translation import ugettext_lazy as _ from computes.models import Compute from instances.models import Instance @@ -134,7 +134,7 @@ def instance(request, compute_id, vname): error_messages = [] messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) computes = Compute.objects.all() computes_count = len(computes) keymaps = QEMU_KEYMAPS @@ -161,7 +161,8 @@ def instance(request, compute_id, vname): else: image = disk['image'] + "-clone" clone_disk.append( - {'dev': disk['dev'], 'storage': disk['storage'], 'image': image, 'format': disk['format']}) + {'dev': disk['dev'], 'storage': disk['storage'], + 'image': image, 'format': disk['format']}) return clone_disk try: @@ -424,7 +425,7 @@ def instance(request, compute_id, vname): return render(request, 'instances/instance.html', locals()) -def inst_status(request, host_id, vname): +def inst_status(request, compute_id, vname): """ :param request: :return: @@ -433,7 +434,7 @@ def inst_status(request, host_id, vname): if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('login')) - compute = Compute.objects.get(id=host_id) + compute = get_object_or_404(Compute, pk=compute_id) response = HttpResponse() response['Content-Type'] = "text/javascript" @@ -468,7 +469,7 @@ def inst_graph(request, compute_id, vname): cookies = {} points = 5 curent_time = time.strftime("%H:%M:%S") - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) response = HttpResponse() response['Content-Type'] = "text/javascript" @@ -547,7 +548,8 @@ def inst_graph(request, compute_id, vname): json_net.append({'dev': net['dev'], 'data': [datasets_rx, datasets_tx]}) datasets_net[net['dev']] = [datasets_rx, datasets_tx] - data = json.dumps({'cpudata': datasets['cpu'], 'blkdata': json_blk, 'netdata': json_net, 'timeline': datasets['timer']}) + data = json.dumps({'cpudata': datasets['cpu'], 'blkdata': json_blk, + 'netdata': json_net, 'timeline': datasets['timer']}) response.cookies['cpu'] = datasets['cpu'] response.cookies['timer'] = datasets['timer'] diff --git a/interfaces/views.py b/interfaces/views.py index a438dab..7d05ff9 100644 --- a/interfaces/views.py +++ b/interfaces/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from computes.models import Compute @@ -21,7 +21,7 @@ def interfaces(request, compute_id): ifaces_all = [] error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmInterfaces(compute.hostname, @@ -71,7 +71,7 @@ def interface(request, compute_id, iface): ifaces_all = [] error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmInterface(compute.hostname, diff --git a/networks/views.py b/networks/views.py index a70c6c0..e174f6e 100644 --- a/networks/views.py +++ b/networks/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse @@ -22,7 +22,7 @@ def networks(request, compute_id): return HttpResponseRedirect(reverse('index')) error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmNetworks(compute.hostname, @@ -73,7 +73,7 @@ def network(request, compute_id, pool): return HttpResponseRedirect(reverse('index')) error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmNetwork(compute.hostname, diff --git a/secrets/views.py b/secrets/views.py index 85bc671..cb2075a 100644 --- a/secrets/views.py +++ b/secrets/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from computes.models import Compute @@ -21,7 +21,7 @@ def secrets(request, compute_id): secrets_all = [] error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmSecrets(compute.hostname, diff --git a/storages/views.py b/storages/views.py index 0f6389b..5e125cc 100644 --- a/storages/views.py +++ b/storages/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse @@ -21,7 +21,7 @@ def storages(request, compute_id): return HttpResponseRedirect(reverse('index')) error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) try: conn = wvmStorages(compute.hostname, @@ -85,7 +85,7 @@ def storage(request, compute_id, pool): destination.close() error_messages = [] - compute = Compute.objects.get(id=compute_id) + compute = get_object_or_404(Compute, pk=compute_id) meta_prealloc = False try: diff --git a/webvirtcloud/urls.py b/webvirtcloud/urls.py index 5f17abe..e2b1bc6 100644 --- a/webvirtcloud/urls.py +++ b/webvirtcloud/urls.py @@ -4,23 +4,21 @@ from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'^$', 'instances.views.index', name='index'), url(r'^instances/$', 'instances.views.instances', name='instances'), + url(r'^instance/', include('instances.urls')), url(r'^accounts/', include('accounts.urls')), url(r'^computes/', include('computes.urls')), - url(r'^compute/stgs/(?P[0-9]+)/$', 'storages.views.storages', name='storages'), - url(r'^compute/stg/(?P[0-9]+)/(?P[\w\-\.]+)/$', 'storages.views.storage', name='storage'), - - url(r'^compute/nets/(?P[0-9]+)/$', 'networks.views.networks', name='networks'), - url(r'^compute/net/(?P[0-9]+)/(?P[\w\-\.]+)/$', 'networks.views.network', name='network'), - - url(r'^compute/ifaces/(?P[0-9]+)/$', 'interfaces.views.interfaces', name='interfaces'), - url(r'^compute/iface/(?P[0-9]+)/(?P[\w\-\.\:]+)/$', 'interfaces.views.interface', name='interface'), - - url(r'^compute/secret/(?P[0-9]+)/$', 'secrets.views.secrets', name='secrets'), + url(r'^compute/(?P[0-9]+)/storages/$', 'storages.views.storages', name='storages'), + url(r'^compute/(?P[0-9]+)/storage/(?P[\w\-\.]+)/$', 'storages.views.storage', name='storage'), + url(r'^compute/(?P[0-9]+)/networks/$', 'networks.views.networks', name='networks'), + url(r'^compute/(?P[0-9]+)/network/(?P[\w\-\.]+)/$', 'networks.views.network', name='network'), + url(r'^compute/(?P[0-9]+)/interfaces/$', 'interfaces.views.interfaces', name='interfaces'), + url(r'^compute/(?P[0-9]+)/interface/(?P[\w\-\.\:]+)/$', 'interfaces.views.interface', name='interface'), + url(r'^compute/(?P[0-9]+)/secrets/$', 'secrets.views.secrets', name='secrets'), + url(r'^compute/(?P[0-9]+)/create/$', 'create.views.create_instance', name='create_instance'), url(r'^console/$', 'console.views.console', name='console'), - url(r'^create/(?P[0-9]+)/$', 'create.views.create_instance', name='create_instance'), url(r'^logs/$', 'logs.views.showlogs', name='showlogs'), # (r'^admin/', include(admin.site.urls)), )