From e00d336aeb6da542d8a54f157ab2e285cd4a3e57 Mon Sep 17 00:00:00 2001 From: Parker Berberian Date: Tue, 12 Mar 2019 10:28:48 -0400 Subject: Allow labs to retirieve and update some host information in the api Change-Id: Ib0682141351f7789c50d98a992ab166c2f033f4b Signed-off-by: Parker Berberian --- src/api/models.py | 16 ++++++++++++++++ src/api/urls.py | 2 ++ src/api/views.py | 12 ++++++++++++ 3 files changed, 30 insertions(+) (limited to 'src/api') diff --git a/src/api/models.py b/src/api/models.py index 7109bbe..b35adf2 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -116,6 +116,22 @@ class LabManager(object): inventory['host_types'] = self.serialize_host_profiles(profiles) return inventory + def get_host(self, hostname): + host = get_object_or_404(Host, labid=hostname, lab=self.lab) + return { + "booked": host.booked, + "working": host.working, + "type": host.profile.name + } + + def update_host(self, hostname, data): + host = get_object_or_404(Host, labid=hostname, lab=self.lab) + if "working" in data: + working = data['working'] == "true" + host.working = working + host.save() + return self.get_host(hostname) + def get_status(self): return {"status": self.lab.status} diff --git a/src/api/urls.py b/src/api/urls.py index 33a8289..d18a04d 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -40,6 +40,7 @@ from api.views import ( current_jobs, done_jobs, update_host_bmc, + lab_host, GenerateTokenView ) @@ -52,6 +53,7 @@ urlpatterns = [ path('labs//profile', lab_profile), path('labs//status', lab_status), path('labs//inventory', lab_inventory), + path('labs//hosts/', lab_host), path('labs//hosts//bmc', update_host_bmc), path('labs//jobs/', specific_job), path('labs//jobs//', specific_task), diff --git a/src/api/views.py b/src/api/views.py index 90f87d9..a56dcfe 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -54,6 +54,16 @@ def lab_inventory(request, lab_name=""): return JsonResponse(lab_manager.get_inventory(), safe=False) +@csrf_exempt +def lab_host(request, lab_name="", host_id=""): + lab_token = request.META.get('HTTP_AUTH_TOKEN') + lab_manager = LabManagerTracker.get(lab_name, lab_token) + if request.method == "GET": + return JsonResponse(lab_manager.get_host(host_id), safe=False) + if request.method == "POST": + return JsonResponse(lab_manager.update_host(host_id, request.POST), safe=False) + + def lab_status(request, lab_name=""): lab_token = request.META.get('HTTP_AUTH_TOKEN') lab_manager = LabManagerTracker.get(lab_name, lab_token) @@ -62,6 +72,7 @@ def lab_status(request, lab_name=""): return JsonResponse(lab_manager.get_status(), safe=False) +@csrf_exempt def update_host_bmc(request, lab_name="", host_id=""): lab_token = request.META.get('HTTP_AUTH_TOKEN') lab_manager = LabManagerTracker.get(lab_name, lab_token) @@ -104,6 +115,7 @@ def specific_task(request, lab_name="", job_id="", task_id=""): return JsonResponse(get_task(task_id).config.get_delta()) +@csrf_exempt def specific_job(request, lab_name="", job_id=""): lab_token = request.META.get('HTTP_AUTH_TOKEN') lab_manager = LabManagerTracker.get(lab_name, lab_token) -- cgit 1.2.3-korg