X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fplanetlab%2Fplaggregate.py;h=399b3a2a0a17c0e7495d2d1450f9a562f7172ee6;hb=b54e90d0c3868fa5afb89ff784cba0d5d36265ad;hp=c6006fbbc5f8c936ca1d88e9e1daae501aa821f9;hpb=1cc8e9613cab8b5b22478de369f259e591c54e6d;p=sfa.git diff --git a/sfa/planetlab/plaggregate.py b/sfa/planetlab/plaggregate.py index c6006fbb..399b3a2a 100644 --- a/sfa/planetlab/plaggregate.py +++ b/sfa/planetlab/plaggregate.py @@ -1,6 +1,6 @@ #!/usr/bin/python from collections import defaultdict -from sfa.util.xrn import Xrn, hrn_to_urn, urn_to_hrn +from sfa.util.xrn import Xrn, hrn_to_urn, urn_to_hrn, get_authority, get_leaf from sfa.util.sfatime import utcparse, datetime_to_string from sfa.util.sfalogging import logger from sfa.util.faults import SliverDoesNotExist @@ -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 +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 @@ -129,7 +128,17 @@ class PlAggregate: except ValueError: pass else: - names.add(xrn.pl_slicename()) + slice_hrn = xrn.get_hrn() + top_auth_hrn = top_auth(slice_hrn) + site_hrn = '.'.join(slice_hrn.split('.')[:-1]) + slice_part = slice_hrn.split('.')[-1] + if top_auth_hrn == self.driver.hrn: + login_base = slice_hrn.split('.')[-2][:12] + else: + login_base = hash_loginbase(site_hrn) + + slice_name = '_'.join([login_base, slice_part]) + names.add(slice_name) filter = {} if names: @@ -141,7 +150,7 @@ class PlAggregate: if not slices: return [] slice = slices[0] - slice['hrn'] = PlXrn(auth=self.driver.hrn, slicename=slice['name']).hrn + slice['hrn'] = slice_hrn # get sliver users persons = [] @@ -165,10 +174,10 @@ class PlAggregate: # construct user key info users = [] for person in persons: - name = person['email'][0:person['email'].index('@')] + person_urn = hrn_to_urn(self.driver.shell.GetPersonHrn(int(person['person_id'])), 'user') user = { 'login': slice['name'], - 'user_urn': Xrn('%s.%s' % (self.driver.hrn, name), type='user').urn, + 'user_urn': person_urn, 'keys': [keys[k_id]['key'] for k_id in person['key_ids'] if k_id in keys] } users.append(user) @@ -193,7 +202,7 @@ class PlAggregate: rspec_node = NodeElement() # xxx how to retrieve site['login_base'] site=sites[node['site_id']] - rspec_node['component_id'] = PlXrn(self.driver.hrn, hostname=node['hostname']).get_urn() + rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], node['hostname']) rspec_node['component_name'] = node['hostname'] rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn() rspec_node['authority_id'] = hrn_to_urn(PlXrn.site_hrn(self.driver.hrn, site['login_base']), 'authority+sa') @@ -203,7 +212,13 @@ class PlAggregate: rspec_node['available'] = 'true' else: rspec_node['available'] = 'false' - rspec_node['exclusive'] = 'false' + + #distinguish between Shared and Reservable nodes + if node['node_type'] == 'reservable': + rspec_node['exclusive'] = 'true' + else: + rspec_node['exclusive'] = 'false' + rspec_node['hardware_types'] = [HardwareType({'name': 'plab-pc'}), HardwareType({'name': 'pc'})] # only doing this because protogeni rspec needs @@ -248,9 +263,10 @@ class PlAggregate: 'type': 'plab-vserver', '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 + if sliver['urn'] in sliver_allocations: + 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 @@ -310,6 +326,9 @@ class PlAggregate: op_status = 'geni_unknown' else: allocation_status = 'geni_unallocated' + else: + allocation_status = 'geni_unallocated' + op_status = 'geni_failed' # required fields geni_sliver = {'geni_sliver_urn': rspec_node['sliver_id'], 'geni_expires': rspec_node['expires'], @@ -319,11 +338,8 @@ class PlAggregate: } return geni_sliver - def get_leases(self, slice_xrn=None, slice=None, options={}): + def get_leases(self, slice=None, options={}): - if slice_xrn and not slice: - return [] - now = int(time.time()) filter={} filter.update({'clip':now}) @@ -349,13 +365,9 @@ class PlAggregate: site_id=lease['site_id'] site=sites_dict[site_id] - rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], lease['hostname']) - if slice_xrn: - slice_urn = slice_xrn - slice_hrn = urn_to_hrn(slice_urn) - else: - slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name']) - slice_urn = hrn_to_urn(slice_hrn, 'slice') + rspec_lease['component_id'] = hrn_to_urn(self.driver.shell.GetNodeHrn(lease['hostname']), 'node') + slice_hrn = self.driver.shell.GetSliceHrn(lease['slice_id']) + slice_urn = hrn_to_urn(slice_hrn, 'slice') rspec_lease['slice_id'] = slice_urn rspec_lease['start_time'] = lease['t_from'] rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) / grain @@ -398,7 +410,7 @@ class PlAggregate: rspec.version.add_links(links) if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources': - leases = self.get_leases(slice_xrn, slice) + leases = self.get_leases() rspec.version.add_leases(leases) return rspec.toxml()