#from sfa.util.config import Config
from sfa.util.xrn import hrn_to_urn, urn_to_hrn, urn_to_sliver_id
-from sfa.planetlab.plxrn import PlXrn, hostname_to_urn, slicename_to_hrn
from sfa.rspecs.rspec import RSpec
-from sfa.rspecs.elements.versions.slabv1Node import SlabLocation
-from sfa.storage.alchemy import dbsession
-from sfa.storage.model import RegRecord
-#from sfa.rspecs.elements.location import Location
+from sfa.rspecs.elements.versions.slabv1Node import SlabPosition
+from sfa.rspecs.elements.location import Location
from sfa.rspecs.elements.hardware_type import HardwareType
-from sfa.rspecs.elements.node import Node
#from sfa.rspecs.elements.login import Login
#from sfa.rspecs.elements.services import Services
from sfa.rspecs.elements.sliver import Sliver
from sfa.rspecs.elements.versions.slabv1Node import SlabNode
from sfa.util.sfalogging import logger
+from sfa.util.xrn import Xrn
-def hostname_to_hrn(root_auth, login_base, hostname):
- return PlXrn(auth=root_auth, hostname=login_base + '_' +hostname).get_hrn()
+def slab_xrn_to_hostname(xrn):
+ return Xrn.unescape(Xrn(xrn=xrn, type='node').get_leaf())
+
+def slab_xrn_object(root_auth, hostname):
+ """Attributes are urn and hrn.
+ Get the hostname using slab_xrn_to_hostname on the urn.
+
+ """
+ return Xrn('.'.join( [root_auth, Xrn.escape(hostname)]), type='node')
class SlabAggregate:
%(slices))
if not slices:
return (sfa_slice, slivers)
- if isinstance(sfa_slice, list):
- sfa_slice = slices[0]
- else:
- sfa_slice = slices
+ #if isinstance(sfa_slice, list):
+ #sfa_slice = slices[0]
+ #else:
+ #sfa_slice = slices
# sort slivers by node id , if there is a job
#and therfore, node allocated to this slice
- if sfa_slice['oar_job_id'] is not -1:
- try:
-
- for node_id in sfa_slice['node_ids']:
- #node_id = self.driver.root_auth + '.' + node_id
- sliver = Sliver({'sliver_id': urn_to_sliver_id(slice_urn, \
- sfa_slice['record_id_slice'], node_id),
- 'name': sfa_slice['slice_hrn'],
- 'type': 'slab-node',
- 'tags': []})
- slivers[node_id] = sliver
- except KeyError:
- logger.log_exc("SLABAGGREGATE \t \
- get_slice_and_slivers KeyError ")
+ for sfa_slice in slices:
+ if sfa_slice['oar_job_id'] is not -1:
+ try:
+
+ for node_id in sfa_slice['node_ids']:
+ #node_id = self.driver.root_auth + '.' + node_id
+ sliver = Sliver({'sliver_id': urn_to_sliver_id(slice_urn, \
+ sfa_slice['record_id_slice'], node_id),
+ 'name': sfa_slice['slice_hrn'],
+ 'type': 'slab-node',
+ 'tags': []})
+ slivers[node_id] = sliver
+ except KeyError:
+ logger.log_exc("SLABAGGREGATE \t \
+ get_slice_and_slivers KeyError ")
## sort sliver attributes by node id
##tags = self.driver.GetSliceTags({'slice_tag_id': slice['slice_tag_ids']})
##for tag in tags:
rspec_node['mobile'] = node['mobile']
rspec_node['archi'] = node['archi']
rspec_node['radio'] = node['radio']
- rspec_node['component_id'] = \
- hostname_to_urn(self.driver.root_auth, \
- node['site'], node['hostname'])
+
+ slab_xrn = slab_xrn_object(self.driver.root_auth, node['hostname'])
+ rspec_node['component_id'] = slab_xrn.urn
rspec_node['component_name'] = node['hostname']
rspec_node['component_manager_id'] = \
hrn_to_urn(self.driver.root_auth, 'authority+sa')
- #rspec_node['component_manager_id'] = Xrn(self.driver.root_auth, 'authority+sa').get_urn()
- rspec_node['authority_id'] = \
- hrn_to_urn(PlXrn.site_hrn(self.driver.root_auth, \
- node['site']), 'authority+sa')
+
+ # Senslab's nodes are federated : there is only one authority
+ # for all Senslab sites, registered in SFA.
+ # Removing the part including the site in authority_id SA 27/07/12
+ rspec_node['authority_id'] = rspec_node['component_manager_id']
+
# do not include boot state (<available> element) in the manifest rspec
#if not slice:
# add site/interface info to nodes.
# assumes that sites, interfaces and tags have already been prepared.
#site = sites_dict[node['site_id']]
-
- try:
- if node['posx'] and node['posy'] and node['posz']:
- location = SlabLocation()
- location['longitude'] = node['posx']
- location['latitude'] = node['posy']
- location['hauteur'] = node['posz']
+ location = Location({'country':'France'})
+ rspec_node['location'] = location
+
+
+ position = SlabPosition()
+ for field in position :
+ try:
+ position[field] = node[field]
+ except KeyError, error :
+ logger.log_exc("SLABAGGREGATE\t get_rspec position %s "%(error))
- rspec_node['location'] = location
- except KeyError:
- pass
+ rspec_node['position'] = position
#rspec_node['interfaces'] = []
#if_count=0
#for if_id in node['interface_ids']:
#service = Services({'login': login})
#rspec_node['services'] = [service]
rspec_nodes.append(rspec_node)
- #logger.debug("SLABAGGREGATE \t get_nodes rspec_nodes %s"%(rspec_nodes))
+
return (rspec_nodes)
def get_leases(self, slice_record = None, options = {}):
now = int(time.time())
lease_filter = {'clip': now }
+
+ self.driver.synchronize_oar_and_slice_table()
#if slice_record:
#lease_filter.update({'name': slice_record['name']})
return_fields = ['lease_id', 'hostname', 'site_id', \
rspec_lease = Lease()
rspec_lease['lease_id'] = lease['lease_id']
site = node['site_id']
- rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, \
- site, node['hostname'])
+ slab_xrn = slab_xrn_object(self.driver.root_auth, node['hostname'])
+ rspec_lease['component_id'] = slab_xrn.urn
+ #rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, \
+ #site, node['hostname'])
rspec_lease['slice_id'] = lease['slice_id']
rspec_lease['start_time'] = lease['t_from']
rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) \
#nodes, links = self.get_nodes(slice, slivers)
logger.debug("\r\n \r\n SlabAggregate \tget_rspec ******* slice_xrn %s \r\n \r\n"\
%(slice_xrn))
- if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'leases':
+
+ try:
+ lease_option = options['list_leases']
+ except KeyError:
+ return
+
+ if lease_option == 'resources':
+ #if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'leases':
nodes = self.get_nodes(slices, slivers)
#In case creating a job slice _xrn is not set to None
rspec.version.add_nodes(nodes)
tmp = ldap_username.split('.')
ldap_username = tmp[1].split('_')[0]
logger.debug("SlabAggregate \tget_rspec **** \
- ldap_username %s \r\n" %(ldap_username))
- rspec.version.add_connection_information(ldap_username)
+ ldap_username %s rspec.version %s\r\n" %(ldap_username, rspec.version))
+ if version.type == "Slab":
+ rspec.version.add_connection_information(ldap_username)
default_sliver = slivers.get(None, [])
if default_sliver:
rspec.version.add_default_sliver_attribute(attrib['tagname'], \
- attrib['value'])
- if options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources':
+ attrib['value'])
+ if lease_option in ['all','leases']:
+ #if options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources':
leases = self.get_leases(slices)
rspec.version.add_leases(leases)