summaryrefslogtreecommitdiffstats
path: root/dashboard/src
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-01-03 15:46:32 -0500
committerParker Berberian <pberberian@iol.unh.edu>2019-02-25 11:34:10 -0500
commit3ef36a843a36a4c340b22514fc57decafd9d8a42 (patch)
tree2fcd147e85150ee59538207076d841504d6d06ed /dashboard/src
parent879ebf85275e5f8942eb1a1e30d76cbee2a70715 (diff)
Check for Host Availability
Currently, if not enough hosts are free to fulfill a booking, booking creation will fail with an error message to the users. This commit adds a way to check if a given POD will be available and communicates to the user if not. Change-Id: Ib75d9ee4759cf991a5c985cb4a6f7baaaafbe8fa Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'dashboard/src')
-rw-r--r--dashboard/src/resource_inventory/resource_manager.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/dashboard/src/resource_inventory/resource_manager.py b/dashboard/src/resource_inventory/resource_manager.py
index 812fcd7..f43ae4d 100644
--- a/dashboard/src/resource_inventory/resource_manager.py
+++ b/dashboard/src/resource_inventory/resource_manager.py
@@ -38,6 +38,31 @@ class ResourceManager:
hostprofileset = HostProfile.objects.filter(host__in=hostset, labs=lab)
return set(hostprofileset)
+ def hostsAvailable(self, grb):
+ """
+ This method will check if the given GenericResourceBundle
+ is available. No changes to the database
+ """
+
+ # count up hosts
+ profile_count = {}
+ for host in grb.getHosts():
+ if host.profile not in profile_count:
+ profile_count[host.profile] = 0
+ profile_count[host.profile] += 1
+
+ # check that all required hosts are available
+ for profile in profile_count.keys():
+ available = Host.objects.filter(
+ booked=False,
+ lab=grb.lab,
+ profile=profile
+ ).count()
+ needed = profile_count[profile]
+ if available < needed:
+ return False
+ return True
+
# public interface
def deleteResourceBundle(self, resourceBundle):
for host in Host.objects.filter(bundle=resourceBundle):