aboutsummaryrefslogtreecommitdiffstats
path: root/src/static/js/workflows/design-a-pod.js
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/static/js/workflows/design-a-pod.js
parenta6168306c08e8d5b207b9acc48869180d194ff01 (diff)
MVP
Change-Id: Ib590302f49e7e66f8d04841fb6cb97baf623f51a Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/static/js/workflows/design-a-pod.js')
-rw-r--r--src/static/js/workflows/design-a-pod.js51
1 files changed, 38 insertions, 13 deletions
diff --git a/src/static/js/workflows/design-a-pod.js b/src/static/js/workflows/design-a-pod.js
index 58f8b85..2083f7d 100644
--- a/src/static/js/workflows/design-a-pod.js
+++ b/src/static/js/workflows/design-a-pod.js
@@ -89,7 +89,6 @@ class DesignWorkflow extends Workflow {
this.labImages = new Map(); // Map<UUID, ImageBlob>
for (const fblob of flavorsList) {
- fblob.images = await LibLaaSAPI.getImagesForFlavor(fblob.flavor_id);
for (const iblob of fblob.images) {
this.labImages.set(iblob.image_id, iblob)
}
@@ -110,18 +109,17 @@ class DesignWorkflow extends Workflow {
this.step = steps.ADD_RESOURCES;
if (this.templateBlob.lab_name == null) {
- showError("Please select a lab before adding resources.");
- this.goTo(steps.SELECT_LAB);
+ showError("Please select a lab before adding resources.", steps.SELECT_LAB);
return;
}
if (this.templateBlob.host_list.length >= 8) {
- showError("You may not add more than 8 hosts to a single pod.")
+ showError("You may not add more than 8 hosts to a single pod.", -1)
return;
}
this.resourceBuilder = null;
- GUI.refreshAddHostModal(this.userTemplates);
+ GUI.refreshAddHostModal(this.userTemplates, this.labFlavors);
$("#resource_modal").modal('toggle');
}
@@ -248,6 +246,7 @@ class DesignWorkflow extends Workflow {
for (const [index, host] of this.resourceBuilder.user_configs.entries()) {
const new_host = new HostConfigBlob(host);
this.templateBlob.host_list.push(new_host);
+ this.labFlavors.get(host.flavor).available_count--
}
// Add networks
@@ -274,6 +273,7 @@ class DesignWorkflow extends Workflow {
for (let existing_host of this.templateBlob.host_list) {
if (hostname == existing_host.hostname) {
this.removeHostFromTemplateBlob(existing_host);
+ this.labFlavors.get(existing_host.flavor).available_count++;
GUI.refreshHostStep(this.templateBlob.host_list, this.labFlavors, this.labImages);
GUI.refreshNetworkStep(this.templateBlob.networks);
GUI.refreshConnectionStep(this.templateBlob.host_list);
@@ -282,7 +282,7 @@ class DesignWorkflow extends Workflow {
}
}
- showError("didnt remove");
+ showError("didnt remove", -1);
}
@@ -297,8 +297,7 @@ class DesignWorkflow extends Workflow {
this.step = steps.ADD_NETWORKS;
if (this.templateBlob.lab_name == null) {
- showError("Please select a lab before adding networks.");
- this.goTo(steps.SELECT_LAB);
+ showError("Please select a lab before adding networks.", steps.SELECT_LAB);
return;
}
@@ -561,8 +560,7 @@ class DesignWorkflow extends Workflow {
this.step = steps.POD_SUMMARY;
const simpleValidation = this.simpleStepValidation();
if (!simpleValidation[0]) {
- showError(simpleValidation[1])
- this.goTo(simpleValidation[2]);
+ showError(simpleValidation[1], simpleValidation[2])
return;
}
@@ -632,7 +630,7 @@ class GUI {
/** Resets the host modal inner html
* Takes a list of templateBlobs
*/
- static refreshAddHostModal(template_list) {
+ static refreshAddHostModal(template_list, flavor_map) {
document.getElementById('add_resource_modal_body').innerHTML = `
<h2>Resource</h2>
<div id="template-cards" class="row align-items-center justify-content-start">
@@ -663,13 +661,39 @@ class GUI {
const template_cards = document.getElementById('template-cards');
for (let template of template_list) {
- template_cards.appendChild(this.makeTemplateCard(template));
+ template_cards.appendChild(this.makeTemplateCard(template, this.calculateAvailability(template, flavor_map)));
}
}
+ static calculateAvailability(templateBlob, flavor_map) {
+ const local_map = new Map()
+
+ // Map flavor uuid to amount in template
+ for (const host of templateBlob.host_list) {
+ const existing_count = local_map.get(host.flavor)
+ if (existing_count) {
+ local_map.set(host.flavor, existing_count + 1)
+ } else {
+ local_map.set(host.flavor, 1)
+ }
+ }
+
+ let lowest_count = Number.POSITIVE_INFINITY;
+ for (const [key, val] of local_map) {
+ const curr_count = Math.floor(flavor_map.get(key).available_count / val)
+ if (curr_count < lowest_count) {
+ lowest_count = curr_count;
+ }
+ }
+
+ return lowest_count;
+ }
+
/** Makes a card to be displayed in the add resource modal for a given templateBlob */
- static makeTemplateCard(templateBlob) {
+ static makeTemplateCard(templateBlob, available_count) {
+ let color = available_count > 0 ? 'text-success' : 'text-danger';
+ // let disabled = available_count == 0 ? 'disabled = "true"' : '';
const col = document.createElement('div');
col.classList.add('col-12', 'col-md-6', 'col-xl-3', 'my-3');
col.innerHTML= `
@@ -679,6 +703,7 @@ class GUI {
</div>
<div class="card-body">
<p class="grid-item-description">` + templateBlob.pod_desc +`</p>
+ <p class="grid-item-description ` + color + `">Resources available:` + available_count +`</p>
</div>
<div class="card-footer">
<button type="button" class="btn btn-success grid-item-select-btn w-100 stretched-link"