pagkage /etc/sfa/api_versions.xml
[sfa.git] / sfa / planetlab / plslices.py
index 0ee4fda..ec60f36 100644 (file)
@@ -180,18 +180,19 @@ class PlSlices:
         return leases
 
 
-    def verify_slice_nodes(self, slice, rspec_nodes, peer):
+    def verify_slice_nodes(self, slice_urn, slice, rspec_nodes, peer):
         
         slivers = {}
         for node in rspec_nodes:
-            hostname = None
-            client_id = node.get('client_id')    
-            if node.get('component_name'):
-                hostname = node.get('component_name').strip()
-            elif node.get('component_id'):
-                hostname = xrn_to_hostname(node.get('component_id').strip())
+            hostname = node.get('component_name')
+            client_id = node.get('client_id')
+            component_id = node.get('component_id').strip()    
             if hostname:
-                slivers[hostname] = client_id
+                hostname = hostname.strip()
+            elif component_id:
+                hostname = xrn_to_hostname(component_id)
+            if hostname:
+                slivers[hostname] = {'client_id': client_id, 'component_id': component_id}
         
         nodes = self.driver.shell.GetNodes(slice['node_ids'], ['node_id', 'hostname', 'interface_ids'])
         current_slivers = [node['hostname'] for node in nodes]
@@ -216,11 +217,14 @@ class PlSlices:
 
         # update sliver allocations
         for node in resulting_nodes:
-            client_id = slivers[node['hostname']]
-            logger.info(client_id)
+            client_id = slivers[node['hostname']]['client_id']
+            component_id = slivers[node['hostname']]['component_id']
             sliver_hrn = '%s.%s-%s' % (self.driver.hrn, slice['slice_id'], node['node_id'])
             sliver_id = Xrn(sliver_hrn, type='sliver').urn
-            record = SliverAllocation(sliver_id=sliver_id, client_id=client_id, allocation_state='geni_allocated')      
+            record = SliverAllocation(sliver_id=sliver_id, client_id=client_id, 
+                                      component_id=component_id,
+                                      slice_urn = slice_urn, 
+                                      allocation_state='geni_allocated')      
             record.sync()
         return resulting_nodes
 
@@ -368,11 +372,12 @@ class PlSlices:
         
         return site        
 
-    def verify_slice(self, slice_hrn, slice_record, peer, sfa_peer, options={}):
+    def verify_slice(self, slice_hrn, slice_record, peer, sfa_peer, expiration, options={}):
         slicename = hrn_to_pl_slicename(slice_hrn)
         parts = slicename.split("_")
         login_base = parts[0]
         slices = self.driver.shell.GetSlices([slicename]) 
+        expires = int(datetime_to_epoch(utcparse(expiration)))
         if not slices:
             slice = {'name': slicename,
                      'url': 'No Url', 
@@ -382,18 +387,19 @@ class PlSlices:
             slice['node_ids'] = []
             slice['person_ids'] = []
             if peer and slice_record:
-                slice['peer_slice_id'] = slice_record.get('slice_id', None) 
+                slice['peer_slice_id'] = slice_record.get('slice_id', None)
+            # set the expiration
+            self.driver.shell.UpdateSlice(slice['slice_id'], {'expires': expires}) 
         else:
             slice = slices[0]
             if peer and slice_record:
                 slice['peer_slice_id'] = slice_record.get('slice_id', None)
                 # unbind from peer so we can modify if necessary. Will bind back later
                 self.driver.shell.UnBindObjectFromPeer('slice', slice['slice_id'], peer['shortname'])
-               #Update existing record (e.g. expires field) it with the latest info.
-            if slice_record and slice_record.get('expires'):
-                requested_expires = int(datetime_to_epoch(utcparse(slice_record['expires'])))
-                if requested_expires and slice['expires'] != requested_expires:
-                    self.driver.shell.UpdateSlice( slice['slice_id'], {'expires' : requested_expires})
+            
+               #Update expiration if necessary
+            if slice['expires'] != expires:
+                self.driver.shell.UpdateSlice( slice['slice_id'], {'expires' : expires})
        
         return slice