pl: wider mgt of new slice url and description
[sfa.git] / sfa / planetlab / plaggregate.py
index fdd70e5..cae6495 100644 (file)
@@ -18,10 +18,9 @@ from sfa.rspecs.elements.lease import Lease
 from sfa.rspecs.elements.granularity import Granularity
 from sfa.rspecs.version_manager import VersionManager
 
-from sfa.planetlab.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename, slicename_to_hrn, xrn_to_ext_slicename, top_auth
+from sfa.planetlab.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename, slicename_to_hrn, top_auth, hash_loginbase
 from sfa.planetlab.vlink import get_tc_rate
 from sfa.planetlab.topology import Topology
-from sfa.storage.alchemy import dbsession
 from sfa.storage.model import SliverAllocation
 
 
@@ -116,6 +115,7 @@ class PlAggregate:
         names = set()
         slice_ids = set()
         node_ids = []
+        slice_hrn = None
         for urn in urns:
             xrn = PlXrn(xrn=urn)
             if xrn.type == 'sliver':
@@ -130,20 +130,18 @@ class PlAggregate:
                     pass 
             else:  
                 slice_hrn = xrn.get_hrn()
-                top_auth_hrn = top_auth(slice_hrn)
-                if top_auth_hrn == self.driver.hrn:
-                    slice_name = hrn_to_pl_slicename(slice_hrn)
-                else:
-                    slice_name = xrn_to_ext_slicename(slice_hrn) 
-                names.add(slice_name)
 
         filter = {}
-        if names:
-            filter['name'] = list(names)
+        filter['peer_id'] = None
         if slice_ids:
             filter['slice_id'] = list(slice_ids)
-        # get slices
-        slices = self.driver.shell.GetSlices(filter)
+        # get all slices
+        all_slices = self.driver.shell.GetSlices(filter, ['slice_id', 'name', 'hrn', 'person_ids', 'node_ids', 'slice_tag_ids', 'expires'])
+        if slice_hrn:
+            slices = [slice for slice in all_slices if slice['hrn'] == slice_hrn]
+        else:
+            slices = all_slices
+      
         if not slices:
             return []
         slice = slices[0]     
@@ -431,7 +429,7 @@ class PlAggregate:
         geni_urn = urns[0]
         sliver_ids = [sliver['sliver_id'] for sliver in slivers]
         constraint = SliverAllocation.sliver_id.in_(sliver_ids)
-        sliver_allocations = dbsession.query(SliverAllocation).filter(constraint)
+        sliver_allocations = self.driver.api.dbsession().query(SliverAllocation).filter(constraint)
         sliver_allocation_dict = {}
         for sliver_allocation in sliver_allocations:
             geni_urn = sliver_allocation.slice_urn