return a list of reservable resources with an account; fix blank names in account...
smbaker [Thu, 22 Nov 2012 03:10:56 +0000 (19:10 -0800)]
apps/gacks/API.py
apps/gacks/gackspolicy.py

index 00aed7b..523acd5 100644 (file)
@@ -788,6 +788,8 @@ class RemoteApi(AuthenticatedApi):
 
             result = acct.as_dict()
 
+            result['reservable'] = self.policies.get_reservable(acct.level)
+
             # fill in some policy fields as they are useful to the clients
             policy = self.policies.get_policy(acct.level, "plc.vicci.cores")
             if policy is None:
index 878fa6f..de611d5 100644 (file)
@@ -129,10 +129,26 @@ class GacksPolicyDirectory:
 
             resList = parser.GetOpt(section, "reservations", "").split(",")
             resList = [x.strip() for x in resList]
+            resList = [x for x in resList if x!=""]
             p.reservations = resList
 
             self.policies.append(p)
 
+    def get_reservable(self, name):
+        """ build up a description of what the named policy can reserve. For example:
+              calendar: [plc.vicci.cores, plc.disk]
+              asap: [plc.vicci.cores]
+        """
+        reservable = {}
+        for policy in self.policies:
+            if (policy.name == name):
+                for resKind in policy.reservations:
+                    if (not resKind in reservable):
+                        reservable[resKind] = []
+                    if not (policy.resource in reservable[resKind]):
+                        reservable[resKind].append(policy.resource)
+        return reservable
+
     def get_policy(self, name, resource):
         for policy in self.policies:
             if (policy.name == name) and ((resource==None) or (policy.resource == resource)):