from sfa.rspecs.rspec import RSpec
from sfa.util.xrn import hrn_to_urn, urn_to_sliver_id, get_leaf
-from sfa.planetlab.plxrn import slicename_to_hrn, hrn_to_pl_slicename, \
- hostname_to_urn, \
- xrn_to_hostname
+
## thierry: everything that is API-related (i.e. handling incoming requests)
# is taken care of
from sfa.senslab.LDAPapi import LDAPapi
from sfa.senslab.slabpostgres import SlabDB, slab_dbsession, SliceSenslab
-from sfa.senslab.slabaggregate import SlabAggregate
+from sfa.senslab.slabaggregate import SlabAggregate, slab_xrn_to_hostname, slab_xrn_object
from sfa.senslab.slabslices import SlabSlices
-def __process_walltime(duration=None):
- """ Calculates the walltime in seconds from the duration in H:M:S
- specified in the RSpec.
-
- """
- if duration:
- walltime = duration.split(":")
- # Fixing the walltime by adding a few delays. First put the walltime
- # in seconds oarAdditionalDelay = 20; additional delay for
- # /bin/sleep command to
- # take in account prologue and epilogue scripts execution
- # int walltimeAdditionalDelay = 120; additional delay
-
- desired_walltime = int(walltime[0])*3600 + int(walltime[1]) * 60 +\
- int(walltime[2])
- total_walltime = desired_walltime + 140 #+2 min 20
- sleep_walltime = desired_walltime + 20 #+20 sec
- logger.debug("SLABDRIVER \t__process_walltime desired_walltime %s\
- total_walltime %s sleep_walltime %s "\
- %(desired_walltime, total_walltime, \
- sleep_walltime))
- #Put the walltime back in str form
- #First get the hours
- walltime[0] = str(total_walltime / 3600)
- total_walltime = total_walltime - 3600 * int(walltime[0])
- #Get the remaining minutes
- walltime[1] = str(total_walltime / 60)
- total_walltime = total_walltime - 60 * int(walltime[1])
- #Get the seconds
- walltime[2] = str(total_walltime)
- logger.debug("SLABDRIVER \t__process_walltime walltime %s "\
- %(walltime))
- else:
- #automatically set 10min +2 min 20
- walltime[0] = '0'
- walltime[1] = '12'
- walltime[2] = '20'
- sleep_walltime = '620'
-
- return walltime, sleep_walltime
requested_lease = {}
if not lease.get('lease_id'):
requested_lease['hostname'] = \
- xrn_to_hostname(lease.get('component_id').strip())
- requested_lease['t_from'] = lease.get('t_from')
- requested_lease['t_until'] = lease.get('t_until')
+ slab_xrn_to_hostname(lease.get('component_id').strip())
+ requested_lease['start_time'] = lease.get('start_time')
+ requested_lease['duration'] = lease.get('duration')
else:
kept_leases.append(int(lease['lease_id']))
if requested_lease.get('hostname'):
#return rspec
#panos: passing user-defined options
- logger.debug("SLABDRIVER \tlist_resources rspec " )
aggregate = SlabAggregate(self)
origin_hrn = Credential(string=creds[0]).get_gid_caller().get_hrn()
options.update({'origin_hrn':origin_hrn})
#return slices
# get data from db
- logger.debug("SLABDRIVER.PY \tlist_slices")
- slices = self.GetSlices()
- slice_hrns = [slicename_to_hrn(self.hrn, slab_slice['slice_hrn']) \
- for slab_slice in slices]
+
+ slices = self.GetSlices()
+ logger.debug("SLABDRIVER.PY \tlist_slices hrn %s \r\n \r\n" %(slices))
+ slice_hrns = [slab_slice['slice_hrn'] for slab_slice in slices]
+ #slice_hrns = [slicename_to_hrn(self.hrn, slab_slice['slice_hrn']) \
+ #for slab_slice in slices]
slice_urns = [hrn_to_urn(slice_hrn, 'slice') \
for slice_hrn in slice_hrns]
-
+
# cache the result
#if self.cache:
#logger.debug ("SlabDriver.list_slices stores value in cache")
existing_hrns_by_types = {}
logger.debug("SLABDRIVER \tGetPeers auth = %s, peer_filter %s, \
return_field %s " %(auth , peer_filter, return_fields_list))
- all_records = dbsession.query(RegRecord).\
- filter(RegRecord.type.like('%authority%')).all()
+ all_records = dbsession.query(RegRecord).filter(RegRecord.type.like('%authority%')).all()
for record in all_records:
existing_records[(record.hrn, record.type)] = record
if record.type not in existing_hrns_by_types:
answer = self.oar.POSTRequestToOARRestAPI('DELETE_jobs_id', \
reqdict,username)
- logger.debug("SLABDRIVER \tDeleteJobs jobid %s \r\n answer %s " \
- %(job_id,answer))
+ logger.debug("SLABDRIVER \tDeleteJobs jobid %s \r\n answer %s username %s" \
+ %(job_id,answer, username))
return answer
hostname_list = []
hostname_dict_list = []
for resource_id in resource_id_list:
- hostname_dict_list.append({'hostname' : \
- oar_id_node_dict[resource_id]['hostname'],
- 'site_id' : oar_id_node_dict[resource_id]['site']})
-
+ #Because jobs requested "asap" do not have defined resources
+ if resource_id is not "Undefined":
+ hostname_dict_list.append({'hostname' : \
+ oar_id_node_dict[resource_id]['hostname'],
+ 'site_id' : oar_id_node_dict[resource_id]['site']})
+
#hostname_list.append(oar_id_node_dict[resource_id]['hostname'])
return hostname_dict_list
%(authorized_filter_types_list))
if slice_filter_type in authorized_filter_types_list:
if slice_filter_type == 'slice_hrn':
- slicerec = slab_dbsession.query(SliceSenslab).\
- filter_by(slice_hrn = slice_filter).first()
+ slicerec = slab_dbsession.query(SliceSenslab).filter_by(slice_hrn = slice_filter).first()
if slice_filter_type == 'record_id_user':
- slicerec = slab_dbsession.query(SliceSenslab).\
- filter_by(record_id_user = slice_filter).first()
+ slicerec = slab_dbsession.query(SliceSenslab).filter_by(record_id_user = slice_filter).first()
if slicerec:
#warning pylint OK
else:
- return_slice_list = slab_dbsession.query(SliceSenslab).all()
-
+ slice_list = slab_dbsession.query(SliceSenslab).all()
+ return_slice_list = []
+ for record in slice_list:
+ return_slice_list.append(record.dump_sqlalchemyobj_to_dict())
+
logger.debug("SLABDRIVER.PY \tGetSlices slices %s \
slice_filter %s " %(return_slice_list, slice_filter))
#instantion used in get_slivers ?
if not "instantiation" in slab_record:
slab_record["instantiation"] = "senslab-instantiated"
- slab_record["hrn"] = hrn_to_pl_slicename(hrn)
+ #slab_record["hrn"] = hrn_to_pl_slicename(hrn)
+ #Unused hrn_to_pl_slicename because Slab's hrn already in the appropriate form SA 23/07/12
+ slab_record["hrn"] = hrn
logger.debug("SLABDRIVER.PY sfa_fields_to_slab_fields \
- slab_record %s hrn_to_pl_slicename(hrn) hrn %s " \
- %(slab_record['hrn'], hrn))
+ slab_record %s " %(slab_record['hrn']))
if "url" in record:
slab_record["url"] = record["url"]
if "description" in record:
custom_length = len(reqdict['resource'])- 2
reqdict['resource'] = reqdict['resource'][0:custom_length] + \
")}/nodes=" + str(len(nodeid_list))
-
+
+ def __process_walltime(duration=None):
+ """ Calculates the walltime in seconds from the duration in H:M:S
+ specified in the RSpec.
+
+ """
+ if duration:
+ walltime = duration.split(":")
+ # Fixing the walltime by adding a few delays. First put the walltime
+ # in seconds oarAdditionalDelay = 20; additional delay for
+ # /bin/sleep command to
+ # take in account prologue and epilogue scripts execution
+ # int walltimeAdditionalDelay = 120; additional delay
+
+ desired_walltime = int(walltime[0])*3600 + int(walltime[1]) * 60 +\
+ int(walltime[2])
+ total_walltime = desired_walltime + 140 #+2 min 20
+ sleep_walltime = desired_walltime + 20 #+20 sec
+ logger.debug("SLABDRIVER \t__process_walltime desired_walltime %s\
+ total_walltime %s sleep_walltime %s "\
+ %(desired_walltime, total_walltime, \
+ sleep_walltime))
+ #Put the walltime back in str form
+ #First get the hours
+ walltime[0] = str(total_walltime / 3600)
+ total_walltime = total_walltime - 3600 * int(walltime[0])
+ #Get the remaining minutes
+ walltime[1] = str(total_walltime / 60)
+ total_walltime = total_walltime - 60 * int(walltime[1])
+ #Get the seconds
+ walltime[2] = str(total_walltime)
+ logger.debug("SLABDRIVER \t__process_walltime walltime %s "\
+ %(walltime))
+ else:
+ #automatically set 10min +2 min 20
+ walltime[0] = '0'
+ walltime[1] = '12'
+ walltime[2] = '20'
+ sleep_walltime = '620'
+
+ return walltime, sleep_walltime
+
#if slot['duration']:
walltime, sleep_walltime = __process_walltime(duration = \
slot['duration'])
return
-
+ def GetLeaseGranularity(self):
+ """ Returns the granularity of Senslab testbed.
+ Defined in seconds. """
+
+ grain = 60
+ return grain
def GetLeases(self, lease_filter_dict=None, return_fields_list=None):
unfiltered_reservation_list = self.GetReservedNodes()
user = dbsession.query(RegUser).filter_by(email = \
ldap_info['mail'][0]).first()
-
- slice_info = slab_dbsession.query(SliceSenslab).\
- filter_by(record_id_user = user.record_id).first()
+ #Separated in case user not in database : record_id not defined SA 17/07//12
+ query_slice_info = slab_dbsession.query(SliceSenslab).filter_by(record_id_user = user.record_id)
+ if query_slice_info:
+ slice_info = query_slice_info.first()
+
#Put the slice_urn
resa['slice_id'] = hrn_to_urn(slice_info.slice_hrn, 'slice')
resa['component_id_list'] = []
#Transform the hostnames into urns (component ids)
for node in resa['reserved_nodes']:
- resa['component_id_list'].append(hostname_to_urn(self.hrn, \
- self.root_auth, node['hostname']))
-
+ #resa['component_id_list'].append(hostname_to_urn(self.hrn, \
+ #self.root_auth, node['hostname']))
+ slab_xrn = slab_xrn_object(self.root_auth, node['hostname'])
+ resa['component_id_list'].append(slab_xrn.urn)
#Filter the reservation list if necessary
#Returns all the leases associated with a given slice
#therefore fetches user and slice info again(one more loop)
#Will update PIs and researcher for the slice
recuser = dbsession.query(RegRecord).filter_by(record_id = \
- recslice['record_id_user']).\
- first()
+ recslice['record_id_user']).first()
recslice.update({'PI':[recuser.hrn],
'researcher': [recuser.hrn],
'name':record['hrn'],