use granularity from config
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 10 Jun 2010 08:13:23 +0000 (08:13 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 10 Jun 2010 08:13:23 +0000 (08:13 +0000)
PLC/Leases.py
PLC/Methods/GetLeaseGranularity.py
PLC/Methods/GetSlivers.py

index 2f7d493..cb8eed6 100644 (file)
@@ -46,18 +46,15 @@ class Lease(Row):
 
     related_fields = { }
 
-    # leases do not have arbitrary boundaries
-    # f_from and t_until are rounded to this period of time
-    # initial model is 15 minutes
-#    granularity = 15*60    granularity = 5*60
-
     def validate_time (self, timestamp, round_up):
         # convert to long
         timestamp = Timestamp.cast_long(timestamp)
+        # retrieve configured granularity
+        granularity = self.api.config.PLC_RESERVATION_GRANULARITY
         # the trick for rounding up rather than down
-        if round_up: timestamp += (Lease.granularity-1)
+        if round_up: timestamp += (granularity-1)
         # round down
-        timestamp = (timestamp/Lease.granularity) * Lease.granularity
+        timestamp = (timestamp/granularity) * granularity
         # return a SQL string
         return Timestamp.sql_validate_utc(timestamp)
 
index 383ee8c..34a0034 100644 (file)
@@ -4,7 +4,6 @@ from PLC.Method import Method
 from PLC.Auth import Auth
 from PLC.Faults import *
 from PLC.Parameter import Parameter
-from PLC.Leases import Lease
 
 class GetLeaseGranularity(Method):
     """
@@ -22,4 +21,4 @@ class GetLeaseGranularity(Method):
 
     def call(self, auth):
 
-        return Lease.granularity
+        return self.api.config.PLC_RESERVATION_GRANULARITY
index 9f86615..e7844f0 100644 (file)
@@ -324,7 +324,7 @@ class GetSlivers(Method):
                                                    'clip': (timestamp, timestamp+24*Duration.HOUR),
                                                    '-SORT': 't_from',
                                                    }) ]
-        granularity=Lease.granularity
+        granularity=self.api.config.PLC_RESERVATION_GRANULARITY
 
         return {
             'timestamp': timestamp,