diff options
author | Justin Choquette <jchoquette@iol.unh.edu> | 2023-09-27 17:03:38 -0400 |
---|---|---|
committer | Justin Choquette <jchoquette@iol.unh.edu> | 2023-10-19 18:10:17 -0400 |
commit | aff53e072502d63d8002d9c83213ce7f9d12c352 (patch) | |
tree | 3a30adca1fe7c958ddc092dbf7b9fa24259dd923 /src/static/js/workflows | |
parent | 1947d40115c7b13f8617ea92078a6f910d6bc799 (diff) |
user subsystem clean up
Change-Id: Ia59bb7c1e4412693f55cdcaf9607bcb4158850ae
Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/static/js/workflows')
-rw-r--r-- | src/static/js/workflows/book-a-pod.js | 9 | ||||
-rw-r--r-- | src/static/js/workflows/workflow.js | 128 |
2 files changed, 27 insertions, 110 deletions
diff --git a/src/static/js/workflows/book-a-pod.js b/src/static/js/workflows/book-a-pod.js index 2396fdb..60a5370 100644 --- a/src/static/js/workflows/book-a-pod.js +++ b/src/static/js/workflows/book-a-pod.js @@ -247,13 +247,14 @@ const steps = { if (!response) { showError("The selected resources for this booking are unavailable at this time. Please select a different resource or try again later.", -1) } - if (response.bookingId) { + const r = JSON.parse(response) + if (r.bookingId) { showError("The booking has been successfully created.", -1) - window.location.href = "../../booking/detail/" + response.bookingId + "/"; // todo + window.location.href = "../../booking/detail/" + r.bookingId + "/"; return; } else { - if (response.error == true) { - showError(response.message, -1) + if (r.error == true) { + showError(r.message, -1) } else { showError("The booking could not be created at this time.", -1) } diff --git a/src/static/js/workflows/workflow.js b/src/static/js/workflows/workflow.js index 97892a2..02f79a5 100644 --- a/src/static/js/workflows/workflow.js +++ b/src/static/js/workflows/workflow.js @@ -1,26 +1,15 @@ /* Defines a common interface for creating workflows -Functions as the "view" part of MVC, or the "controller" part. Not really sure tbh +Functions as the "view" part of MVC, or the "controller" part. */ - -const HTTP = { - GET: "GET", - POST: "POST", - DELETE: "DELETE", - PUT: "PUT" -} - const endpoint = { LABS: "todo", // Not implemented FLAVORS: "flavor/", IMAGES: "images/", - TEMPLATES: "template/list/[username]", - SAVE_DESIGN_WORKFLOW: "todo", // Post MVP - SAVE_BOOKING_WORKFLOW: "todo", // Post MVP - MAKE_TEMPLATE: "template/create", - DELETE_TEMPLATE: "template", - MAKE_BOOKING: "booking/create", + TEMPLATES: "template/", + MAKE_TEMPLATE: "template/create/", + MAKE_BOOKING: "booking/create/", } /** Functions as a namespace for static methods that post to the dashboard, then send an HttpRequest to LibLaas, then receive the response */ @@ -28,25 +17,20 @@ class LibLaaSAPI { /** POSTs to dashboard, which then auths and logs the requests, makes the request to LibLaaS, and passes the result back to here. Treat this as a private function. Only use the async functions when outside of this class */ - static makeRequest(method, endpoint, workflow_data) { + static makeRequest(endpoint, json_data) { const token = document.getElementsByName('csrfmiddlewaretoken')[0].value + return new Promise((resolve, reject) => {// -> HttpResponse $.ajax( { - crossDomain: true, // might need to change this back to true - method: "POST", - contentType: "application/json; charset=utf-8", - dataType : 'json', + url: '../../liblaas/' + endpoint, + type: 'post', + data: JSON.stringify(json_data), headers: { - 'X-CSRFToken': token + 'X-CSRFToken': token, + 'Content-Type': 'application/json' }, - data: JSON.stringify( - { - "method": method, - "endpoint": endpoint, - "workflow_data": workflow_data - } - ), + dataType: 'text', timeout: 10000, success: (response) => { resolve(response); @@ -60,85 +44,44 @@ class LibLaaSAPI { } static async getLabs() { // -> List<LabBlob> - // return this.makeRequest(HTTP.GET, endpoint.LABS, {}); let jsonObject = JSON.parse('{"name": "UNH_IOL","description": "University of New Hampshire InterOperability Lab","location": "NH","status": 0}'); return [new LabBlob(jsonObject)]; } - static async getLabFlavors(lab_name) { // -> List<FlavorBlob> - const data = await this.handleResponse(this.makeRequest(HTTP.GET, endpoint.FLAVORS, {"lab_name": lab_name})); + static async getLabFlavors(project) { // -> List<FlavorBlob> + const response = await this.handleResponse(this.makeRequest(endpoint.FLAVORS, {"project": project})); let flavors = []; + let data = JSON.parse(response) if (data) { - for (const d of data) { + for (const d of data.flavors_list) { flavors.push(new FlavorBlob(d)) } } else { apiError("flavors") } return flavors; - // let jsonObject = JSON.parse('{"flavor_id": "aaa-bbb-ccc", "name": "HPE Gen 9", "description": "placeholder", "interfaces": ["ens1", "ens2", "ens3"]}') - // return [new FlavorBlob(jsonObject)]; } - static async getImagesForFlavor(flavor_id) { - let full_endpoint = endpoint.FLAVORS + flavor_id + '/[username]/' + endpoint.IMAGES; - const data = await this.handleResponse(this.makeRequest(HTTP.GET, full_endpoint, {})); - let images = [] - - if (data) { - for (const d of data) { - images.push(new ImageBlob(d)); - } - } else { - apiError("images") - } - - return images; - // let jsonObject = JSON.parse('{"image_id": "111-222-333", "name": "Arch Linux"}') - // let jsonObject2 = JSON.parse('{"image_id": "444-555-666", "name": "Oracle Linux"}') - // return [new ImageBlob(jsonObject), new ImageBlob(jsonObject2)]; - } - - /** Doesn't need to be passed a username because django will pull this from the request */ static async getTemplatesForUser() { // -> List<TemplateBlob> - const data = await this.handleResponse(this.makeRequest(HTTP.GET, endpoint.TEMPLATES, {})) + const response = await this.handleResponse(this.makeRequest(endpoint.TEMPLATES, {})) let templates = [] - + let data = JSON.parse(response) if (data) - for (const d of data) { + for (const d of data.templates_list) { templates.push(new TemplateBlob(d)) } else { apiError("templates") } return templates; - // let jsonObject = JSON.parse('{"id": "12345", "owner":"jchoquette", "lab_name":"UNH_IOL","pod_name":"test pod","pod_desc":"for e2e testing","public":false,"host_list":[{"hostname":"test-node","flavor":"1ca6169c-a857-43c6-80b7-09b608c0daec","image":"3fc3833e-7b8b-4748-ab44-eacec8d14f8b","cifile":[],"bondgroups":[{"connections":[{"tagged":true,"connects_to":"public"}],"ifaces":[{"name":"eno49","speed":{"value":10000,"unit":"BitsPerSecond"},"cardtype":"Unknown"}]}]}],"networks":[{"name":"public","public":true}]}') - // let jsonObject2 = JSON.parse('{"id":6789,"owner":"jchoquette","lab_name":"UNH_IOL","pod_name":"Other Host","pod_desc":"Default Template","public":false,"host_list":[{"cifile":["some ci data goes here"],"hostname":"node","flavor":"aaa-bbb-ccc","image":"111-222-333", "bondgroups":[{"connections": [{"tagged": false, "connects_to": "private"}], "ifaces": [{"name": "ens2"}]}]}],"networks":[{"name": "private", "public": false}]}'); - - return [new TemplateBlob(jsonObject)]; - } - - static async saveDesignWorkflow(templateBlob) { // -> bool - templateBlob.owner = user; - return await this.handleResponse(this.makeRequest(HTTP.PUT, endpoint.SAVE_DESIGN_WORKFLOW)) - } - - static async saveBookingWorkflow(bookingBlob) { // -> bool - bookingBlob.owner = user; - return await this.handleResponse(this.makeRequest(HTTP.PUT, endpoint.SAVE_BOOKING_WORKFLOW, bookingBlob)); } static async makeTemplate(templateBlob) { // -> UUID or null - templateBlob.owner = user; - return await this.handleResponse(this.makeRequest(HTTP.POST, endpoint.MAKE_TEMPLATE, templateBlob)); + templateBlob.owner = user; // todo - remove this and handle this in django + return await this.handleResponse(this.makeRequest(endpoint.MAKE_TEMPLATE, {"template_blob": templateBlob})); } - static async deleteTemplate(template_id) { // -> UUID or null - return await this.handleResponse(this.makeRequest(HTTP.DELETE, endpoint.DELETE_TEMPLATE + "/" + template_id, {})); - } - - /** PUT to the dashboard with the bookingBlob. Dashboard will fill in lab and owner, make the django model, then hit liblaas, then come back and fill in the agg_id */ static async makeBooking(bookingBlob) { - return await this.handleResponse(this.createDashboardBooking(bookingBlob)); + return await this.handleResponse(this.makeRequest(endpoint.MAKE_BOOKING, {"booking_blob": bookingBlob})); } /** Wraps a call in a try / catch, processes the result, and returns the response or null if it failed */ @@ -151,33 +94,6 @@ class LibLaaSAPI { return null; } } - - /** Uses PUT instead of POST to tell the dashboard that we want to create a dashboard booking instead of a liblaas request */ - static createDashboardBooking(bookingBlob) { - const token = document.getElementsByName('csrfmiddlewaretoken')[0].value - return new Promise((resolve, reject) => { // -> HttpResponse - $.ajax( - { - crossDomain: false, - method: "PUT", - contentType: "application/json; charset=utf-8", - dataType : 'json', - headers: { - 'X-CSRFToken': token - }, - data: JSON.stringify( - bookingBlob), - timeout: 10000, - success: (response) => { - resolve(response); - }, - error: (response) => { - reject(response); - } - } - ) - }) - } } |