store component_id in sliver_allocation table
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Thu, 13 Dec 2012 16:53:45 +0000 (11:53 -0500)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Thu, 13 Dec 2012 16:53:45 +0000 (11:53 -0500)
sfa/planetlab/plaggregate.py
sfa/planetlab/plslices.py
sfa/storage/model.py

index 98232fd..645722e 100644 (file)
@@ -211,6 +211,8 @@ class PlAggregate:
                          'tags': []})
         rspec_node['sliver_id'] = rspec_sliver['sliver_id']
         rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
+        if sliver_allocations[sliver['urn']].component_id:
+            rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
         rspec_node['slivers'] = [rspec_sliver]
 
         # slivers always provide the ssh service
@@ -301,7 +303,7 @@ class PlAggregate:
             site=sites_dict[site_id]
 
             rspec_lease['lease_id'] = lease['lease_id']
-            rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], lease['hostname'])
+            rspec_lease['component_id'] = PlXrn(self.driver.hrn, hostname=lease['hostname']).urn
             slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name'])
             slice_urn = hrn_to_urn(slice_hrn, 'slice')
             rspec_lease['slice_id'] = slice_urn
index 2b4459d..16d9bc3 100644 (file)
@@ -184,14 +184,15 @@ class PlSlices:
         
         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,10 +217,13 @@ class PlSlices:
 
         # update sliver allocations
         for node in resulting_nodes:
-            client_id = slivers[node['hostname']]
+            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, 
+                                      allocation_state='geni_allocated')      
             record.sync()
         return resulting_nodes
 
index 43be3e7..1535297 100644 (file)
@@ -316,13 +316,16 @@ class SliverAllocation(Base,AlchemyObj):
     __tablename__       = 'sliver_allocation'
     sliver_id           = Column(String, primary_key=True)
     client_id           = Column(String)
+    component_id        = Column(String)
     allocation_state    = Column(String)
 
     def __init__(self, **kwds):
         if 'sliver_id' in kwds:
             self.sliver_id = kwds['sliver_id']
-        if 'sliver_id' in kwds:
+        if 'client_id' in kwds:
             self.client_id = kwds['client_id']
+        if 'component_id' in kwds:
+            self.component_id = kwds['component_id']
         if 'allocation_state' in kwds:
             self.allocation_state = kwds['allocation_state']
 
@@ -373,9 +376,7 @@ class SliverAllocation(Base,AlchemyObj):
     def sync(self):
         from sfa.storage.alchemy import dbsession
         
-        constraints = [SliverAllocation.sliver_id==self.sliver_id,
-                       SliverAllocation.client_id==self.client_id,
-                       SliverAllocation.allocation_state==self.allocation_state]
+        constraints = [SliverAllocation.sliver_id==self.sliver_id]
         results = dbsession.query(SliverAllocation).filter(and_(*constraints))
         records = []
         for result in results:
@@ -387,6 +388,7 @@ class SliverAllocation(Base,AlchemyObj):
             record = records[0]
             record.sliver_id = self.sliver_id
             record.client_id  = self.client_id
+            record.component_id  = self.component_id
             record.allocation_state = self.allocation_state
         dbsession.commit()