aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2021-01-11 15:02:03 -0500
committerSawyer Bergeron <sbergeron@iol.unh.edu>2021-01-11 20:39:36 +0000
commitb28a17658565e07bbef9130550d1530f7678ef3f (patch)
tree77218acec43eb620bd9e531fe5a059dd085473ae /src
parent6f9071549baa597c2819ab0dd255f937a1891c3d (diff)
Add server create function to admin utils2.2.0-rc12.2.0
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Change-Id: I5776213bfc2eda310049c47dcb1fa1a601bd1896 (cherry picked from commit c77b9169b09b7b53572b45a4f3679e602b8ca6a2)
Diffstat (limited to 'src')
-rw-r--r--src/dashboard/admin_utils.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py
index 4b9c258..6d990c9 100644
--- a/src/dashboard/admin_utils.py
+++ b/src/dashboard/admin_utils.py
@@ -12,7 +12,8 @@ from resource_inventory.models import (
Network,
DiskProfile,
CpuProfile,
- RamProfile
+ RamProfile,
+ Interface
)
import json
@@ -346,3 +347,38 @@ def make_default_template(resource_profile, image_id=None, template_name=None, c
print("adding connection to iface ", iface)
iface.save()
connection.save()
+
+
+"""
+Note: interfaces should be dict from interface name (eg ens1f0) to dict of schema:
+ {
+ mac_address: <mac addr>,
+ bus_addr: <bus addr>, //this field is optional, "" is default
+ }
+"""
+
+
+def add_server(profile, uname, interfaces, lab_username="unh_iol", vendor="unknown", model="unknown"):
+ server = Server.objects.create(
+ bundle=None,
+ profile=profile,
+ config=None,
+ working=True,
+ vendor=vendor,
+ model=model,
+ labid=uname,
+ lab=Lab.objects.get(lab_user__username=lab_username),
+ name=uname,
+ booked=False)
+
+ for iface_prof in InterfaceProfile.objects.filter(host=profile).all():
+ mac_addr = interfaces[iface_prof.name]["mac_address"]
+ bus_addr = "unknown"
+ if "bus_addr" in interfaces[iface_prof.name].keys():
+ bus_addr = interfaces[iface_prof.name]["bus_addr"]
+
+ iface = Interface.objects.create(acts_as=None, profile=iface_prof, mac_address=mac_addr, bus_address=bus_addr)
+ iface.save()
+
+ server.interfaces.add(iface)
+ server.save()