From 2958a21ad1d0390525b2a2d6d648cbe3a2d0f15f Mon Sep 17 00:00:00 2001 From: Jan Krcmar Date: Thu, 11 Feb 2016 14:37:26 +0100 Subject: [PATCH] instance/check_instance service endpoint added. checks for existing instance (returns json) --- instances/urls.py | 2 ++ instances/views.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/instances/urls.py b/instances/urls.py index c1b2841..5df6755 100644 --- a/instances/urls.py +++ b/instances/urls.py @@ -10,4 +10,6 @@ urlpatterns = [ views.inst_status, name='inst_status'), url(r'^guess_mac_address/(?P[\w\-\.]+)/$', views.guess_mac_address, name='guess_mac_address'), + url(r'^check_instance/(?P[\w\-\.]+)/$', + views.check_instance, name='check_instance'), ] diff --git a/instances/views.py b/instances/views.py index 57caf46..1f1f9c1 100644 --- a/instances/views.py +++ b/instances/views.py @@ -680,3 +680,11 @@ def guess_mac_address(request, vname): data['mac'] = line.split(' ')[-1].strip().strip(';') break return HttpResponse(json.dumps(data)); + +@login_required +def check_instance(request, vname): + check_instance = Instance.objects.filter(name=vname) + data = { 'vname': vname, 'exists': False } + if check_instance: + data['exists'] = True + return HttpResponse(json.dumps(data));