RSpecVersion.todict() needs to turn values() into a list()
[sfa.git] / sfa / managers / v2_to_v3_adapter.py
index e29b4cd..8b0ce61 100644 (file)
@@ -7,8 +7,6 @@ from sfa.util.xrn import Xrn, urn_to_hrn, hrn_to_urn, get_leaf, get_authority
 from sfa.util.cache import Cache
 from sfa.rspecs.rspec import RSpec
 from sfa.storage.model import SliverAllocation
-# xxx 1-dbsession-per-request
-from sfa.storage.alchemy import dbsession
 
 class V2ToV3Adapter:
 
@@ -22,11 +20,8 @@ class V2ToV3Adapter:
         elif flavour == "fd":
             from sfa.federica.fddriver import FdDriver
             self.driver = FdDriver(api)
-        elif flavour == "iotlab":
-            from sfa.iotlab.iotlabdriver import IotlabDriver
-            self.driver = IotlabDriver(api)
         else:
-          logger.info("DriverV2Adapter unknown flavour !!!\n supported flavours: pl, nitos, fd, iotlab")
+          logger.error("V2ToV3Adapter: Unknown Flavour !!!\n Supported Flavours: nitos, fd")
          
         # Caching 
         if config.SFA_AGGREGATE_CACHING:
@@ -58,7 +53,7 @@ class V2ToV3Adapter:
                 else:
                     constraint = SliverAllocation.sliver_id.in_(urns)
  
-                sliver_allocations = dbsession.query (SliverAllocation).filter        (constraint)
+                sliver_allocations = self.driver.api.dbsession().query (SliverAllocation).filter        (constraint)
                 sliver_status = getattr(self.driver, "sliver_status")(slice_urn, slice_hrn)               
                 if 'geni_expires' in sliver_status.keys():
                     geni_expires = sliver_status['geni_expires']
@@ -110,7 +105,7 @@ class V2ToV3Adapter:
                                       slice_urn = slice_urn,
                                       allocation_state='geni_allocated')    
      
-                     record.sync()
+                     record.sync(self.driver.api.dbsession())
 
                
                 # return manifest
@@ -126,6 +121,7 @@ class V2ToV3Adapter:
                 else:
                    constraint = SliverAllocation.sliver_id.in_(urns)
                 
+                dbsession = self.driver.api.dbsession()
                 sliver_allocations = dbsession.query (SliverAllocation).filter(constraint)
                 for sliver_allocation in sliver_allocations:
                      sliver_allocation.allocation_state = 'geni_provisioned'
@@ -161,9 +157,10 @@ class V2ToV3Adapter:
              
                 #SliverAllocation
                 constraints = SliverAllocation.slice_urn.in_(urns)
+                dbsession = self.driver.api.dbsession()
                 sliver_allocations = dbsession.query(SliverAllocation).filter(constraints)
                 sliver_ids = [sliver_allocation.sliver_id for sliver_allocation in sliver_allocations]
-                SliverAllocation.delete_allocations(sliver_ids)
+                SliverAllocation.delete_allocations(sliver_ids, dbsession)
                 
 
             elif name == "renew":