added support for geni_extend_alap (as long as possible) in RenewSliver
[sfa.git] / sfa / managers / aggregate_manager.py
index 5d8fc8d..2ad3f9c 100644 (file)
@@ -1,6 +1,10 @@
+import socket
+import datetime
 from sfa.util.version import version_core
-from sfa.util.xrn import Xrn
+from sfa.util.xrn import Xrni
+from sfa.util.sfatime import utcpase, adjust_datetime
 from sfa.util.callids import Callids
+from sfa.server.api_versions import ApiVersions
 
 class AggregateManager:
 
@@ -9,14 +13,15 @@ class AggregateManager:
     # essentially a union of the core version, the generic version (this code) and
     # whatever the driver needs to expose
     def GetVersion(self, api, options):
-    
-        xrn=Xrn(api.hrn)
+        xrn=Xrn(api.hrn, type='authority+am')
         version = version_core()
+        geni_api_versions = ApiVersions().get_versions()
+        geni_api_versions['2'] = 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)
         version_generic = {
             'interface':'aggregate',
             'sfa': 2,
             'geni_api': 2,
-            'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)}
+            'geni_api_versions': geni_api_versions
             'hrn':xrn.get_hrn(),
             'urn':xrn.get_urn(),
             }
@@ -43,14 +48,13 @@ class AggregateManager:
             xrn = Xrn(slice_xrn)
             slice_urn=xrn.get_urn()
             slice_hrn=xrn.get_hrn()
-
         return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
     
     def SliverStatus (self, api, xrn, creds, options):
         call_id = options.get('call_id')
         if Callids().already_handled(call_id): return {}
     
-        xrn = Xrn(xrn)
+        xrn = Xrn(xrn,'slice')
         slice_urn=xrn.get_urn()
         slice_hrn=xrn.get_hrn()
         return self.driver.sliver_status (slice_urn, slice_hrn)
@@ -63,7 +67,7 @@ class AggregateManager:
         call_id = options.get('call_id')
         if Callids().already_handled(call_id): return ""
     
-        xrn = Xrn(xrn)
+        xrn = Xrn(xrn, 'slice')
         slice_urn=xrn.get_urn()
         slice_hrn=xrn.get_hrn()
 
@@ -73,7 +77,7 @@ class AggregateManager:
         call_id = options.get('call_id')
         if Callids().already_handled(call_id): return True
 
-        xrn = Xrn(xrn)
+        xrn = Xrn(xrn, 'slice')
         slice_urn=xrn.get_urn()
         slice_hrn=xrn.get_hrn()
         return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
@@ -82,9 +86,17 @@ class AggregateManager:
         call_id = options.get('call_id')
         if Callids().already_handled(call_id): return True
         
-        xrn = Xrn(xrn)
+        xrn = Xrn(xrn, 'slice')
         slice_urn=xrn.get_urn()
         slice_hrn=xrn.get_hrn()
+
+        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 self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
     
     ### these methods could use an options extension for at least call_id
@@ -112,5 +124,7 @@ class AggregateManager:
         slice_urn=xrn.get_urn()
         slice_hrn=xrn.get_hrn()
 
+        # xxx sounds like GetTicket is dead, but if that gets resurrected we might wish
+        # to pass 'users' over to the driver as well
         return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)