From 3d755d649580518c105f7a92701f61dcf3a1c550 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 10 Jun 2010 08:13:23 +0000 Subject: [PATCH] use granularity from config --- PLC/Leases.py | 11 ++++------- PLC/Methods/GetLeaseGranularity.py | 3 +-- PLC/Methods/GetSlivers.py | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/PLC/Leases.py b/PLC/Leases.py index 2f7d493..cb8eed6 100644 --- a/PLC/Leases.py +++ b/PLC/Leases.py @@ -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) diff --git a/PLC/Methods/GetLeaseGranularity.py b/PLC/Methods/GetLeaseGranularity.py index 383ee8c..34a0034 100644 --- a/PLC/Methods/GetLeaseGranularity.py +++ b/PLC/Methods/GetLeaseGranularity.py @@ -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 diff --git a/PLC/Methods/GetSlivers.py b/PLC/Methods/GetSlivers.py index 9f86615..e7844f0 100644 --- a/PLC/Methods/GetSlivers.py +++ b/PLC/Methods/GetSlivers.py @@ -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, -- 2.43.0