From ab323f56e4e20f8b210572274b09136c15050904 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Thu, 13 Dec 2012 11:53:45 -0500 Subject: [PATCH] store component_id in sliver_allocation table --- sfa/planetlab/plaggregate.py | 4 +++- sfa/planetlab/plslices.py | 22 +++++++++++++--------- sfa/storage/model.py | 10 ++++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/sfa/planetlab/plaggregate.py b/sfa/planetlab/plaggregate.py index 98232fd9..645722e0 100644 --- a/sfa/planetlab/plaggregate.py +++ b/sfa/planetlab/plaggregate.py @@ -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 diff --git a/sfa/planetlab/plslices.py b/sfa/planetlab/plslices.py index 2b4459de..16d9bc33 100644 --- a/sfa/planetlab/plslices.py +++ b/sfa/planetlab/plslices.py @@ -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 diff --git a/sfa/storage/model.py b/sfa/storage/model.py index 43be3e7a..15352975 100644 --- a/sfa/storage/model.py +++ b/sfa/storage/model.py @@ -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() -- 2.43.0