diff options
author | Raven Hodgdon <jhodgdon@iol.unh.edu> | 2022-06-02 16:23:23 -0400 |
---|---|---|
committer | Raven Hodgdon <jhodgdon@iol.unh.edu> | 2022-06-03 09:19:09 -0400 |
commit | 627171dc89fbfb07863c8df6b23cf0e10709139a (patch) | |
tree | a6df495eab2b3c5f1eb984d04c8da76a1fd5939a /src | |
parent | 9367a2ced41c26f9d799a7b3de7cdee3f6b6247c (diff) |
rebuilt host import admin util
Signed-off-by: jhodgon <jhodgdon@iol.unh.edu>
Change-Id: I6f602266fd5b62a5193afeb842c79e11c408dd16
Diffstat (limited to 'src')
-rw-r--r-- | src/dashboard/admin_utils.py | 120 | ||||
-rw-r--r-- | src/static/package-lock.json | 91 |
2 files changed, 210 insertions, 1 deletions
diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py index 821ca03..75e4f3e 100644 --- a/src/dashboard/admin_utils.py +++ b/src/dashboard/admin_utils.py @@ -27,6 +27,7 @@ from resource_inventory.models import ( ) import json +import yaml import sys import inspect import pydoc @@ -443,6 +444,125 @@ def print_dict_pretty(a_dict): print(json.dumps(a_dict, sort_keys=True, indent=4)) +def import_host(filenames): + """ + Imports host from an array of converted inspection files and if needed creates a new profile for the host. + NOTE: CONVERT INSPECTION FILES USING convert_inspect_results(["file", "file"]) + (original file names not including "-import.yaml" i.e. hpe44) AND FILL IN <NEEDED FIELDS> BEFORE THIS + @filenames: array of host import file names to import + """ + + for filename in filenames: + + # open import file + file = open("dashboard/" + filename + "-import.yaml", "r") + data = yaml.safe_load(file) + + # if a new profile is needed create one and a matching template + if (data["new_profile"]): + add_profile(data) + print("Profile: " + data["name"] + " created!") + make_default_template( + ResourceProfile.objects.get(name=data["name"]), + Image.objects.get(lab_id=data["image"]).id, + None, + None, + False, + False, + data["owner"], + "unh_iol", + True, + False, + data["temp_desc"] + ) + + print(" Template: " + data["temp_name"] + " created!") + + # add the server + add_server( + ResourceProfile.objects.get(name=data["name"]), + data["hostname"], + data["interfaces"], + data["lab"], + data["vendor"], + data["model"] + ) + + print(data["hostname"] + " imported!") + + +def convert_inspect_results(files): + """ + Converts an array of inspection result files into templates (filename-import.yaml) to be filled out for importing the servers into the dashboard + @files an array of file names (not including the file type. i.e hpe44). Default: [] + """ + for filename in files: + # open host inspect file + file = open("dashboard/" + filename + ".yaml") + output = open("dashboard/" + filename + "-import.yaml", "w") + data = json.load(file) + + # gather data about disks + disk_data = {} + for i in data["disk"]: + + # don't include loops in disks + if "loop" not in i: + disk_data[i["name"]] = { + "capacity": i["size"][:-3], + "media_type": "<\"SSD\" or \"HDD\">", + "interface": "<\"sata\", \"sas\", \"ssd\", \"nvme\", \"scsi\", or \"iscsi\">", + } + + # gather interface data + interface_data = {} + for i in data["interfaces"]: + interface_data[data["interfaces"][i]["name"]] = { + "speed": data["interfaces"][i]["speed"], + "nic_type": "<\"onboard\" or \"pcie\">", + "order": "<order in switch>", + "mac_address": data["interfaces"][i]["mac"], + "bus_addr": data["interfaces"][i]["busaddr"], + } + + # gather cpu data + cpu_data = { + "cores": data["cpu"]["cores"], + "architecture": data["cpu"]["arch"], + "cpus": data["cpu"]["cpus"], + "cflags": "<cflags string>", + } + + # gather ram data + ram_data = { + "amount": data["memory"][:-1], + "channels": "<int of ram channels used>", + } + + # assemble data for host import file + import_data = { + "new_profile": "<True or False> (Set to True to create a new profile for the host's type)", + "name": "<profile name> (Used to set the profile of a host and for creating a new profile)", + "description": "<profile description>", + "labs": "<labs using profile>", + "temp_name": "<Template name>", + "temp_desc": "<template description>", + "image": "<image lab_id>", + "owner": "<template owner>", + "hostname": data["hostname"], + "lab": "<lab server is in> (i.e. \"unh_iol\")", + "disks": disk_data, + "interfaces": interface_data, + "cpus": cpu_data, + "ram": ram_data, + "vendor": "<host vendor>", + "model": "<host model>", + } + + # export data as yaml + yaml.dump(import_data, output) + + def add_profile(data): """ Used for adding a host profile to the dashboard diff --git a/src/static/package-lock.json b/src/static/package-lock.json index f8eabe4..89a26db 100644 --- a/src/static/package-lock.json +++ b/src/static/package-lock.json @@ -1,8 +1,97 @@ { "name": "laas", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "laas", + "version": "1.0.0", + "license": "Apache-2.0", + "dependencies": { + "@fortawesome/fontawesome-free": "^5.12.0", + "bootstrap": "^4.4.1", + "datatables.net-bs4": "^1.10.20", + "datatables.net-responsive-bs4": "^2.2.3", + "jquery": "^3.4.1", + "mxgraph": "^4.0.6", + "plotly.js-dist": "^1.51.3", + "popper.js": "^1.16.0" + } + }, + "node_modules/@fortawesome/fontawesome-free": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.12.0.tgz", + "integrity": "sha512-vKDJUuE2GAdBERaQWmmtsciAMzjwNrROXA5KTGSZvayAsmuTGjam5z6QNqNPCwDfVljLWuov1nEC3mEQf/n6fQ==", + "engines": { + "node": ">=6" + } + }, + "node_modules/bootstrap": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.4.1.tgz", + "integrity": "sha512-tbx5cHubwE6e2ZG7nqM3g/FZ5PQEDMWmMGNrCUBVRPHXTJaH7CBDdsLeu3eCh3B1tzAxTnAbtmrzvWEvT2NNEA==", + "engines": { + "node": ">=6" + } + }, + "node_modules/datatables.net": { + "version": "1.10.20", + "resolved": "https://registry.npmjs.org/datatables.net/-/datatables.net-1.10.20.tgz", + "integrity": "sha512-4E4S7tTU607N3h0fZPkGmAtr9mwy462u+VJ6gxYZ8MxcRIjZqHy3Dv1GNry7i3zQCktTdWbULVKBbkAJkuHEnQ==", + "dependencies": { + "jquery": "3.4.1" + } + }, + "node_modules/datatables.net-bs4": { + "version": "1.10.20", + "resolved": "https://registry.npmjs.org/datatables.net-bs4/-/datatables.net-bs4-1.10.20.tgz", + "integrity": "sha512-kQmMUMsHMOlAW96ztdoFqjSbLnlGZQ63iIM82kHbmldsfYdzuyhbb4hTx6YNBi481WCO3iPSvI6YodNec46ZAw==", + "dependencies": { + "datatables.net": "1.10.20", + "jquery": "3.4.1" + } + }, + "node_modules/datatables.net-responsive": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/datatables.net-responsive/-/datatables.net-responsive-2.2.3.tgz", + "integrity": "sha512-8D6VtZcyuH3FG0Hn5A4LPZQEOX3+HrRFM7HjpmsQc/nQDBbdeBLkJX4Sh/o1nzFTSneuT1Wh/lYZHVPpjcN+Sw==", + "dependencies": { + "datatables.net": "1.10.20", + "jquery": "3.4.1" + } + }, + "node_modules/datatables.net-responsive-bs4": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/datatables.net-responsive-bs4/-/datatables.net-responsive-bs4-2.2.3.tgz", + "integrity": "sha512-SQaWI0uLuPcaiBBin9zX+MuQfTSIkK1bYxbXqUV6NLkHCVa6PMQK7Rvftj0ywG4R7uOtjbzY8nSVqxEKvQI0Vg==", + "dependencies": { + "datatables.net-bs4": "1.10.20", + "datatables.net-responsive": "2.2.3", + "jquery": "3.4.1" + } + }, + "node_modules/jquery": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", + "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==" + }, + "node_modules/mxgraph": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/mxgraph/-/mxgraph-4.0.6.tgz", + "integrity": "sha512-5XZXeAkA4k6n4BS05Fxd2cNhMw+3dnlRqAaLtsuXdT0g8BvvEa1VT4jjuGtUW4QTt38Q+I2Dr/3EWiAaGRfAXw==" + }, + "node_modules/plotly.js-dist": { + "version": "1.51.3", + "resolved": "https://registry.npmjs.org/plotly.js-dist/-/plotly.js-dist-1.51.3.tgz", + "integrity": "sha512-Bxz0XBg963gpnbt7FVPEhYvT33JsaKa0hEozXBnQZkiKtsiM2M1lZN6tkEHmq6o1N2K6qJXFtdzCXbZ/hLGV0Q==" + }, + "node_modules/popper.js": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.0.tgz", + "integrity": "sha512-+G+EkOPoE5S/zChTpmBSSDYmhXJ5PsW8eMhH8cP/CQHMFPBG/kC9Y5IIw6qNYgdJ+/COf0ddY2li28iHaZRSjw==" + } + }, "dependencies": { "@fortawesome/fontawesome-free": { "version": "5.12.0", |