aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-08-08 11:33:57 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-08-18 11:59:01 -0400
commitecadb07367d31c0929212618e120130f54af78da (patch)
treef626ef347f6fa7cb7f9ee962539a5f769bc3d471 /src/resource_inventory
parenta6168306c08e8d5b207b9acc48869180d194ff01 (diff)
MVP
Change-Id: Ib590302f49e7e66f8d04841fb6cb97baf623f51a Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory')
-rw-r--r--src/resource_inventory/urls.py10
-rw-r--r--src/resource_inventory/views.py47
2 files changed, 57 insertions, 0 deletions
diff --git a/src/resource_inventory/urls.py b/src/resource_inventory/urls.py
index f9bd07e..f230509 100644
--- a/src/resource_inventory/urls.py
+++ b/src/resource_inventory/urls.py
@@ -7,3 +7,13 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+from django.conf.urls import url
+from django.urls import path
+
+from resource_inventory.views import host_list_view, profile_view
+app_name = 'resource'
+urlpatterns = [
+ url(r'^list/$', host_list_view, name='host-list'),
+ path('profile/<str:resource_id>', profile_view),
+] \ No newline at end of file
diff --git a/src/resource_inventory/views.py b/src/resource_inventory/views.py
index f903394..837cc73 100644
--- a/src/resource_inventory/views.py
+++ b/src/resource_inventory/views.py
@@ -6,3 +6,50 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+import json
+from django.shortcuts import render
+from django.http import HttpResponse
+from api.views import list_hosts, list_flavors
+
+
+def host_list_view(request):
+ if request.method == "GET":
+ host_list = json.loads(list_hosts(request).content)
+ flavor_list = json.loads(list_flavors(request).content)
+ flavor_map = {}
+ for flavor in flavor_list:
+ flavor_map[flavor['flavor_id']] = flavor['name']
+
+ # Apparently Django Templating lacks many features that regular Jinja offers, so I need to get creative
+ for host in host_list:
+ id = host["flavor"]
+ name = flavor_map[id]
+ host["flavor"] = {"id": id, "name": name}
+
+ template = "resource/hosts.html"
+ context = {
+ "hosts": host_list,
+ "flavor_map": flavor_map
+ }
+ return render(request, template, context)
+
+ return HttpResponse(status=405)
+
+
+def profile_view(request, resource_id):
+ if request.method == "GET":
+ flavor_list = json.loads(list_flavors(request).content)
+ selected_flavor = {}
+ for flavor in flavor_list:
+ if flavor["flavor_id"] == resource_id:
+ selected_flavor = flavor
+ break
+
+ template = "resource/hostprofile_detail.html"
+ context = {
+ "flavor": selected_flavor
+ }
+ return render(request, template, context)
+
+ return HttpResponse(status=405) \ No newline at end of file