summaryrefslogtreecommitdiffstats
path: root/dashboard
diff options
context:
space:
mode:
Diffstat (limited to 'dashboard')
-rw-r--r--dashboard/src/api/models.py30
-rw-r--r--dashboard/src/api/urls.py2
-rw-r--r--dashboard/src/api/views.py11
-rw-r--r--dashboard/src/resource_inventory/models.py21
4 files changed, 63 insertions, 1 deletions
diff --git a/dashboard/src/api/models.py b/dashboard/src/api/models.py
index 30f0f75..7109bbe 100644
--- a/dashboard/src/api/models.py
+++ b/dashboard/src/api/models.py
@@ -11,6 +11,7 @@
from django.contrib.auth.models import User
from django.db import models
from django.core.exceptions import PermissionDenied
+from django.shortcuts import get_object_or_404
import json
import uuid
@@ -21,7 +22,8 @@ from resource_inventory.models import (
HostProfile,
Host,
Image,
- Interface
+ Interface,
+ RemoteInfo
)
@@ -60,6 +62,32 @@ class LabManager(object):
def __init__(self, lab):
self.lab = lab
+ def update_host_remote_info(self, data, host_id):
+ host = get_object_or_404(Host, labid=host_id, lab=self.lab)
+ info = {}
+ try:
+ info['address'] = data['address']
+ info['mac_address'] = data['mac_address']
+ info['password'] = data['password']
+ info['user'] = data['user']
+ info['type'] = data['type']
+ info['versions'] = json.dumps(data['versions'])
+ except Exception as e:
+ return {"error": "invalid arguement: " + str(e)}
+ remote_info = host.remote_management
+ if "default" in remote_info.mac_address:
+ remote_info = RemoteInfo()
+ remote_info.address = info['address']
+ remote_info.mac_address = info['mac_address']
+ remote_info.password = info['password']
+ remote_info.user = info['user']
+ remote_info.type = info['type']
+ remote_info.versions = info['versions']
+ remote_info.save()
+ host.remote_management = remote_info
+ host.save()
+ return {"status": "success"}
+
def get_profile(self):
prof = {}
prof['name'] = self.lab.name
diff --git a/dashboard/src/api/urls.py b/dashboard/src/api/urls.py
index 50cc6ac..33a8289 100644
--- a/dashboard/src/api/urls.py
+++ b/dashboard/src/api/urls.py
@@ -39,6 +39,7 @@ from api.views import (
new_jobs,
current_jobs,
done_jobs,
+ update_host_bmc,
GenerateTokenView
)
@@ -51,6 +52,7 @@ urlpatterns = [
path('labs/<slug:lab_name>/profile', lab_profile),
path('labs/<slug:lab_name>/status', lab_status),
path('labs/<slug:lab_name>/inventory', lab_inventory),
+ path('labs/<slug:lab_name>/hosts/<slug:host_id>/bmc', update_host_bmc),
path('labs/<slug:lab_name>/jobs/<int:job_id>', specific_job),
path('labs/<slug:lab_name>/jobs/<int:job_id>/<slug:task_id>', specific_task),
path('labs/<slug:lab_name>/jobs/new', new_jobs),
diff --git a/dashboard/src/api/views.py b/dashboard/src/api/views.py
index c72c85c..90f87d9 100644
--- a/dashboard/src/api/views.py
+++ b/dashboard/src/api/views.py
@@ -62,6 +62,17 @@ def lab_status(request, lab_name=""):
return JsonResponse(lab_manager.get_status(), safe=False)
+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)
+ if request.method == "POST":
+ # update / create RemoteInfo for host
+ return JsonResponse(
+ lab_manager.update_host_remote_info(request.POST, host_id),
+ safe=False
+ )
+
+
def lab_profile(request, lab_name=""):
lab_token = request.META.get('HTTP_AUTH_TOKEN')
lab_manager = LabManagerTracker.get(lab_name, lab_token)
diff --git a/dashboard/src/resource_inventory/models.py b/dashboard/src/resource_inventory/models.py
index ebf63cc..5f7f3d3 100644
--- a/dashboard/src/resource_inventory/models.py
+++ b/dashboard/src/resource_inventory/models.py
@@ -291,6 +291,26 @@ class HostConfiguration(models.Model):
return "config with " + str(self.host) + " and image " + str(self.image)
+class RemoteInfo(models.Model):
+ address = models.CharField(max_length=15)
+ mac_address = models.CharField(max_length=17)
+ password = models.CharField(max_length=100)
+ user = models.CharField(max_length=100)
+ management_type = models.CharField(max_length=50, default="ipmi")
+ versions = models.CharField(max_length=100) # json serialized list of floats
+
+
+def get_default_remote_info():
+ RemoteInfo.objects.get_or_create(
+ address="default",
+ mac_address="default",
+ password="default",
+ user="default",
+ management_type="default",
+ versions="[default]"
+ )
+
+
# Concrete host, actual machine in a lab
class Host(models.Model):
id = models.AutoField(primary_key=True)
@@ -305,6 +325,7 @@ class Host(models.Model):
working = models.BooleanField(default=True)
vendor = models.CharField(max_length=100, default="unknown")
model = models.CharField(max_length=150, default="unknown")
+ remote_management = models.ForeignKey(RemoteInfo, default=get_default_remote_info, on_delete=models.SET(get_default_remote_info))
def __str__(self):
return self.name