added support for geni_extend_alap (as long as possible) in RenewSliver
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Wed, 22 Jan 2014 02:20:29 +0000 (21:20 -0500)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Wed, 22 Jan 2014 02:20:29 +0000 (21:20 -0500)
sfa/managers/aggregate_manager.py
sfa/util/sfatime.py

index 7c4bacb..5108c4f 100644 (file)
@@ -145,6 +145,15 @@ class AggregateManager:
     def Renew(self, api, xrns, creds, expiration_time, options):
         call_id = options.get('call_id')
         if Callids().already_handled(call_id): return True
+
+        # extend as long as possible
+        if options.get('geni_extend_alap'):
+            now = datetime.datetime.now()
+            requested = utcparse(expiration_time)
+            max = adjust_datetime(now, days=30)
+            if requested > max:
+                expiration_time = max
+
         return api.driver.renew(xrns, expiration_time, options)
 
     def PerformOperationalAction(self, api, xrns, creds, action, options={}):
index 4879689..992785e 100644 (file)
@@ -64,3 +64,10 @@ def datetime_to_utc(input):
 
 def datetime_to_epoch(input):
     return int(time.mktime(input.timetuple()))
+
+def adjust_datetime(input, days=0, hours=0, minutes=0, seconds=0):
+    """
+    Adjust the input date by the specified delta (in seconds).
+    """
+    dt = utcparse(input)
+    return dt + datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)