-class slab (Generic):
-
+class iotlab (Generic):
+
# use the standard api class
def api_class (self):
return sfa.server.sfaapi.SfaApi
-
+
# the importer class
- def importer_class (self):
- import sfa.importer.slabimporter
- return sfa.importer.slabimporter.SlabImporter
-
+ def importer_class (self):
+ import sfa.importer.iotlabimporter
+ return sfa.importer.iotlabimporter.IotlabImporter
+
# the manager classes for the server-side services
def registry_manager_class (self) :
- import sfa.managers.registry_manager
+ import sfa.managers.registry_manager
return sfa.managers.registry_manager.RegistryManager
-
+
def slicemgr_manager_class (self) :
- import sfa.managers.slice_manager
+ import sfa.managers.slice_manager
return sfa.managers.slice_manager.SliceManager
-
+
def aggregate_manager_class (self) :
import sfa.managers.aggregate_manager
return sfa.managers.aggregate_manager.AggregateManager
# driver class for server-side services, talk to the whole testbed
def driver_class (self):
+<<<<<<< HEAD:sfa/generic/slab.py
import sfa.managers.v2_to_v3_adapter
return sfa.managers.v2_to_v3_adapter.V2ToV3Adapter
+=======
+ import sfa.iotlab.iotlabdriver
+ return sfa.iotlab.iotlabdriver.IotlabDriver
+>>>>>>> 7cb1e78... Renaming Senslab into Iotlab.:sfa/generic/iotlab.py
- # slab does not have a component manager yet
+ # iotlab does not have a component manager yet
# manager class
def component_manager_class (self):
return None
# driver_class
def component_driver_class (self):
return None
-
-
from sfa.util.config import Config
from sfa.util.xrn import Xrn, get_authority, hrn_to_urn
-from sfa.senslab.slabdriver import SlabDriver
+from sfa.iotlab.iotlabdriver import IotlabDriver
from sfa.trust.certificate import Keypair, convert_public_key
from sfa.trust.gid import create_uuid
-class SlabImporter:
+class IotlabImporter:
"""
- SlabImporter class, generic importer_class. Used to populate the SFA DB
- with senslab resources' records.
+ IotlabImporter class, generic importer_class. Used to populate the SFA DB
+ with iotlab resources' records.
Used to update records when new resources, users or nodes, are added
or deleted.
"""
"""
rec_tuple = (record.type, record.hrn)
if rec_tuple in self.records_by_type_hrn:
- self.logger.warning ("SlabImporter.update_just_added_records_dict:\
+ self.logger.warning ("IotlabImporter.update_just_added_records_dict:\
duplicate (%s,%s)"%rec_tuple)
return
self.records_by_type_hrn [ rec_tuple ] = record
- def import_sites_and_nodes(self, slabdriver):
+ def import_sites_and_nodes(self, iotlabdriver):
"""
Gets all the sites and nodes from OAR, process the information,
For each site, import the site's nodes to the DB by calling
import_nodes.
- :param slabdriver: SlabDriver object, used to have access to slabdriver
+ :param iotlabdriver: IotlabDriver object, used to have access to iotlabdriver
methods and fetching info on sites and nodes.
- :type slabdriver: SlabDriver
+ :type iotlabdriver: IotlabDriver
"""
- sites_listdict = slabdriver.slab_api.GetSites()
- nodes_listdict = slabdriver.slab_api.GetNodes()
+ sites_listdict = iotlabdriver.iotlab_api.GetSites()
+ nodes_listdict = iotlabdriver.iotlab_api.GetNodes()
nodes_by_id = dict([(node['node_id'], node) for node in nodes_listdict])
for site in sites_listdict:
site_hrn = site['name']
site_record.just_created()
dbsession.add(site_record)
dbsession.commit()
- self.logger.info("SlabImporter: imported authority (site) \
+ self.logger.info("IotlabImporter: imported authority (site) \
%s" % site_record)
self.update_just_added_records_dict(site_record)
except SQLAlchemyError:
# if the site import fails then there is no point in
# trying to import the
# site's child records(node, slices, persons), so skip them.
- self.logger.log_exc("SlabImporter: failed to import site. \
+ self.logger.log_exc("IotlabImporter: failed to import site. \
Skipping child records")
continue
else:
site_record.stale = False
- self.import_nodes(site['node_ids'], nodes_by_id, slabdriver)
+ self.import_nodes(site['node_ids'], nodes_by_id, iotlabdriver)
return
- def import_nodes(self, site_node_ids, nodes_by_id, slabdriver):
+ def import_nodes(self, site_node_ids, nodes_by_id, iotlabdriver):
"""
Creates appropriate hostnames and RegNode records for
:param nodes_by_id: dictionary , key is the node id, value is the a dict
with node information.
:type nodes_by_id: dictionary
- :param slabdriver:SlabDriver object, used to have access to slabdriver
+ :param iotlabdriver:IotlabDriver object, used to have access to iotlabdriver
attributes.
- :type slabdriver:SlabDriver
+ :type iotlabdriver:IotlabDriver
"""
try:
node = nodes_by_id[node_id]
except KeyError:
- self.logger.warning ("SlabImporter: cannot find node_id %s \
+ self.logger.warning ("IotlabImporter: cannot find node_id %s \
- ignored" %(node_id))
continue
escaped_hrn = \
- self.hostname_to_hrn_escaped(slabdriver.slab_api.root_auth, \
+ self.hostname_to_hrn_escaped(iotlabdriver.iotlab_api.root_auth, \
node['hostname'])
- self.logger.info("SLABIMPORTER node %s " %(node))
+ self.logger.info("IOTLABIMPORTER node %s " %(node))
hrn = node['hrn']
self.auth_hierarchy.create_gid(urn, \
create_uuid(), pkey)
- def slab_get_authority(hrn):
+ def iotlab_get_authority(hrn):
return hrn.split(".")[0]
node_record = RegNode(hrn=hrn, gid=node_gid,
pointer = '-1',
- authority=slab_get_authority(hrn))
+ authority=iotlab_get_authority(hrn))
try:
node_record.just_created()
dbsession.add(node_record)
dbsession.commit()
- self.logger.info("SlabImporter: imported node: %s" \
+ self.logger.info("IotlabImporter: imported node: %s" \
% node_record)
self.update_just_added_records_dict(node_record)
except SQLAlchemyError:
- self.logger.log_exc("SlabImporter: \
+ self.logger.log_exc("IotlabImporter: \
failed to import node")
else:
#TODO: xxx update the record ...
node_record.stale = False
- def init_person_key (self, person, slab_key):
+ def init_person_key (self, person, iotlab_key):
"""
Returns a tuple pubkey and pkey.
:param person Person's data.
:type person: dict
- :param slab_key: SSH public key, from LDAP user's data.
+ :param iotlab_key: SSH public key, from LDAP user's data.
RSA type supported.
- :type slab_key: string
+ :type iotlab_key: string
:rtype (string, Keypair)
"""
pubkey = None
if person['pkey']:
# randomly pick first key in set
- pubkey = slab_key
+ pubkey = iotlab_key
try:
pkey = convert_public_key(pubkey)
except TypeError:
#key not good. create another pkey
- self.logger.warn('SlabImporter: \
+ self.logger.warn('IotlabImporter: \
unable to convert public \
key for %s' %person['hrn'])
pkey = Keypair(create=True)
else:
# the user has no keys.
#Creating a random keypair for the user's gid
- self.logger.warn("SlabImporter: person %s does not have a \
+ self.logger.warn("IotlabImporter: person %s does not have a \
public key" %(person['hrn']))
pkey = Keypair(create=True)
return (pubkey, pkey)
- def import_persons_and_slices(self, slabdriver):
+ def import_persons_and_slices(self, iotlabdriver):
"""
Gets user data from LDAP, process the information.
import the user's slice onto the database as well by calling
import_slice.
- :param slabdriver:SlabDriver object, used to have access to slabdriver
+ :param iotlabdriver:IotlabDriver object, used to have access to iotlabdriver
attributes.
- :type slabdriver:SlabDriver
+ :type iotlabdriver:IotlabDriver
"""
- ldap_person_listdict = slabdriver.slab_api.GetPersons()
- self.logger.info("SLABIMPORT \t ldap_person_listdict %s \r\n" \
+ ldap_person_listdict = iotlabdriver.iotlab_api.GetPersons()
+ self.logger.info("IOTLABIMPORT \t ldap_person_listdict %s \r\n" \
%(ldap_person_listdict))
# import persons
for person in ldap_person_listdict :
- self.logger.info("SlabImporter: person :" %(person))
+ self.logger.info("IotlabImporter: person :" %(person))
if 'ssh-rsa' not in person['pkey']:
#people with invalid ssh key (ssh-dss, empty, bullshit keys...)
#won't be imported
person_urn = hrn_to_urn(person_hrn, 'user')
- self.logger.info("SlabImporter: users_rec_by_email %s " \
+ self.logger.info("IotlabImporter: users_rec_by_email %s " \
%(self.users_rec_by_email))
#Check if user using person['email'] from LDAP is already registered
#in SFA. One email = one person. In this case, do not create another
#record for this person
- #person_hrn returned by GetPerson based on senslab root auth +
+ #person_hrn returned by GetPerson based on iotlab root auth +
#uid ldap
user_record = self.find_record_by_type_hrn('user', person_hrn)
slice_record = self.find_record_by_type_hrn ('slice', slice_hrn)
- slab_key = person['pkey']
+ iotlab_key = person['pkey']
# new person
if not user_record:
- (pubkey, pkey) = self.init_person_key(person, slab_key)
+ (pubkey, pkey) = self.init_person_key(person, iotlab_key)
if pubkey is not None and pkey is not None :
person_gid = \
self.auth_hierarchy.create_gid(person_urn, \
user_record.just_created()
dbsession.add (user_record)
dbsession.commit()
- self.logger.info("SlabImporter: imported person %s"\
+ self.logger.info("IotlabImporter: imported person %s"\
%(user_record))
self.update_just_added_records_dict( user_record )
except SQLAlchemyError:
- self.logger.log_exc("SlabImporter: \
+ self.logger.log_exc("IotlabImporter: \
failed to import person %s"%(person))
else:
# update the record ?
sfa_keys = user_record.reg_keys
new_key = False
- if slab_key is not sfa_keys :
+ if iotlab_key is not sfa_keys :
new_key = True
if new_key:
- self.logger.info("SlabImporter: \t \t USER UPDATE \
+ self.logger.info("IotlabImporter: \t \t USER UPDATE \
person: %s" %(person['hrn']))
- (pubkey, pkey) = self.init_person_key (person, slab_key)
+ (pubkey, pkey) = self.init_person_key (person, iotlab_key)
person_gid = \
self.auth_hierarchy.create_gid(person_urn, \
create_uuid(), pkey)
user_record.reg_keys = []
else:
user_record.reg_keys = [RegKey(pubkey)]
- self.logger.info("SlabImporter: updated person: %s" \
+ self.logger.info("IotlabImporter: updated person: %s" \
% (user_record))
if person['email']:
dbsession.commit()
user_record.stale = False
except SQLAlchemyError:
- self.logger.log_exc("SlabImporter: \
+ self.logger.log_exc("IotlabImporter: \
failed to update person %s"%(person))
self.import_slice(slice_hrn, slice_record, user_record)
self.update_just_added_records_dict ( slice_record )
except SQLAlchemyError:
- self.logger.log_exc("SlabImporter: failed to import slice")
+ self.logger.log_exc("IotlabImporter: failed to import slice")
- #No slice update upon import in senslab
+ #No slice update upon import in iotlab
else:
# xxx update the record ...
self.logger.warning ("Slice update not yet implemented")
dbsession.commit()
slice_record.stale = False
except SQLAlchemyError:
- self.logger.log_exc("SlabImporter: failed to update slice")
+ self.logger.log_exc("IotlabImporter: failed to update slice")
def run (self, options):
"""
- Create the special senslab table, slab_xp, in the senslab database.
+ Create the special iotlab table, iotlab_xp, in the iotlab database.
Import everything (users, slices, nodes and sites from OAR
and LDAP) into the SFA database.
Delete stale records that are no longer in OAR or LDAP.
"""
config = Config()
- slabdriver = SlabDriver(config)
+ iotlabdriver = IotlabDriver(config)
- #Create special slice table for senslab
+ #Create special slice table for iotlab
- if not slabdriver.db.exists('slab_xp'):
- slabdriver.db.createtable()
- self.logger.info ("SlabImporter.run: slab_xp table created ")
+ if not iotlabdriver.db.exists('iotlab_xp'):
+ iotlabdriver.db.createtable()
+ self.logger.info ("IotlabImporter.run: iotlab_xp table created ")
# import site and node records in site into the SFA db.
- self.import_sites_and_nodes(slabdriver)
+ self.import_sites_and_nodes(iotlabdriver)
#import users and slice into the SFA DB.
- self.import_persons_and_slices(slabdriver)
+ self.import_persons_and_slices(iotlabdriver)
### remove stale records
# special records must be preserved
- system_hrns = [slabdriver.hrn, slabdriver.slab_api.root_auth, \
- slabdriver.hrn+ '.slicemanager']
+ system_hrns = [iotlabdriver.hrn, iotlabdriver.iotlab_api.root_auth, \
+ iotlabdriver.hrn+ '.slicemanager']
for record in self.all_records:
if record.hrn in system_hrns:
record.stale = False
for record in self.all_records:
if record.type == 'user':
- self.logger.info("SlabImporter: stale records: hrn %s %s" \
+ self.logger.info("IotlabImporter: stale records: hrn %s %s" \
%(record.hrn,record.stale) )
try:
stale = record.stale
stale = True
self.logger.warning("stale not found with %s"%record)
if stale:
- self.logger.info("SlabImporter: deleting stale record: %s" \
+ self.logger.info("IotlabImporter: deleting stale record: %s" \
%(record))
try:
dbsession.delete(record)
dbsession.commit()
except SQLAlchemyError:
- self.logger.log_exc("SlabImporter: failed to delete stale \
+ self.logger.log_exc("IotlabImporter: failed to delete stale \
record %s" %(record) )
""" Set admin login and server configuration variables."""
def __init__(self):
- #Senslab PROD LDAP parameters
+ #Iotlab PROD LDAP parameters
self.ldapserv = None
ldap_config = LdapConfig()
self.config = ldap_config
:return: Returns encrypted password.
:rtype:string
"""
- #Keep consistency with Java Senslab's LDAP API
+ #Keep consistency with Java Iotlab's LDAP API
#RFC2307SSHAPasswordEncryptor so set the salt size to 8 bytes
return lssha.encrypt(password, salt_size = 8)
#Hrn should not be part of the filter because the hrn
#presented by a certificate of a SFA user not imported in
- #Senslab does not include the senslab login in it
- #Plus, the SFA user may already have an account with senslab
+ #Iotlab does not include the iotlab login in it
+ #Plus, the SFA user may already have an account with iotlab
#using another login.
return req_ldap
def make_ldap_attributes_from_record(self, record):
- """When adding a new user to Senslab's LDAP, creates an attributes
+ """When adding a new user to Iotlab's LDAP, creates an attributes
dictionnary from the SFA record understandable by LDAP.
Generates the user's LDAP login.
User is automatically validated (account enabled) and described
#Password is automatically generated because SFA user don't go
- #through the Senslab website used to register new users,
+ #through the Iotlab website used to register new users,
#There is no place in SFA where users can enter such information
#yet.
- #If the user wants to set his own password , he must go to the Senslab
+ #If the user wants to set his own password , he must go to the Iotlab
#website.
password = self.login_pwd.generate_password()
attrs['userPassword'] = self.login_pwd.encrypt_password(password)
#Set to 0 to disable the account, -1 to enable it,
attrs['shadowExpire'] = '-1'
- #Motivation field in Senslab
+ #Motivation field in Iotlab
attrs['description'] = 'SFA USER FROM OUTSIDE SENSLAB'
attrs['ou'] = 'SFA' #Optional: organizational unit
parent_hrn = get_authority(hrn)
if parent_hrn != self.authname:
peer_authority = parent_hrn
- #In case the user was not imported from Senslab LDAP
+ #In case the user was not imported from Iotlab LDAP
#but from another federated site, has an account in
- #senslab but currently using his hrn from federated site
+ #iotlab but currently using his hrn from federated site
#then the login is different from the one found in its hrn
if tmpname != hrn.split('.')[1]:
hrn = None
expected_fields=None):
"""
Search a SFA user with a hrn. User should be already registered
- in Senslab LDAP.
+ in Iotlab LDAP.
:param record: sfa user's record. Should contain first_name,last_name,
email or mail. If no record is provided, returns all the users found
in LDAP.
:type record: dict
- :param is_user_enabled: is the user's senslab account already valid.
+ :param is_user_enabled: is the user's iotlab account already valid.
:type is_user_enabled: Boolean.
:return: LDAP entries from ldap matching the filter provided. Returns
a single entry if one filter has been given and a list of
from httplib import HTTPConnection, HTTPException, NotConnected
import json
#import datetime
-#from time import gmtime, strftime
+#from time import gmtime, strftime
import os.path
import sys
#import urllib
#OARpostdatareqfields = {'resource' :"/nodes=", 'command':"sleep", \
#'workdir':"/home/", 'walltime':""}
-
+
class JsonPage:
"""Class used to manipulate jsopn pages given by OAR."""
#Indicates end of data, no more pages to be loaded.
self.end = False
self.next_page = False
- #Next query address
+ #Next query address
self.next_offset = None
#Json page
self.raw_json = None
self.next_page = True
self.next_offset = "?" + page['href'].split("?")[1]
print>>sys.stderr, "\r\n \t FindNextPage NEXT LINK"
- return
-
+ return
+
if self.concatenate :
self.end = True
self.next_page = False
- self.next_offset = None
+ self.next_offset = None
+
+ return
- return
-
#Otherwise, no next page and no concatenate, must be a single page
#Concatenate the single page and get out of here.
else:
self.concatenate = True
self.next_offset = None
return
-
- @staticmethod
+
+ @staticmethod
def ConcatenateJsonPages(saved_json_list):
#reset items list
-
+
tmp = {}
tmp['items'] = []
-
+
for page in saved_json_list:
- tmp['items'].extend(page['items'])
+ tmp['items'].extend(page['items'])
return tmp
-
-
+
+
def ResetNextPage(self):
self.next_page = True
self.next_offset = None
self.concatenate = False
self.end = False
-
-
+
+
class OARrestapi:
def __init__(self, config_file = '/etc/sfa/oar_config.py'):
self.oarserver = {}
-
-
+
+
self.oarserver['uri'] = None
self.oarserver['postformat'] = 'json'
-
+
try:
execfile(config_file, self.__dict__)
-
+
self.config_file = config_file
# path to configuration data
self.config_path = os.path.dirname(config_file)
-
+
except IOError:
raise IOError, "Could not find or load the configuration file: %s" \
% config_file
'toError', 'toAckReservation', 'Launching', \
'Finishing', 'Running', 'Suspended', 'Resuming',\
'Error']
-
+
self.parser = OARGETParser(self)
-
-
- def GETRequestToOARRestAPI(self, request, strval=None, next_page=None, username = None ):
+
+
+ def GETRequestToOARRestAPI(self, request, strval=None, next_page=None, username = None ):
self.oarserver['uri'] = \
OARGETParser.OARrequests_uri_dict[request]['uri']
- #Get job details with username
+ #Get job details with username
if 'owner' in OARGETParser.OARrequests_uri_dict[request] and username:
self.oarserver['uri'] += OARGETParser.OARrequests_uri_dict[request]['owner'] + username
headers = {}
if strval:
self.oarserver['uri'] = self.oarserver['uri'].\
replace("id",str(strval))
-
+
if next_page:
self.oarserver['uri'] += next_page
-
+
if username:
- headers['X-REMOTE_IDENT'] = username
-
+ headers['X-REMOTE_IDENT'] = username
+
logger.debug("OARrestapi: \t GETRequestToOARRestAPI \
self.oarserver['uri'] %s strval %s" \
%(self.oarserver['uri'], strval))
- try :
+ try :
#seems that it does not work if we don't add this
- headers['content-length'] = '0'
+ headers['content-length'] = '0'
conn = HTTPConnection(self.oarserver['ip'], \
self.oarserver['port'])
conn.request("GET", self.oarserver['uri'], data, headers)
resp = ( conn.getresponse()).read()
conn.close()
-
+
except HTTPException, error :
logger.log_exc("GET_OAR_SRVR : Problem with OAR server : %s " \
%(error))
js_dict = json.loads(resp)
#print "\r\n \t\t\t js_dict keys" , js_dict.keys(), " \r\n", js_dict
return js_dict
-
+
except ValueError, error:
logger.log_exc("Failed to parse Server Response: %s ERROR %s"\
%(js_dict, error))
#raise ServerError("Failed to parse Server Response:" + js)
-
+
def POSTRequestToOARRestAPI(self, request, datadict, username=None):
- """ Used to post a job on OAR , along with data associated
+ """ Used to post a job on OAR , along with data associated
with the job.
-
+
"""
- #first check that all params for are OK
+ #first check that all params for are OK
try:
self.oarserver['uri'] = OAR_REQUEST_POST_URI_DICT[request]['uri']
data = json.dumps(datadict)
headers = {'X-REMOTE_IDENT':username, \
'content-type': POST_FORMAT['json']['content'], \
- 'content-length':str(len(data))}
+ 'content-length':str(len(data))}
try :
conn = HTTPConnection(self.oarserver['ip'], \
%(data,headers,self.oarserver['uri']))
#raise ServerError("POST_OAR_SRVR : error")
-
+
try:
answer = json.loads(resp)
logger.debug("POSTRequestToOARRestAPI : answer %s" %(answer))
def AddOarNodeId(tuplelist, value):
""" Adds Oar internal node id to the nodes attributes """
-
+
tuplelist.append(('oar_id', int(value)))
-
+
def AddNodeNetworkAddr(dictnode, value):
#Inserts new key. The value associated is a tuple list
node_id = value
-
- dictnode[node_id] = [('node_id', node_id),('hostname', node_id) ]
-
- return node_id
-
+
+ dictnode[node_id] = [('node_id', node_id),('hostname', node_id) ]
+
+ return node_id
+
def AddNodeSite(tuplelist, value):
tuplelist.append(('site', str(value)))
def AddNodeRadio(tuplelist, value):
- tuplelist.append(('radio', str(value)))
+ tuplelist.append(('radio', str(value)))
-def AddMobility(tuplelist, value):
+def AddMobility(tuplelist, value):
if value is 0:
- tuplelist.append(('mobile', 'False'))
+ tuplelist.append(('mobile', 'False'))
else :
tuplelist.append(('mobile', 'True'))
def AddPosX(tuplelist, value):
- tuplelist.append(('posx', value))
+ tuplelist.append(('posx', value))
def AddPosY(tuplelist, value):
- tuplelist.append(('posy', value))
-
+ tuplelist.append(('posy', value))
+
def AddPosZ(tuplelist, value):
tuplelist.append(('posz', value))
-
+
def AddBootState(tuplelist, value):
tuplelist.append(('boot_state', str(value)))
-
+
#Insert a new node into the dictnode dictionary
def AddNodeId(dictnode, value):
#Inserts new key. The value associated is a tuple list
node_id = int(value)
-
- dictnode[node_id] = [('node_id', node_id)]
- return node_id
+
+ dictnode[node_id] = [('node_id', node_id)]
+ return node_id
def AddHardwareType(tuplelist, value):
value_list = value.split(':')
- tuplelist.append(('archi', value_list[0]))
+ tuplelist.append(('archi', value_list[0]))
tuplelist.append(('radio', value_list[1]))
-
-
+
+
class OARGETParser:
resources_fulljson_dict = {
'network_address' : AddNodeNetworkAddr,
- 'site': AddNodeSite,
+ 'site': AddNodeSite,
'radio': AddNodeRadio,
'mobile': AddMobility,
'x': AddPosX,
'y': AddPosY,
'z':AddPosZ,
- 'archi':AddHardwareType,
+ 'archi':AddHardwareType,
'state':AddBootState,
'id' : AddOarNodeId,
}
-
-
+
+
def __init__(self, srv) :
- self.version_json_dict = {
+ self.version_json_dict = {
'api_version' : None , 'apilib_version' :None,\
'api_timezone': None, 'api_timestamp': None, 'oar_version': None ,}
self.config = Config()
- self.interface_hrn = self.config.SFA_INTERFACE_HRN
- self.timezone_json_dict = {
+ self.interface_hrn = self.config.SFA_INTERFACE_HRN
+ self.timezone_json_dict = {
'timezone': None, 'api_timestamp': None, }
#self.jobs_json_dict = {
#'total' : None, 'links' : [],\
#'offset':None , 'items' : [], }
#self.jobs_table_json_dict = self.jobs_json_dict
- #self.jobs_details_json_dict = self.jobs_json_dict
+ #self.jobs_details_json_dict = self.jobs_json_dict
self.server = srv
self.node_dictlist = {}
-
+
self.json_page = JsonPage()
-
+
self.site_dict = {}
self.SendRequest("GET_version")
-
-
-
- def ParseVersion(self) :
+
+
+
+ def ParseVersion(self) :
#print self.json_page.raw_json
#print >>sys.stderr, self.json_page.raw_json
if 'oar_version' in self.json_page.raw_json :
self.version_json_dict.update(api_version = \
- self.json_page.raw_json['api_version'],
- apilib_version = self.json_page.raw_json['apilib_version'],
- api_timezone = self.json_page.raw_json['api_timezone'],
- api_timestamp = self.json_page.raw_json['api_timestamp'],
+ self.json_page.raw_json['api_version'],
+ apilib_version = self.json_page.raw_json['apilib_version'],
+ api_timezone = self.json_page.raw_json['api_timezone'],
+ api_timestamp = self.json_page.raw_json['api_timestamp'],
oar_version = self.json_page.raw_json['oar_version'] )
else :
self.version_json_dict.update(api_version = \
api_timezone = self.json_page.raw_json['api_timezone'],
api_timestamp = self.json_page.raw_json['api_timestamp'],
oar_version = self.json_page.raw_json['oar'] )
-
+
print self.version_json_dict['apilib_version']
-
-
- def ParseTimezone(self) :
+
+
+ def ParseTimezone(self) :
api_timestamp = self.json_page.raw_json['api_timestamp']
api_tz = self.json_page.raw_json['timezone']
return api_timestamp, api_tz
-
+
def ParseJobs(self) :
self.jobs_list = []
print " ParseJobs "
return self.json_page.raw_json
-
- def ParseJobsTable(self) :
+
+ def ParseJobsTable(self) :
print "ParseJobsTable"
-
+
def ParseJobsDetails (self):
- # currently, this function is not used a lot,
- #so i have no idea what be usefull to parse,
+ # currently, this function is not used a lot,
+ #so i have no idea what be usefull to parse,
#returning the full json. NT
#logger.debug("ParseJobsDetails %s " %(self.json_page.raw_json))
return self.json_page.raw_json
-
+
def ParseJobsIds(self):
-
+
job_resources = ['wanted_resources', 'name', 'id', 'start_time', \
'state','owner','walltime','message']
-
-
+
+
job_resources_full = ['launching_directory', 'links', \
'resubmit_job_id', 'owner', 'events', 'message', \
'scheduled_start', 'id', 'array_id', 'exit_code', \
for k in job_resources:
values.append(job_info[k])
return dict(zip(job_resources, values))
-
+
except KeyError:
logger.log_exc("ParseJobsIds KeyError ")
-
+
def ParseJobsIdResources(self):
- """ Parses the json produced by the request
+ """ Parses the json produced by the request
/oarapi/jobs/id/resources.json.
- Returns a list of oar node ids that are scheduled for the
+ Returns a list of oar node ids that are scheduled for the
given job id.
-
+
"""
job_resources = []
for resource in self.json_page.raw_json['items']:
job_resources.append(resource['id'])
-
+
#logger.debug("OARESTAPI \tParseJobsIdResources %s" %(self.json_page.raw_json))
return job_resources
-
+
def ParseResources(self) :
""" Parses the json produced by a get_resources request on oar."""
-
+
#logger.debug("OARESTAPI \tParseResources " )
#resources are listed inside the 'items' list from the json
self.json_page.raw_json = self.json_page.raw_json['items']
def ParseReservedNodes(self):
""" Returns an array containing the list of the reserved nodes """
-
+
#resources are listed inside the 'items' list from the json
- reservation_list = []
+ reservation_list = []
job = {}
#Parse resources info
for json_element in self.json_page.raw_json['items']:
job['t_from'] = "As soon as possible"
job['t_until'] = "As soon as possible"
job['resource_ids'] = ["Undefined"]
-
-
- job['state'] = json_element['state']
- job['lease_id'] = json_element['id']
-
-
+
+
+ job['state'] = json_element['state']
+ job['lease_id'] = json_element['id']
+
+
job['user'] = json_element['owner']
- #logger.debug("OARRestapi \tParseReservedNodes job %s" %(job))
+ #logger.debug("OARRestapi \tParseReservedNodes job %s" %(job))
reservation_list.append(job)
#reset dict
job = {}
return reservation_list
-
- def ParseRunningJobs(self):
+
+ def ParseRunningJobs(self):
""" Gets the list of nodes currently in use from the attributes of the
running jobs.
-
+
"""
- logger.debug("OARESTAPI \tParseRunningJobs__________________________ ")
+ logger.debug("OARESTAPI \tParseRunningJobs__________________________ ")
#resources are listed inside the 'items' list from the json
nodes = []
for job in self.json_page.raw_json['items']:
for node in job['nodes']:
nodes.append(node['network_address'])
return nodes
-
-
-
+
+
+
def ParseDeleteJobs(self):
- """ No need to parse anything in this function.A POST
+ """ No need to parse anything in this function.A POST
is done to delete the job.
-
+
"""
- return
-
+ return
+
def ParseResourcesFull(self) :
- """ This method is responsible for parsing all the attributes
+ """ This method is responsible for parsing all the attributes
of all the nodes returned by OAR when issuing a get resources full.
The information from the nodes and the sites are separated.
- Updates the node_dictlist so that the dictionnary of the platform's
- nodes is available afterwards.
-
+ Updates the node_dictlist so that the dictionnary of the platform's
+ nodes is available afterwards.
+
"""
logger.debug("OARRESTAPI ParseResourcesFull________________________ ")
#print self.json_page.raw_json[1]
self.ParseNodes()
self.ParseSites()
return self.node_dictlist
-
+
def ParseResourcesFullSites(self) :
""" UNUSED. Originally used to get information from the sites.
ParseResourcesFull is used instead.
-
+
"""
if self.version_json_dict['apilib_version'] != "0.2.10" :
self.json_page.raw_json = self.json_page.raw_json['items']
self.ParseNodes()
self.ParseSites()
return self.site_dict
-
-
- def ParseNodes(self):
+
+
+ def ParseNodes(self):
""" Parse nodes properties from OAR
- Put them into a dictionary with key = node id and value is a dictionary
+ Put them into a dictionary with key = node id and value is a dictionary
of the node properties and properties'values.
-
+
"""
node_id = None
keys = self.resources_fulljson_dict.keys()
keys.sort()
for dictline in self.json_page.raw_json:
- node_id = None
- # dictionary is empty and/or a new node has to be inserted
+ node_id = None
+ # dictionary is empty and/or a new node has to be inserted
node_id = self.resources_fulljson_dict['network_address'](\
- self.node_dictlist, dictline['network_address'])
+ self.node_dictlist, dictline['network_address'])
for k in keys:
if k in dictline:
if k == 'network_address':
continue
-
+
self.resources_fulljson_dict[k](\
self.node_dictlist[node_id], dictline[k])
- #The last property has been inserted in the property tuple list,
- #reset node_id
+ #The last property has been inserted in the property tuple list,
+ #reset node_id
#Turn the property tuple list (=dict value) into a dictionary
self.node_dictlist[node_id] = dict(self.node_dictlist[node_id])
node_id = None
-
- @staticmethod
- def slab_hostname_to_hrn( root_auth, hostname):
- return root_auth + '.'+ hostname
-
+ @staticmethod
+ def iotlab_hostname_to_hrn( root_auth, hostname):
+ return root_auth + '.'+ hostname
+
+
def ParseSites(self):
""" Returns a list of dictionnaries containing the sites' attributes."""
-
+
nodes_per_site = {}
config = Config()
#logger.debug(" OARrestapi.py \tParseSites self.node_dictlist %s"\
# Create a list of nodes per site_id
for node_id in self.node_dictlist:
node = self.node_dictlist[node_id]
-
+
if node['site'] not in nodes_per_site:
nodes_per_site[node['site']] = []
nodes_per_site[node['site']].append(node['node_id'])
else:
if node['node_id'] not in nodes_per_site[node['site']]:
nodes_per_site[node['site']].append(node['node_id'])
-
+
#Create a site dictionary whose key is site_login_base (name of the site)
- # and value is a dictionary of properties, including the list
+ # and value is a dictionary of properties, including the list
#of the node_ids
for node_id in self.node_dictlist:
node = self.node_dictlist[node_id]
- #node.update({'hrn':self.slab_hostname_to_hrn(self.interface_hrn, \
+ #node.update({'hrn':self.iotlab_hostname_to_hrn(self.interface_hrn, \
#node['site'],node['hostname'])})
- node.update({'hrn':self.slab_hostname_to_hrn(self.interface_hrn, node['hostname'])})
+ node.update({'hrn':self.iotlab_hostname_to_hrn(self.interface_hrn, node['hostname'])})
self.node_dictlist.update({node_id:node})
if node['site'] not in self.site_dict:
'longitude':"- 2.10336",'name':config.SFA_REGISTRY_ROOT_AUTH,
'pcu_ids':[], 'max_slices':None, 'ext_consortium_id':None,
'max_slivers':None, 'is_public':True, 'peer_site_id': None,
- 'abbreviated_name':"senslab", 'address_ids': [],
+ 'abbreviated_name':"iotlab", 'address_ids': [],
'url':"http,//www.senslab.info", 'person_ids':[],
'site_tag_ids':[], 'enabled': True, 'slice_ids':[],
- 'date_created': None, 'peer_id': None }
+ 'date_created': None, 'peer_id': None }
#if node['site_login_base'] not in self.site_dict.keys():
#self.site_dict[node['site_login_base']] = {'login_base':node['site_login_base'],
#'node_ids':nodes_per_site[node['site_login_base']],
#'abbreviated_name':"senslab", 'address_ids': [],
#'url':"http,//www.senslab.info", 'person_ids':[],
#'site_tag_ids':[], 'enabled': True, 'slice_ids':[],
- #'date_created': None, 'peer_id': None }
+ #'date_created': None, 'peer_id': None }
+
-
- OARrequests_uri_dict = {
- 'GET_version':
+ OARrequests_uri_dict = {
+ 'GET_version':
{'uri':'/oarapi/version.json', 'parse_func': ParseVersion},
'GET_timezone':
{'uri':'/oarapi/timezone.json' ,'parse_func': ParseTimezone },
- 'GET_jobs':
+ 'GET_jobs':
{'uri':'/oarapi/jobs.json','parse_func': ParseJobs},
- 'GET_jobs_id':
+ 'GET_jobs_id':
{'uri':'/oarapi/jobs/id.json','parse_func': ParseJobsIds},
- 'GET_jobs_id_resources':
+ 'GET_jobs_id_resources':
{'uri':'/oarapi/jobs/id/resources.json',\
'parse_func': ParseJobsIdResources},
- 'GET_jobs_table':
+ 'GET_jobs_table':
{'uri':'/oarapi/jobs/table.json','parse_func': ParseJobsTable},
- 'GET_jobs_details':
+ 'GET_jobs_details':
{'uri':'/oarapi/jobs/details.json',\
'parse_func': ParseJobsDetails},
'GET_reserved_nodes':
'owner':'&user=',
'parse_func':ParseReservedNodes},
-
- 'GET_running_jobs':
+
+ 'GET_running_jobs':
{'uri':'/oarapi/jobs/details.json?state=Running',\
'parse_func':ParseRunningJobs},
- 'GET_resources_full':
+ 'GET_resources_full':
{'uri':'/oarapi/resources/full.json',\
'parse_func': ParseResourcesFull},
'GET_sites':
}
-
-
+
+
def SendRequest(self, request, strval = None , username = None):
""" Connects to OAR , sends the valid GET requests and uses
the appropriate json parsing functions.
-
+
"""
save_json = None
self.json_page.FindNextPage()
if self.json_page.concatenate:
save_json.append(self.json_page.raw_json)
-
+
if self.json_page.concatenate and self.json_page.end :
self.json_page.raw_json = \
self.json_page.ConcatenateJsonPages(save_json)
else:
logger.error("OARRESTAPI OARGetParse __init__ : ERROR_REQUEST " \
%(request))
-
+
from sfa.rspecs.version_manager import VersionManager
-from sfa.rspecs.elements.versions.slabv1Node import SlabPosition, SlabNode, \
- SlabLocation
+from sfa.rspecs.elements.versions.iotlabv1Node import IotlabPosition, IotlabNode, \
+ IotlabLocation
from sfa.util.sfalogging import logger
from sfa.util.xrn import Xrn
-def slab_xrn_to_hostname(xrn):
+def iotlab_xrn_to_hostname(xrn):
return Xrn.unescape(Xrn(xrn=xrn, type='node').get_leaf())
-def slab_xrn_object(root_auth, hostname):
+def iotlab_xrn_object(root_auth, hostname):
"""Attributes are urn and hrn.
- Get the hostname using slab_xrn_to_hostname on the urn.
+ Get the hostname using iotlab_xrn_to_hostname on the urn.
- :return: the senslab node's xrn
+ :return: the iotlab node's xrn
:rtype: Xrn
"""
return Xrn('.'.join( [root_auth, Xrn.escape(hostname)]), type='node')
-class SlabAggregate:
+class IotlabAggregate:
sites = {}
nodes = {}
def get_slice_and_slivers(self, slice_xrn, login=None):
"""
- Get the slices and the associated leases if any from the senslab
+ Get the slices and the associated leases if any from the iotlab
testbed. For each slice, get the nodes in the associated lease
and create a sliver with the necessary info and insertinto the sliver
dictionary, keyed on the node hostnames.
:param slice_xrn: xrn of the slice
- :param login: user's login on senslab ldap
+ :param login: user's login on iotlab ldap
:type slice_xrn: string
:type login: string
:reutnr : a list of slices dict and a dictionary of Sliver object
:rtype: (list, dict)
- ..note: There is no slivers in senslab, only leases.
+ ..note: There is no slivers in iotlab, only leases.
"""
slivers = {}
slice_hrn, _ = urn_to_hrn(slice_xrn)
slice_name = slice_hrn
- slices = self.driver.slab_api.GetSlices(slice_filter= str(slice_name), \
+ slices = self.driver.iotlab_api.GetSlices(slice_filter= str(slice_name), \
slice_filter_type = 'slice_hrn', \
login=login)
sliver_xrn.set_authority(self.driver.hrn)
sliver = Sliver({'sliver_id':sliver_xrn.urn,
'name': sfa_slice['hrn'],
- 'type': 'slab-node',
+ 'type': 'iotlab-node',
'tags': []})
slivers[node] = sliver
#Add default sliver attribute :
- #connection information for senslab
- if get_authority (sfa_slice['hrn']) == self.driver.slab_api.root_auth:
+ #connection information for iotlab
+ if get_authority (sfa_slice['hrn']) == self.driver.iotlab_api.root_auth:
tmp = sfa_slice['hrn'].split('.')
ldap_username = tmp[1].split('_')[0]
ssh_access = None
#tags_filter = {}
# get the granularity in second for the reservation system
- grain = self.driver.slab_api.GetLeaseGranularity()
+ grain = self.driver.iotlab_api.GetLeaseGranularity()
- nodes = self.driver.slab_api.GetNodes()
+ nodes = self.driver.iotlab_api.GetNodes()
#geni_available = options.get('geni_available')
#if geni_available:
#filter['boot_state'] = 'boot'
#filter.update({'peer_id': None})
- #nodes = self.driver.slab_api.GetNodes(filter['hostname'])
+ #nodes = self.driver.iotlab_api.GetNodes(filter['hostname'])
#site_ids = []
#interface_ids = []
#for node in one_slice['node_ids']:
#slice_nodes_list.append(node)
- reserved_nodes = self.driver.slab_api.GetNodesCurrentlyInUse()
+ reserved_nodes = self.driver.iotlab_api.GetNodesCurrentlyInUse()
logger.debug("SLABAGGREGATE api get_nodes slice_nodes_list %s "\
%(slice_nodes_list))
for node in nodes:
nodes_dict[node['node_id']] = node
if slice_nodes_list == [] or node['hostname'] in slice_nodes_list:
- rspec_node = SlabNode()
+ rspec_node = IotlabNode()
# xxx how to retrieve site['login_base']
#site_id=node['site_id']
#site=sites_dict[site_id]
rspec_node['archi'] = node['archi']
rspec_node['radio'] = node['radio']
- slab_xrn = slab_xrn_object(self.driver.slab_api.root_auth, \
+ iotlab_xrn = iotlab_xrn_object(self.driver.iotlab_api.root_auth, \
node['hostname'])
- rspec_node['component_id'] = slab_xrn.urn
+ rspec_node['component_id'] = iotlab_xrn.urn
rspec_node['component_name'] = node['hostname']
rspec_node['component_manager_id'] = \
- hrn_to_urn(self.driver.slab_api.root_auth, \
+ hrn_to_urn(self.driver.iotlab_api.root_auth, \
'authority+sa')
- # Senslab's nodes are federated : there is only one authority
- # for all Senslab sites, registered in SFA.
+ # Iotlab's nodes are federated : there is only one authority
+ # for all Iotlab 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']
rspec_node['boot_state'] = "Reserved"
rspec_node['exclusive'] = 'true'
rspec_node['hardware_types'] = [HardwareType({'name': \
- 'slab-node'})]
+ 'iotlab-node'})]
- location = SlabLocation({'country':'France', 'site': \
+ location = IotlabLocation({'country':'France', 'site': \
node['site']})
rspec_node['location'] = location
- position = SlabPosition()
+ position = IotlabPosition()
for field in position :
try:
position[field] = node[field]
#if slice_record:
#lease_filter.update({'name': slice_record['name']})
- #leases = self.driver.slab_api.GetLeases(lease_filter)
- leases = self.driver.slab_api.GetLeases()
- grain = self.driver.slab_api.GetLeaseGranularity()
+ #leases = self.driver.iotlab_api.GetLeases(lease_filter)
+ leases = self.driver.iotlab_api.GetLeases()
+ grain = self.driver.iotlab_api.GetLeaseGranularity()
site_ids = []
rspec_leases = []
for lease in leases:
rspec_lease = Lease()
rspec_lease['lease_id'] = lease['lease_id']
#site = node['site_id']
- slab_xrn = slab_xrn_object(self.driver.slab_api.root_auth, node)
- rspec_lease['component_id'] = slab_xrn.urn
+ iotlab_xrn = iotlab_xrn_object(self.driver.iotlab_api.root_auth, node)
+ rspec_lease['component_id'] = iotlab_xrn.urn
#rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn,\
#site, node['hostname'])
try:
rspec_lease['slice_id'] = lease['slice_id']
except KeyError:
- #No info on the slice used in slab_xp table
+ #No info on the slice used in iotlab_xp table
pass
rspec_lease['start_time'] = lease['t_from']
rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) \
rspec = None
version_manager = VersionManager()
version = version_manager.get_version(version)
- logger.debug("SlabAggregate \t get_rspec ***version %s \
+ logger.debug("IotlabAggregate \t get_rspec ***version %s \
version.type %s version.version %s options %s \r\n" \
%(version,version.type,version.version,options))
version.version, 'manifest')
slices, slivers = self.get_slice_and_slivers(slice_xrn, login)
- #at this point sliver may be empty if no senslab job
+ #at this point sliver may be empty if no iotlab job
#is running for this user/slice.
rspec = RSpec(version=rspec_version, user_options=options)
#datetime_to_string(utcparse(slice['expires']))
# add sliver defaults
#nodes, links = self.get_nodes(slice, slivers)
- logger.debug("\r\n \r\n SlabAggregate \tget_rspec *** \
+ logger.debug("\r\n \r\n IotlabAggregate \tget_rspec *** \
slice_xrn %s slices %s\r\n \r\n"\
%(slice_xrn, slices))
#if not options.get('list_leases') or options.get('list_leases')
#and options['list_leases'] != 'leases':
nodes = self.get_nodes(slices, slivers)
- logger.debug("\r\n \r\n SlabAggregate \ lease_option %s \
+ logger.debug("\r\n \r\n IotlabAggregate \ lease_option %s \
get rspec ******* nodes %s"\
%(lease_option, nodes[0]))
default_sliver = slivers.get('default_sliver', [])
if default_sliver:
#default_sliver_attribs = default_sliver.get('tags', [])
- logger.debug("SlabAggregate \tget_rspec **** \
+ logger.debug("IotlabAggregate \tget_rspec **** \
default_sliver%s \r\n" %(default_sliver))
for attrib in default_sliver:
rspec.version.add_default_sliver_attribute(attrib, \
leases = self.get_all_leases()
rspec.version.add_leases(leases)
- #logger.debug("SlabAggregate \tget_rspec ******* rspec_toxml %s \r\n"\
+ #logger.debug("IotlabAggregate \tget_rspec ******* rspec_toxml %s \r\n"\
#%(rspec.toxml()))
return rspec.toxml()
from sfa.storage.alchemy import dbsession
from sqlalchemy.orm import joinedload
from sfa.storage.model import RegRecord, RegUser, RegSlice, RegKey
-from sfa.senslab.slabpostgres import slab_dbsession, SenslabXP
+from sfa.iotlab.iotlabpostgres import iotlab_dbsession, IotlabXP
-from sfa.senslab.OARrestapi import OARrestapi
-from sfa.senslab.LDAPapi import LDAPapi
+from sfa.iotlab.OARrestapi import OARrestapi
+from sfa.iotlab.LDAPapi import LDAPapi
from sfa.util.xrn import Xrn, hrn_to_urn, get_authority
from sfa.trust.gid import create_uuid
from sfa.trust.hierarchy import Hierarchy
-from sfa.senslab.slabaggregate import slab_xrn_object
+from sfa.iotlab.iotlabaggregate import iotlab_xrn_object
-class SlabTestbedAPI():
+class IotlabTestbedAPI():
""" Class enabled to use LDAP and OAR api calls. """
def __init__(self, config):
existing_records = {}
existing_hrns_by_types = {}
- logger.debug("SLABDRIVER \tGetPeers peer_filter %s, \
+ logger.debug("IOTLABDRIVER \tGetPeers peer_filter %s, \
" %(peer_filter))
all_records = dbsession.query(RegRecord).filter(RegRecord.type.like('%authority%')).all()
existing_hrns_by_types[record.type].append(record.hrn)
- logger.debug("SLABDRIVER \tGetPeer\texisting_hrns_by_types %s "\
+ logger.debug("IOTLABDRIVER \tGetPeer\texisting_hrns_by_types %s "\
%( existing_hrns_by_types))
records_list = []
for hrn in existing_hrns_by_types['authority']:
records_list.append(existing_records[(hrn,'authority')])
- logger.debug("SLABDRIVER \tGetPeer \trecords_list %s " \
+ logger.debug("IOTLABDRIVER \tGetPeer \trecords_list %s " \
%(records_list))
except KeyError:
pass
return_records = records_list
- logger.debug("SLABDRIVER \tGetPeer return_records %s " \
+ logger.debug("IOTLABDRIVER \tGetPeer return_records %s " \
%(return_records))
return return_records
#over the records' list
def GetPersons(self, person_filter=None):
"""
- Get the enabled users and their properties from Senslab LDAP.
+ Get the enabled users and their properties from Iotlab LDAP.
If a filter is specified, looks for the user whose properties match
the filter, otherwise returns the whole enabled users'list.
:param person_filter: Must be a list of dictionnaries
:rtype: list of dicts
"""
- logger.debug("SLABDRIVER \tGetPersons person_filter %s" \
+ logger.debug("IOTLABDRIVER \tGetPersons person_filter %s" \
%(person_filter))
person_list = []
if person_filter and isinstance(person_filter, list):
#Usually the list contains only one user record
for searched_attributes in person_filter:
- #Get only enabled user accounts in senslab LDAP :
+ #Get only enabled user accounts in iotlab LDAP :
#add a filter for make_ldap_filters_from_record
person = self.ldap.LdapFindUser(searched_attributes, \
is_user_enabled=True)
person_list = None
else:
- #Get only enabled user accounts in senslab LDAP :
+ #Get only enabled user accounts in iotlab LDAP :
#add a filter for make_ldap_filters_from_record
person_list = self.ldap.LdapFindUser(is_user_enabled=True)
posting a delete request to OAR.
:param job_id: job id in OAR.
- :param username: user's senslab login in LDAP.
+ :param username: user's iotlab login in LDAP.
:type job_id:integer
:type username: string
(True) or no (False)
:rtype: dict
"""
- logger.debug("SLABDRIVER \tDeleteJobs jobid %s username %s "\
+ logger.debug("IOTLABDRIVER \tDeleteJobs jobid %s username %s "\
%(job_id, username))
if not job_id or job_id is -1:
return
ret = {job_id : True }
else:
ret = {job_id :False }
- logger.debug("SLABDRIVER \tDeleteJobs jobid %s \r\n answer %s \
+ logger.debug("IOTLABDRIVER \tDeleteJobs jobid %s \r\n answer %s \
username %s" %(job_id, answer, username))
return ret
##Get job info from OAR
#job_info = self.oar.parser.SendRequest(req, job_id, username)
- #logger.debug("SLABDRIVER \t GetJobsId %s " %(job_info))
+ #logger.debug("IOTLABDRIVER \t GetJobsId %s " %(job_info))
#try:
#if job_info['state'] == 'Terminated':
- #logger.debug("SLABDRIVER \t GetJobsId job %s TERMINATED"\
+ #logger.debug("IOTLABDRIVER \t GetJobsId job %s TERMINATED"\
#%(job_id))
#return None
#if job_info['state'] == 'Error':
- #logger.debug("SLABDRIVER \t GetJobsId ERROR message %s "\
+ #logger.debug("IOTLABDRIVER \t GetJobsId ERROR message %s "\
#%(job_info))
#return None
#except KeyError:
- #logger.error("SLABDRIVER \tGetJobsId KeyError")
+ #logger.error("IOTLABDRIVER \tGetJobsId KeyError")
#return None
#parsed_job_info = self.get_info_on_reserved_nodes(job_info, \
##with "node_ids"
#job_info.update({'node_ids':parsed_job_info[node_list_k]})
#del job_info[node_list_k]
- #logger.debug(" \r\nSLABDRIVER \t GetJobsId job_info %s " %(job_info))
+ #logger.debug(" \r\nIOTLABDRIVER \t GetJobsId job_info %s " %(job_info))
#return job_info
def GetJobsResources(self, job_id, username = None):
""" Gets the list of nodes associated with the job_id and username
if provided.
- Transforms the senslab hostnames to the corresponding
+ Transforms the iotlab hostnames to the corresponding
SFA nodes hrns.
Rertuns dict key :'node_ids' , value : hostnames list
:param username: user's LDAP login
#Get job resources list from OAR
node_id_list = self.oar.parser.SendRequest(req, job_id, username)
- logger.debug("SLABDRIVER \t GetJobsResources %s " %(node_id_list))
+ logger.debug("IOTLABDRIVER \t GetJobsResources %s " %(node_id_list))
hostname_list = \
self.__get_hostnames_from_oar_node_ids(node_id_list)
#reserved_node_hostname_list[index] = \
#node_dict[job_info[node_list_name][index]]['hostname']
- #logger.debug("SLABDRIVER \t get_info_on_reserved_nodes \
+ #logger.debug("IOTLABDRIVER \t get_info_on_reserved_nodes \
#reserved_node_hostname_list %s" \
#%(reserved_node_hostname_list))
#except KeyError:
- #logger.error("SLABDRIVER \t get_info_on_reserved_nodes KEYERROR " )
+ #logger.error("IOTLABDRIVER \t get_info_on_reserved_nodes KEYERROR " )
#return reserved_node_hostname_list
def GetNodes(self, node_filter_dict = None, return_fields_list = None):
"""
- Make a list of senslab nodes and their properties from information
+ Make a list of iotlab nodes and their properties from information
given by OAR. Search for specific nodes if some filters are specified.
Nodes properties returned if no return_fields_list given:
'hrn','archi','mobile','hostname','site','boot_state','node_id',
"""
node_dict_by_id = self.oar.parser.SendRequest("GET_resources_full")
node_dict_list = node_dict_by_id.values()
- logger.debug (" SLABDRIVER GetNodes node_filter_dict %s \
+ logger.debug (" IOTLABDRIVER GetNodes node_filter_dict %s \
return_fields_list %s "%(node_filter_dict, return_fields_list))
#No filtering needed return the list directly
if not (node_filter_dict or return_fields_list):
@staticmethod
def AddSlice(slice_record, user_record):
- """Add slice to the local senslab sfa tables if the slice comes
- from a federated site and is not yet in the senslab sfa DB,
+ """Add slice to the local iotlab sfa tables if the slice comes
+ from a federated site and is not yet in the iotlab sfa DB,
although the user has already a LDAP login.
Called by verify_slice during lease/sliver creation.
:param slice_record: record of slice, must contain hrn, gid, slice_id
gid=slice_record['gid'],
pointer=slice_record['slice_id'],
authority=slice_record['authority'])
- logger.debug("SLABDRIVER.PY AddSlice sfa_record %s user_record %s"
+ logger.debug("IOTLABDRIVER.PY AddSlice sfa_record %s user_record %s"
% (sfa_record, user_record))
sfa_record.just_created()
dbsession.add(sfa_record)
#TODO : Check rights to delete person
def DeletePerson(self, person_record):
- """ Disable an existing account in senslab LDAP.
+ """ Disable an existing account in iotlab LDAP.
Users and techs can only delete themselves. PIs can only
delete themselves and other non-PIs at their sites.
ins can delete anyone.
:rtype: boolean
"""
- #Disable user account in senslab LDAP
+ #Disable user account in iotlab LDAP
ret = self.ldap.LdapMarkUserAsDeleted(person_record)
- logger.warning("SLABDRIVER DeletePerson %s " %(person_record))
+ logger.warning("IOTLABDRIVER DeletePerson %s " %(person_record))
return ret['bool']
delete_failed = []
delete_failed.append(job_id)
- logger.info("SLABDRIVER DeleteSlice %s answer %s"%(slice_record, \
+ logger.info("IOTLABDRIVER DeleteSlice %s answer %s"%(slice_record, \
delete_failed))
return delete_failed or True
def __add_person_to_db(user_dict):
"""
Add a federated user straight to db when the user issues a lease
- request with senslab nodes and that he has not registered with senslab
+ request with iotlab nodes and that he has not registered with iotlab
yet (that is he does not have a LDAP entry yet).
Uses parts of the routines in SlabImport when importing user from LDAP.
Called by AddPerson, right after LdapAddUser.
if ret['bool'] is True:
record['hrn'] = self.root_auth + '.' + ret['uid']
- logger.debug("SLABDRIVER AddPerson return code %s record %s \r\n "\
+ logger.debug("IOTLABDRIVER AddPerson return code %s record %s \r\n "\
%(ret, record))
self.__add_person_to_db(record)
return ret['uid']
#TODO AddPersonKey 04/07/2012 SA
def AddPersonKey(self, person_uid, old_attributes_dict, new_key_dict):
"""Adds a new key to the specified account. Adds the key to the
- senslab ldap, provided that the person_uid is valid.
+ iotlab ldap, provided that the person_uid is valid.
Non-admins can only modify their own keys.
- :param person_uid: user's senslab login in LDAP
+ :param person_uid: user's iotlab login in LDAP
:param old_attributes_dict: dict with the user's old sshPublicKey
:param new_key_dict:dict with the user's new sshPublicKey
:type person_uid: string
"""
ret = self.ldap.LdapModify(person_uid, old_attributes_dict, \
new_key_dict)
- logger.warning("SLABDRIVER AddPersonKey EMPTY - DO NOTHING \r\n ")
+ logger.warning("IOTLABDRIVER AddPersonKey EMPTY - DO NOTHING \r\n ")
return ret['bool']
def DeleteLeases(self, leases_id_list, slice_hrn ):
way to handle failure when dealing with multiple job delete. Plus,
there was no easy way to report it to the user.
"""
- logger.debug("SLABDRIVER DeleteLeases leases_id_list %s slice_hrn %s \
+ logger.debug("IOTLABDRIVER DeleteLeases leases_id_list %s slice_hrn %s \
\r\n " %(leases_id_list, slice_hrn))
for job_id in leases_id_list:
self.DeleteJobs(job_id, slice_hrn)
walltime, sleep_walltime = \
- SlabTestbedAPI._process_walltime(\
+ IotlabTestbedAPI._process_walltime(\
int(lease_dict['lease_duration']))
lease_dict['time_format'] = self.time_format
- logger.debug("SLABDRIVER.PY \tLaunchExperimentOnOAR slice_user %s\
+ logger.debug("IOTLABDRIVER.PY \tLaunchExperimentOnOAR slice_user %s\
\r\n " %(slice_user))
#Create the request for OAR
reqdict = self._create_job_structure_request_for_OAR(lease_dict)
# first step : start the OAR job and update the job
- logger.debug("SLABDRIVER.PY \tLaunchExperimentOnOAR reqdict %s\
+ logger.debug("IOTLABDRIVER.PY \tLaunchExperimentOnOAR reqdict %s\
\r\n " %(reqdict))
answer = self.oar.POSTRequestToOARRestAPI('POST_job', \
reqdict, slice_user)
- logger.debug("SLABDRIVER \tLaunchExperimentOnOAR jobid %s " %(answer))
+ logger.debug("IOTLABDRIVER \tLaunchExperimentOnOAR jobid %s " %(answer))
try:
jobid = answer['id']
except KeyError:
- logger.log_exc("SLABDRIVER \tLaunchExperimentOnOAR \
+ logger.log_exc("IOTLABDRIVER \tLaunchExperimentOnOAR \
Impossible to create job %s " %(answer))
return None
if jobid :
- logger.debug("SLABDRIVER \tLaunchExperimentOnOAR jobid %s \
+ logger.debug("IOTLABDRIVER \tLaunchExperimentOnOAR jobid %s \
added_nodes %s slice_user %s" %(jobid, added_nodes, \
slice_user))
lease_start_time, lease_duration):
"""Creates a job in OAR corresponding to the information provided
- as parameters. Adds the job id and the slice hrn in the senslab
+ as parameters. Adds the job id and the slice hrn in the iotlab
database so that we are able to know which slice has which nodes.
:param hostname_list: list of nodes' OAR hostnames.
:type lease_duration: integer
"""
- logger.debug("SLABDRIVER \r\n \r\n \t AddLeases hostname_list %s \
+ logger.debug("IOTLABDRIVER \r\n \r\n \t AddLeases hostname_list %s \
slice_record %s lease_start_time %s lease_duration %s "\
%( hostname_list, slice_record , lease_start_time, \
lease_duration))
end_time = lease_start_time + lease_duration
- logger.debug("SLABDRIVER \r\n \r\n \t AddLeases TURN ON LOGGING SQL \
+ logger.debug("IOTLABDRIVER \r\n \r\n \t AddLeases TURN ON LOGGING SQL \
%s %s %s "%(slice_record['hrn'], job_id, end_time))
- logger.debug("SLABDRIVER \r\n \r\n \t AddLeases %s %s %s " \
+ logger.debug("IOTLABDRIVER \r\n \r\n \t AddLeases %s %s %s " \
%(type(slice_record['hrn']), type(job_id), type(end_time)))
- slab_ex_row = SenslabXP(slice_hrn = slice_record['hrn'], \
+ iotlab_ex_row = IotlabXP(slice_hrn = slice_record['hrn'], \
job_id = job_id, end_time= end_time)
- logger.debug("SLABDRIVER \r\n \r\n \t AddLeases slab_ex_row %s" \
- %(slab_ex_row))
- slab_dbsession.add(slab_ex_row)
- slab_dbsession.commit()
+ logger.debug("IOTLABDRIVER \r\n \r\n \t AddLeases iotlab_ex_row %s" \
+ %(iotlab_ex_row))
+ iotlab_dbsession.add(iotlab_ex_row)
+ iotlab_dbsession.commit()
- logger.debug("SLABDRIVER \t AddLeases hostname_list start_time %s " \
+ logger.debug("IOTLABDRIVER \t AddLeases hostname_list start_time %s " \
%(start_time))
return
- #Delete the jobs from job_senslab table
+ #Delete the jobs from job_iotlab table
def DeleteSliceFromNodes(self, slice_record):
""" Deletes all the running or scheduled jobs of a given slice
given its record.
False, for each job id.
:rtype: dict
"""
- logger.debug("SLABDRIVER \t DeleteSliceFromNodese %s " %(slice_record))
+ logger.debug("IOTLABDRIVER \t DeleteSliceFromNodese %s " %(slice_record))
if isinstance(slice_record['oar_job_id'], list):
oar_bool_answer = {}
def GetLeaseGranularity(self):
- """ Returns the granularity of an experiment in the Senslab testbed.
+ """ Returns the granularity of an experiment in the Iotlab testbed.
OAR uses seconds for experiments duration , the granulaity is also
defined in seconds.
Experiments which last less than 10 min (600 sec) are invalid"""
@staticmethod
- def update_jobs_in_slabdb( job_oar_list, jobs_psql):
- """ Cleans the slab db by deleting expired and cancelled jobs.
+ def update_jobs_in_iotlabdb( job_oar_list, jobs_psql):
+ """ Cleans the iotlab db by deleting expired and cancelled jobs.
Compares the list of job ids given by OAR with the job ids that
are already in the database, deletes the jobs that are no longer in
the OAR job id list.
set_jobs_psql = set(jobs_psql)
kept_jobs = set(job_oar_list).intersection(set_jobs_psql)
- logger.debug ( "\r\n \t\ update_jobs_in_slabdb jobs_psql %s \r\n \t \
+ logger.debug ( "\r\n \t\ update_jobs_in_iotlabdb jobs_psql %s \r\n \t \
job_oar_list %s kept_jobs %s "%(set_jobs_psql, job_oar_list, kept_jobs))
deleted_jobs = set_jobs_psql.difference(kept_jobs)
deleted_jobs = list(deleted_jobs)
if len(deleted_jobs) > 0:
- slab_dbsession.query(SenslabXP).filter(SenslabXP.job_id.in_(deleted_jobs)).delete(synchronize_session='fetch')
- slab_dbsession.commit()
+ iotlab_dbsession.query(IotlabXP).filter(IotlabXP.job_id.in_(deleted_jobs)).delete(synchronize_session='fetch')
+ iotlab_dbsession.commit()
return
Two purposes:
-Fetch all the jobs from OAR (running, waiting..)
complete the reservation information with slice hrn
- found in slabxp table. If not available in the table,
- assume it is a senslab slice.
- -Updates the slab table, deleting jobs when necessary.
+ found in iotlab_xp table. If not available in the table,
+ assume it is a iotlab slice.
+ -Updates the iotlab table, deleting jobs when necessary.
:return: reservation_list, list of dictionaries with 'lease_id',
'reserved_nodes','slice_id', 'state', 'user', 'component_id_list',
'slice_hrn', 'resource_ids', 't_from', 't_until'
unfiltered_reservation_list = self.GetReservedNodes(login)
reservation_list = []
- #Find the slice associated with this user senslab ldap uid
- logger.debug(" SLABDRIVER.PY \tGetLeases login %s\
+ #Find the slice associated with this user iotlab ldap uid
+ logger.debug(" IOTLABDRIVER.PY \tGetLeases login %s\
unfiltered_reservation_list %s " %(login, unfiltered_reservation_list))
#Create user dict first to avoid looking several times for
#the same user in LDAP SA 27/07/12
job_oar_list = []
- jobs_psql_query = slab_dbsession.query(SenslabXP).all()
+ jobs_psql_query = iotlab_dbsession.query(IotlabXP).all()
jobs_psql_dict = dict([(row.job_id, row.__dict__ ) for row in jobs_psql_query ])
#jobs_psql_dict = jobs_psql_dict)
- logger.debug("SLABDRIVER \tGetLeases jobs_psql_dict %s"\
+ logger.debug("IOTLABDRIVER \tGetLeases jobs_psql_dict %s"\
%(jobs_psql_dict))
jobs_psql_id_list = [ row.job_id for row in jobs_psql_query ]
for resa in unfiltered_reservation_list:
- logger.debug("SLABDRIVER \tGetLeases USER %s"\
+ logger.debug("IOTLABDRIVER \tGetLeases USER %s"\
%(resa['user']))
#Construct list of jobs (runing, waiting..) in oar
job_oar_list.append(resa['lease_id'])
#(slice used and job id)
if resa['lease_id'] in jobs_psql_dict:
job_info = jobs_psql_dict[resa['lease_id']]
- logger.debug("SLABDRIVER \tGetLeases job_info %s"\
+ logger.debug("IOTLABDRIVER \tGetLeases job_info %s"\
%(job_info))
resa['slice_hrn'] = job_info['slice_hrn']
resa['slice_id'] = hrn_to_urn(resa['slice_hrn'], 'slice')
- #otherwise, assume it is a senslab slice:
+ #otherwise, assume it is a iotlab slice:
else:
resa['slice_id'] = hrn_to_urn(self.root_auth+'.'+ \
resa['user'] +"_slice" , 'slice')
#Transform the hostnames into urns (component ids)
for node in resa['reserved_nodes']:
- slab_xrn = slab_xrn_object(self.root_auth, node)
- resa['component_id_list'].append(slab_xrn.urn)
+ iotlab_xrn = iotlab_xrn_object(self.root_auth, node)
+ resa['component_id_list'].append(iotlab_xrn.urn)
if lease_filter_dict:
- logger.debug("SLABDRIVER \tGetLeases resa_ %s \
+ logger.debug("IOTLABDRIVER \tGetLeases resa_ %s \
\r\n leasefilter %s" %(resa, lease_filter_dict))
if lease_filter_dict['name'] == resa['slice_hrn']:
reservation_list = unfiltered_reservation_list
- self.update_jobs_in_slabdb(job_oar_list, jobs_psql_id_list)
+ self.update_jobs_in_iotlabdb(job_oar_list, jobs_psql_id_list)
- logger.debug(" SLABDRIVER.PY \tGetLeases reservation_list %s"\
+ logger.debug(" IOTLABDRIVER.PY \tGetLeases reservation_list %s"\
%(reservation_list))
return reservation_list
#FROM PLC DOC
#"""
- #logger.warning("SLABDRIVER \tUnBindObjectFromPeer EMPTY-\
+ #logger.warning("IOTLABDRIVER \tUnBindObjectFromPeer EMPTY-\
#DO NOTHING \r\n ")
#return
#FROM PLC API DOC
#"""
- #logger.warning("SLABDRIVER \tBindObjectToPeer EMPTY - DO NOTHING \r\n ")
+ #logger.warning("IOTLABDRIVER \tBindObjectToPeer EMPTY - DO NOTHING \r\n ")
#return
##TODO UpdateSlice 04/07/2012 SA || Commented out 28/05/13 SA
- ##Funciton should delete and create another job since oin senslab slice=job
+ ##Funciton should delete and create another job since oin iotlab slice=job
#def UpdateSlice(self, auth, slice_id_or_name, slice_fields=None):
#"""Updates the parameters of an existing slice with the values in
#slice_fields.
#FROM PLC API DOC
#"""
- #logger.warning("SLABDRIVER UpdateSlice EMPTY - DO NOTHING \r\n ")
+ #logger.warning("IOTLABDRIVER UpdateSlice EMPTY - DO NOTHING \r\n ")
#return
#Unused SA 30/05/13, we only update the user's key or we delete it.
##TODO UpdatePerson 04/07/2012 SA
- #def UpdatePerson(self, slab_hrn, federated_hrn, person_fields=None):
+ #def UpdatePerson(self, iotlab_hrn, federated_hrn, person_fields=None):
#"""Updates a person. Only the fields specified in person_fields
#are updated, all other fields are left untouched.
#Users and techs can only update themselves. PIs can only update
#FROM PLC API DOC
#"""
- ##new_row = FederatedToSenslab(slab_hrn, federated_hrn)
- ##slab_dbsession.add(new_row)
- ##slab_dbsession.commit()
+ ##new_row = FederatedToIotlab(iotlab_hrn, federated_hrn)
+ ##iotlab_dbsession.add(new_row)
+ ##iotlab_dbsession.commit()
- #logger.debug("SLABDRIVER UpdatePerson EMPTY - DO NOTHING \r\n ")
+ #logger.debug("IOTLABDRIVER UpdatePerson EMPTY - DO NOTHING \r\n ")
#return
@staticmethod
#user_by_email = dict((user[1]['mail'][0], user[1]['sshPublicKey']) \
#for user in ldap_rslt)
- logger.debug("SLABDRIVER GetKeys -key_dict %s \r\n " %(key_dict))
+ logger.debug("IOTLABDRIVER GetKeys -key_dict %s \r\n " %(key_dict))
return key_dict
#TODO : test
all_user_keys.remove(key_string)
new_attributes = {'sshPublicKey':all_user_keys}
ret = self.ldap.LdapModifyUser(user_record, new_attributes)
- logger.debug("SLABDRIVER DeleteKey %s- "%(ret))
+ logger.debug("IOTLABDRIVER DeleteKey %s- "%(ret))
return ret['bool']
#of the user otherwise will mess up the RegRecord in
#Resolve, don't know why - SA 08/08/2012
- #Only one entry for one user = one slice in slab_xp table
+ #Only one entry for one user = one slice in iotlab_xp table
#slicerec = dbsession.query(RegRecord).filter_by(hrn = slice_filter).first()
raw_slicerec = dbsession.query(RegSlice).options(joinedload('reg_researchers')).filter_by(hrn = slice_filter).first()
#raw_slicerec = dbsession.query(RegRecord).filter_by(hrn = slice_filter).first()
#load_reg_researcher
#raw_slicerec.reg_researchers
raw_slicerec = raw_slicerec.__dict__
- logger.debug(" SLABDRIVER \t get_slice_info slice_filter %s \
+ logger.debug(" IOTLABDRIVER \t get_slice_info slice_filter %s \
raw_slicerec %s"%(slice_filter, raw_slicerec))
slicerec = raw_slicerec
#only one researcher per slice so take the first one
#At this point if there is no login it means
#record_id_user filter has been used for filtering
#if login is None :
- ##If theslice record is from senslab
+ ##If theslice record is from iotlab
#if fixed_slicerec_dict['peer_authority'] is None:
#login = fixed_slicerec_dict['hrn'].split(".")[1].split("_")[0]
#return login, fixed_slicerec_dict
def GetSlices(self, slice_filter = None, slice_filter_type = None, \
login=None):
- """ Get the slice records from the slab db and add lease information
+ """ Get the slice records from the iotlab db and add lease information
if any.
:param slice_filter: can be the slice hrn or slice record id in the db
self._get_slice_records(slice_filter, slice_filter_type)
slice_hrn = fixed_slicerec_dict['hrn']
- logger.debug(" SLABDRIVER \tGetSlices login %s \
+ logger.debug(" IOTLABDRIVER \tGetSlices login %s \
slice record %s slice_filter %s \
slice_filter_type %s " %(login, \
fixed_slicerec_dict, slice_filter, \
for lease in leases_list :
slicerec_dict = {}
- logger.debug("SLABDRIVER.PY \tGetSlices slice_filter %s \
+ logger.debug("IOTLABDRIVER.PY \tGetSlices slice_filter %s \
\ lease['slice_hrn'] %s" \
%(slice_filter, lease['slice_hrn']))
if lease['slice_hrn'] == slice_hrn:
#str(fixed_slicerec_dict['slice_hrn'])})
return_slicerec_dictlist.append(slicerec_dict)
- logger.debug("SLABDRIVER.PY \tGetSlices \
+ logger.debug("IOTLABDRIVER.PY \tGetSlices \
OHOHOHOH %s" %(return_slicerec_dictlist ))
- logger.debug("SLABDRIVER.PY \tGetSlices \
+ logger.debug("IOTLABDRIVER.PY \tGetSlices \
slicerec_dict %s return_slicerec_dictlist %s \
lease['reserved_nodes'] \
%s" %(slicerec_dict, return_slicerec_dictlist, \
lease['reserved_nodes'] ))
- logger.debug("SLABDRIVER.PY \tGetSlices RETURN \
+ logger.debug("IOTLABDRIVER.PY \tGetSlices RETURN \
return_slicerec_dictlist %s" \
%(return_slicerec_dictlist))
else:
- #Get all slices from the senslab sfa database ,
+ #Get all slices from the iotlab sfa database ,
#put them in dict format
#query_slice_list = dbsession.query(RegRecord).all()
query_slice_list = dbsession.query(RegSlice).options(joinedload('reg_researchers')).all()
for fixed_slicerec_dict in return_slicerec_dictlist:
slicerec_dict = {}
- #Check if the slice belongs to a senslab user
+ #Check if the slice belongs to a iotlab user
if fixed_slicerec_dict['peer_authority'] is None:
owner = fixed_slicerec_dict['hrn'].split(".")[1].split("_")[0]
else:
slicerec_dict['oar_job_id'] = lease['lease_id']
#for reserved_node in lease['reserved_nodes']:
- logger.debug("SLABDRIVER.PY \tGetSlices lease %s "\
+ logger.debug("IOTLABDRIVER.PY \tGetSlices lease %s "\
%(lease ))
slicerec_dict.update({'node_ids':lease['reserved_nodes']})
#return_slicerec_dictlist.append(slicerec_dict)
fixed_slicerec_dict.update(slicerec_dict)
- logger.debug("SLABDRIVER.PY \tGetSlices RETURN \
+ logger.debug("IOTLABDRIVER.PY \tGetSlices RETURN \
return_slicerec_dictlist %s \slice_filter %s " \
%(return_slicerec_dictlist, slice_filter))
- #Update slice unused, therefore sfa_fields_to_slab_fields unused
+ #Update slice unused, therefore sfa_fields_to_iotlab_fields unused
#SA 30/05/13
#@staticmethod
- #def sfa_fields_to_slab_fields(sfa_type, hrn, record):
+ #def sfa_fields_to_iotlab_fields(sfa_type, hrn, record):
#"""
#"""
- #slab_record = {}
+ #iotlab_record = {}
##for field in record:
- ## slab_record[field] = record[field]
+ ## iotlab_record[field] = record[field]
#if sfa_type == "slice":
##instantion used in get_slivers ?
- #if not "instantiation" in slab_record:
- #slab_record["instantiation"] = "senslab-instantiated"
- ##slab_record["hrn"] = hrn_to_pl_slicename(hrn)
+ #if not "instantiation" in iotlab_record:
+ #iotlab_record["instantiation"] = "iotlab-instantiated"
+ ##iotlab_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 " %(slab_record['hrn']))
+ #iotlab_record["hrn"] = hrn
+ #logger.debug("IOTLABDRIVER.PY sfa_fields_to_iotlab_fields \
+ #iotlab_record %s " %(iotlab_record['hrn']))
#if "url" in record:
- #slab_record["url"] = record["url"]
+ #iotlab_record["url"] = record["url"]
#if "description" in record:
- #slab_record["description"] = record["description"]
+ #iotlab_record["description"] = record["description"]
#if "expires" in record:
- #slab_record["expires"] = int(record["expires"])
+ #iotlab_record["expires"] = int(record["expires"])
##nodes added by OAR only and then imported to SFA
##elif type == "node":
- ##if not "hostname" in slab_record:
+ ##if not "hostname" in iotlab_record:
##if not "hostname" in record:
##raise MissingSfaInfo("hostname")
- ##slab_record["hostname"] = record["hostname"]
- ##if not "model" in slab_record:
- ##slab_record["model"] = "geni"
+ ##iotlab_record["hostname"] = record["hostname"]
+ ##if not "model" in iotlab_record:
+ ##iotlab_record["model"] = "geni"
##One authority only
##elif type == "authority":
- ##slab_record["login_base"] = hrn_to_slab_login_base(hrn)
+ ##iotlab_record["login_base"] = hrn_to_iotlab_login_base(hrn)
- ##if not "name" in slab_record:
- ##slab_record["name"] = hrn
+ ##if not "name" in iotlab_record:
+ ##iotlab_record["name"] = hrn
- ##if not "abbreviated_name" in slab_record:
- ##slab_record["abbreviated_name"] = hrn
+ ##if not "abbreviated_name" in iotlab_record:
+ ##iotlab_record["abbreviated_name"] = hrn
- ##if not "enabled" in slab_record:
- ##slab_record["enabled"] = True
+ ##if not "enabled" in iotlab_record:
+ ##iotlab_record["enabled"] = True
- ##if not "is_public" in slab_record:
- ##slab_record["is_public"] = True
+ ##if not "is_public" in iotlab_record:
+ ##iotlab_record["is_public"] = True
- #return slab_record
+ #return iotlab_record
from sfa.util.xrn import Xrn, hrn_to_urn, get_authority
-from sfa.senslab.slabpostgres import SlabDB
+from sfa.iotlab.iotlabpostgres import IotlabDB
-from sfa.senslab.slabaggregate import SlabAggregate, slab_xrn_to_hostname
+from sfa.iotlab.iotlabaggregate import IotlabAggregate, iotlab_xrn_to_hostname
-from sfa.senslab.slabslices import SlabSlices
+from sfa.iotlab.iotlabslices import IotlabSlices
-from sfa.senslab.slabapi import SlabTestbedAPI
+from sfa.iotlab.iotlabapi import IotlabTestbedAPI
-class SlabDriver(Driver):
- """ Senslab Driver class inherited from Driver generic class.
+class IotlabDriver(Driver):
+ """ Iotlab Driver class inherited from Driver generic class.
Contains methods compliant with the SFA standard and the testbed
infrastructure (calls to LDAP and OAR).
def __init__(self, config):
"""
- Sets the senslab SFA config parameters ,
- instanciates the testbed api and the senslab database.
+ Sets the iotlab SFA config parameters ,
+ instanciates the testbed api and the iotlab database.
- :param config: senslab SFA configuration object
+ :param config: iotlab SFA configuration object
:type config: Config object
"""
Driver.__init__ (self, config)
self.config = config
- self.db = SlabDB(config, debug = False)
- self.slab_api = SlabTestbedAPI(config)
+ self.db = IotlabDB(config, debug = False)
+ self.iotlab_api = IotlabTestbedAPI(config)
self.cache = None
def augment_records_with_testbed_info (self, record_list ):
def fill_record_info(self, record_list):
"""
- For each SFA record, fill in the senslab specific and SFA specific
+ For each SFA record, fill in the iotlab specific and SFA specific
fields in the record.
:param record_list: list of sfa dictionaries records
other way to do it given the way it's called in registry manager.
"""
- logger.debug("SLABDRIVER \tfill_record_info records %s " %(record_list))
+ logger.debug("IOTLABDRIVER \tfill_record_info records %s " %(record_list))
if not isinstance(record_list, list):
record_list = [record_list]
for record in record_list:
#If the record is a SFA slice record, then add information
#about the user of this slice. This kind of
- #information is in the Senslab's DB.
+ #information is in the Iotlab's DB.
if str(record['type']) == 'slice':
if 'reg_researchers' in record and \
isinstance(record['reg_researchers'], list) :
'key_ids':''}) #For client_helper.py compatibility
- #Get slab slice record and oar job id if any.
- recslice_list = self.slab_api.GetSlices(slice_filter = \
+ #Get iotlab slice record and oar job id if any.
+ recslice_list = self.iotlab_api.GetSlices(slice_filter = \
str(record['hrn']),\
slice_filter_type = 'slice_hrn')
- logger.debug("SLABDRIVER \tfill_record_info \
+ logger.debug("IOTLABDRIVER \tfill_record_info \
TYPE SLICE RECUSER record['hrn'] %s ecord['oar_job_id']\
%s " %(record['hrn'], record['oar_job_id']))
del record['reg_researchers']
try:
for rec in recslice_list:
- logger.debug("SLABDRIVER\r\n \t \
+ logger.debug("IOTLABDRIVER\r\n \t \
fill_record_info oar_job_id %s " \
%(rec['oar_job_id']))
- record['node_ids'] = [ self.slab_api.root_auth + \
+ record['node_ids'] = [ self.iotlab_api.root_auth + \
hostname for hostname in rec['node_ids']]
except KeyError:
pass
- logger.debug( "SLABDRIVER.PY \t fill_record_info SLICE \
+ logger.debug( "IOTLABDRIVER.PY \t fill_record_info SLICE \
recslice_list %s \r\n \t RECORD %s \r\n \
\r\n" %(recslice_list, record))
if str(record['type']) == 'user':
#The record is a SFA user record.
- #Get the information about his slice from Senslab's DB
+ #Get the information about his slice from Iotlab's DB
#and add it to the user record.
- recslice_list = self.slab_api.GetSlices(\
+ recslice_list = self.iotlab_api.GetSlices(\
slice_filter = record['record_id'],\
slice_filter_type = 'record_id_user')
- logger.debug( "SLABDRIVER.PY \t fill_record_info TYPE USER \
+ logger.debug( "IOTLABDRIVER.PY \t fill_record_info TYPE USER \
recslice_list %s \r\n \t RECORD %s \r\n" \
%(recslice_list , record))
#Append slice record in records list,
#Will update PIs and researcher for the slice
recuser = recslice_list[0]['reg_researchers']
- logger.debug( "SLABDRIVER.PY \t fill_record_info USER \
+ logger.debug( "IOTLABDRIVER.PY \t fill_record_info USER \
recuser %s \r\n \r\n" %(recuser))
recslice = {}
recslice = recslice_list[0]
#GetPersons takes [] as filters
- user_slab = self.slab_api.GetPersons([record])
+ user_iotlab = self.iotlab_api.GetPersons([record])
- record.update(user_slab[0])
+ record.update(user_iotlab[0])
#For client_helper.py compatibility
record.update( { 'geni_urn':'',
'keys':'',
'key_ids':'' })
record_list.append(recslice)
- logger.debug("SLABDRIVER.PY \tfill_record_info ADDING SLICE\
+ logger.debug("IOTLABDRIVER.PY \tfill_record_info ADDING SLICE\
INFO TO USER records %s" %(record_list))
except TypeError, error:
- logger.log_exc("SLABDRIVER \t fill_record_info EXCEPTION %s"\
+ logger.log_exc("IOTLABDRIVER \t fill_record_info EXCEPTION %s"\
%(error))
return record_list
def sliver_status(self, slice_urn, slice_hrn):
"""
Receive a status request for slice named urn/hrn
- urn:publicid:IDN+senslab+nturro_slice hrn senslab.nturro_slice
+ urn:publicid:IDN+iotlab+nturro_slice hrn iotlab.nturro_slice
shall return a structure as described in
http://groups.geni.net/geni/wiki/GAPI_AM_API_V2#SliverStatus
NT : not sure if we should implement this or not, but used by sface.
#First get the slice with the slice hrn
- slice_list = self.slab_api.GetSlices(slice_filter = slice_hrn, \
+ slice_list = self.iotlab_api.GetSlices(slice_filter = slice_hrn, \
slice_filter_type = 'slice_hrn')
if len(slice_list) is 0:
#slice_nodes_list.append(node['hostname'])
slice_nodes_list = one_slice['node_ids']
#Get all the corresponding nodes details
- nodes_all = self.slab_api.GetNodes({'hostname':slice_nodes_list},
+ nodes_all = self.iotlab_api.GetNodes({'hostname':slice_nodes_list},
['node_id', 'hostname','site','boot_state'])
nodeall_byhostname = dict([(one_node['hostname'], one_node) \
for one_node in nodes_all])
top_level_status = 'ready'
- #A job is running on Senslab for this slice
+ #A job is running on Iotlab for this slice
# report about the local nodes that are in the slice only
result['geni_urn'] = slice_urn
resources = []
for node_hostname in single_slice['node_ids']:
res = {}
- res['slab_hostname'] = node_hostname
- res['slab_boot_state'] = nodeall_byhostname[node_hostname]['boot_state']
+ res['iotlab_hostname'] = node_hostname
+ res['iotlab_boot_state'] = nodeall_byhostname[node_hostname]['boot_state']
#res['pl_hostname'] = node['hostname']
#res['pl_boot_state'] = \
result['geni_status'] = top_level_status
result['geni_resources'] = resources
- logger.debug("SLABDRIVER \tsliver_statusresources %s res %s "\
+ logger.debug("IOTLABDRIVER \tsliver_statusresources %s res %s "\
%(resources,res))
return result
type. Find the lease requests in the rspec and creates
a lease request list with the mandatory information ( nodes,
start time and duration) of the valid leases (duration above or equal
- to the senslab experiment minimum duration).
+ to the iotlab experiment minimum duration).
:param rspec: rspec request received.
:type rspec: RSpec
requested_lease_list = []
for lease in rspec.version.get_leases():
single_requested_lease = {}
- logger.debug("SLABDRIVER.PY \t_get_requested_leases_list lease %s " %(lease))
+ logger.debug("IOTLABDRIVER.PY \t_get_requested_leases_list lease %s " %(lease))
if not lease.get('lease_id'):
if get_authority(lease['component_id']) == \
- self.slab_api.root_auth:
+ self.iotlab_api.root_auth:
single_requested_lease['hostname'] = \
- slab_xrn_to_hostname(\
+ iotlab_xrn_to_hostname(\
lease.get('component_id').strip())
single_requested_lease['start_time'] = \
lease.get('start_time')
#the lease to the requested leases list
duration_in_seconds = \
int(single_requested_lease['duration'])
- if duration_in_seconds >= self.slab_api.GetMinExperimentDurationInSec() :
+ if duration_in_seconds >= self.iotlab_api.GetMinExperimentDurationInSec() :
requested_lease_list.append(single_requested_lease)
return requested_lease_list
:rtype: dictionary
"""
requested_lease_list = self._get_requested_leases_list(rspec)
- logger.debug("SLABDRIVER _process_requested_jobs requested_lease_list \
+ logger.debug("IOTLABDRIVER _process_requested_jobs requested_lease_list \
%s"%(requested_lease_list))
job_dict = self._group_leases_by_start_time(requested_lease_list)
- logger.debug("SLABDRIVER _process_requested_jobs job_dict\
+ logger.debug("IOTLABDRIVER _process_requested_jobs job_dict\
%s"%(job_dict))
return job_dict
"""
- aggregate = SlabAggregate(self)
+ aggregate = IotlabAggregate(self)
- slices = SlabSlices(self)
+ slices = IotlabSlices(self)
peer = slices.get_peer(slice_hrn)
sfa_peer = slices.get_sfa_peer(slice_hrn)
slice_record = None
if users:
slice_record = users[0].get('slice_record', {})
- logger.debug("SLABDRIVER.PY \t ===============create_sliver \t\
+ logger.debug("IOTLABDRIVER.PY \t ===============create_sliver \t\
creds %s \r\n \r\n users %s" \
%(creds, users))
slice_record['user'] = {'keys':users[0]['keys'], \
'hrn':slice_record['reg-researchers'][0]}
# parse rspec
rspec = RSpec(rspec_string)
- logger.debug("SLABDRIVER.PY \t create_sliver \trspec.version \
+ logger.debug("IOTLABDRIVER.PY \t create_sliver \trspec.version \
%s slice_record %s users %s" \
%(rspec.version,slice_record, users))
#unused, removed SA 13/08/12
#rspec.version.get_slice_attributes()
- logger.debug("SLABDRIVER.PY create_sliver slice %s " %(sfa_slice))
+ logger.debug("IOTLABDRIVER.PY create_sliver slice %s " %(sfa_slice))
# add/remove slice from nodes
#requested_slivers = [node.get('component_id') \
#for node in rspec.version.get_nodes_with_slivers()\
- #if node.get('authority_id') is self.slab_api.root_auth]
+ #if node.get('authority_id') is self.iotlab_api.root_auth]
#l = [ node for node in rspec.version.get_nodes_with_slivers() ]
#logger.debug("SLADRIVER \tcreate_sliver requested_slivers \
#requested_slivers %s listnodes %s" \
requested_job_dict = self._process_requested_jobs(rspec)
- logger.debug("SLABDRIVER.PY \tcreate_sliver requested_job_dict %s "\
+ logger.debug("IOTLABDRIVER.PY \tcreate_sliver requested_job_dict %s "\
%(requested_job_dict))
#verify_slice_leases returns the leases , but the return value is unused
#here. Removed SA 13/08/12
def delete_sliver (self, slice_urn, slice_hrn, creds, options):
"""
Deletes the lease associated with the slice hrn and the credentials
- if the slice belongs to senslab. Answer to DeleteSliver.
+ if the slice belongs to iotlab. Answer to DeleteSliver.
- :return: 1 if the slice to delete was not found on senslab,
+ :return: 1 if the slice to delete was not found on iotlab,
True if the deletion was successful, False otherwise otherwise.
- .. note:: Should really be named delete_leases because senslab does
+ .. note:: Should really be named delete_leases because iotlab does
not have any slivers, but only deals with leases. However, SFA api only
have delete_sliver define so far. SA 13.05/2013
"""
- sfa_slice_list = self.slab_api.GetSlices(slice_filter = slice_hrn, \
+ sfa_slice_list = self.iotlab_api.GetSlices(slice_filter = slice_hrn, \
slice_filter_type = 'slice_hrn')
if not sfa_slice_list:
for sfa_slice in sfa_slice_list:
- logger.debug("SLABDRIVER.PY delete_sliver slice %s" %(sfa_slice))
- slices = SlabSlices(self)
+ logger.debug("IOTLABDRIVER.PY delete_sliver slice %s" %(sfa_slice))
+ slices = IotlabSlices(self)
# determine if this is a peer slice
peer = slices.get_peer(slice_hrn)
- logger.debug("SLABDRIVER.PY delete_sliver peer %s \
+ logger.debug("IOTLABDRIVER.PY delete_sliver peer %s \
\r\n \t sfa_slice %s " %(peer, sfa_slice))
try:
- self.slab_api.DeleteSliceFromNodes(sfa_slice)
+ self.iotlab_api.DeleteSliceFromNodes(sfa_slice)
return True
except :
return False
def list_resources (self, slice_urn, slice_hrn, creds, options):
"""
- List resources from the senslab aggregate and returns a Rspec
+ List resources from the iotlab aggregate and returns a Rspec
advertisement with resources found when slice_urn and slice_hrn are None
(in case of resource discovery).
If a slice hrn and urn are provided, list experiment's slice
#if cached_requested and self.cache and not slice_hrn:
#rspec = self.cache.get(version_string)
#if rspec:
- #logger.debug("SlabDriver.ListResources: \
+ #logger.debug("IotlabDriver.ListResources: \
#returning cached advertisement")
#return rspec
#panos: passing user-defined options
- aggregate = SlabAggregate(self)
+ aggregate = IotlabAggregate(self)
rspec = aggregate.get_rspec(slice_xrn=slice_urn, \
version=rspec_version, options=options)
def list_slices (self, creds, options):
"""
Answer to ListSlices.
- List slices belonging to senslab, returns slice urns list.
+ List slices belonging to iotlab, returns slice urns list.
No caching used. Options unused but are defined in the SFA method
api prototype.
# get data from db
- slices = self.slab_api.GetSlices()
- logger.debug("SLABDRIVER.PY \tlist_slices hrn %s \r\n \r\n" %(slices))
- slice_hrns = [slab_slice['hrn'] for slab_slice in slices]
+ slices = self.iotlab_api.GetSlices()
+ logger.debug("IOTLABDRIVER.PY \tlist_slices hrn %s \r\n \r\n" %(slices))
+ slice_hrns = [iotlab_slice['hrn'] for iotlab_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")
+ #logger.debug ("IotlabDriver.list_slices stores value in cache")
#self.cache.add('slices', slice_urns)
return slice_urns
..warnings:: should not be used. Different components are in charge of
doing this task. Adding nodes = OAR
- Adding users = LDAP Senslab
+ Adding users = LDAP Iotlab
Adding slice = Import from LDAP users
Adding site = OAR
def update (self, old_sfa_record, new_sfa_record, hrn, new_key):
- """No site or node record update allowed in Senslab.
+ """No site or node record update allowed in Iotlab.
The only modifications authorized here are key deletion/addition
on an existing user and password change.
On an existing user, CAN NOT BE MODIFIED:
if new_key:
# must check this key against the previous one if it exists
- persons = self.slab_api.GetPersons([old_sfa_record])
+ persons = self.iotlab_api.GetPersons([old_sfa_record])
person = persons[0]
keys = [person['pkey']]
#Get all the person's keys
- keys_dict = self.slab_api.GetKeys(keys)
+ keys_dict = self.iotlab_api.GetKeys(keys)
# Delete all stale keys, meaning the user has only one key
#at a time
else:
#remove all the other keys
for key in keys_dict:
- self.slab_api.DeleteKey(person, key)
- self.slab_api.AddPersonKey(person, \
+ self.iotlab_api.DeleteKey(person, key)
+ self.iotlab_api.AddPersonKey(person, \
{'sshPublicKey': person['pkey']},{'sshPublicKey': new_key} )
- #self.slab_api.AddPersonKey(person, {'key_type': 'ssh', \
+ #self.iotlab_api.AddPersonKey(person, {'key_type': 'ssh', \
#'key': new_key})
return True
hrn = sfa_record['hrn']
if sfa_record_type == 'user':
- #get user from senslab ldap
- person = self.slab_api.GetPersons(sfa_record)
- #No registering at a given site in Senslab.
- #Once registered to the LDAP, all senslab sites are
+ #get user from iotlab ldap
+ person = self.iotlab_api.GetPersons(sfa_record)
+ #No registering at a given site in Iotlab.
+ #Once registered to the LDAP, all iotlab sites are
#accesible.
if person :
#Mark account as disabled in ldap
- return self.slab_api.DeletePerson(sfa_record)
+ return self.iotlab_api.DeletePerson(sfa_record)
elif sfa_record_type == 'slice':
- if self.slab_api.GetSlices(slice_filter = hrn, \
+ if self.iotlab_api.GetSlices(slice_filter = hrn, \
slice_filter_type = 'slice_hrn'):
- ret = self.slab_api.DeleteSlice(sfa_record)
+ ret = self.iotlab_api.DeleteSlice(sfa_record)
CASCADE ON UPDATE CASCADE','oar_job_id':'integer DEFAULT -1', \
'record_id_slice':'integer', 'slice_hrn':'text NOT NULL'}
-#Dict with all the specific senslab tables
-tablenames_dict = {'slab_xp': slice_table}
+#Dict with all the specific iotlab tables
+tablenames_dict = {'iotlab_xp': slice_table}
-SlabBase = declarative_base()
+IotlabBase = declarative_base()
-
-class SenslabXP (SlabBase):
- """ SQL alchemy class to manipulate slice_senslab table in
- slab_sfa database.
-
+
+class IotlabXP (IotlabBase):
+ """ SQL alchemy class to manipulate slice_iotlab table in
+ iotlab_sfa database.
+
"""
- __tablename__ = 'slab_xp'
+ __tablename__ = 'iotlab_xp'
slice_hrn = Column(String)
#oar_job_id = Column( Integer,default = -1)
#node_list = Column(postgresql.ARRAY(String), nullable =True)
-
+
def __init__ (self, slice_hrn =None, job_id=None, end_time=None):
"""
- Defines a row of the slice_senslab table
+ Defines a row of the slice_iotlab table
"""
if slice_hrn:
self.slice_hrn = slice_hrn
self.job_id = job_id
if end_time:
self.end_time = end_time
-
-
+
+
def __repr__(self):
"""Prints the SQLAlchemy record to the format defined
by the function.
"""
- result = "<slab_xp : slice_hrn = %s , job_id %s end_time = %s" \
+ result = "<iotlab_xp : slice_hrn = %s , job_id %s end_time = %s" \
%(self.slice_hrn, self.job_id, self.end_time)
result += ">"
return result
-
-
-
-class SlabDB:
+
+
+
+class IotlabDB:
""" SQL Alchemy connection class.
From alchemy.py
"""
def __init__(self, config, debug = False):
- self.sl_base = SlabBase
- dbname = "slab_sfa"
+ self.sl_base = IotlabBase
+ dbname = "iotlab_sfa"
if debug == True :
l_echo_pool = True
- l_echo = True
+ l_echo = True
else :
l_echo_pool = False
- l_echo = False
+ l_echo = False
- self.slab_session = None
+ self.iotlab_session = None
# the former PostgreSQL.py used the psycopg2 directly and was doing
#self.connection.set_client_encoding("UNICODE")
- # it's unclear how to achieve this in sqlalchemy, nor if it's needed
+ # it's unclear how to achieve this in sqlalchemy, nor if it's needed
# at all
# http://www.sqlalchemy.org/docs/dialects/postgresql.html#unicode
# we indeed have /var/lib/pgsql/data/postgresql.conf where
config.SFA_DB_PORT, dbname)
for url in [ unix_url, tcp_url ] :
try:
- self.slab_engine = create_engine (url, echo_pool = \
+ self.iotlab_engine = create_engine (url, echo_pool = \
l_echo_pool, echo = l_echo)
self.check()
self.url = url
return
except:
pass
- self.slab_engine = None
+ self.iotlab_engine = None
raise Exception, "Could not connect to database"
-
-
-
+
+
+
def check (self):
""" Cehck if a table exists by trying a selection
- on the table.
-
+ on the table.
+
"""
- self.slab_engine.execute ("select 1").scalar()
-
-
+ self.iotlab_engine.execute ("select 1").scalar()
+
+
def session (self):
"""
Creates a SQLalchemy session. Once the session object is created
- it should be used throughout the code for all the operations on
+ it should be used throughout the code for all the operations on
tables for this given database.
-
- """
- if self.slab_session is None:
+
+ """
+ if self.iotlab_session is None:
Session = sessionmaker()
- self.slab_session = Session(bind = self.slab_engine)
- return self.slab_session
-
- def close_session(self):
+ self.iotlab_session = Session(bind = self.iotlab_engine)
+ return self.iotlab_session
+
+ def close_session(self):
"""
- Closes connection to database.
-
+ Closes connection to database.
+
"""
- if self.slab_session is None: return
- self.slab_session.close()
- self.slab_session = None
-
+ if self.iotlab_session is None: return
+ self.iotlab_session.close()
+ self.iotlab_session = None
+
def exists(self, tablename):
"""
Checks if the table specified as tablename exists.
-
+
"""
-
+
try:
- metadata = MetaData (bind=self.slab_engine)
+ metadata = MetaData (bind=self.iotlab_engine)
table = Table (tablename, metadata, autoload=True)
return True
-
+
except NoSuchTableError:
logger.log_exc("SLABPOSTGRES tablename %s does not exists" \
%(tablename))
return False
-
-
+
+
def createtable(self):
"""
- Creates all the table sof the engine.
+ Creates all the table sof the engine.
Uses the global dictionnary holding the tablenames and the table schema.
-
+
"""
- logger.debug("SLABPOSTGRES createtable SlabBase.metadata.sorted_tables \
- %s \r\n engine %s" %(SlabBase.metadata.sorted_tables , slab_engine))
- SlabBase.metadata.create_all(slab_engine)
+ logger.debug("SLABPOSTGRES createtable IotlabBase.metadata.sorted_tables \
+ %s \r\n engine %s" %(IotlabBase.metadata.sorted_tables , iotlab_engine))
+ IotlabBase.metadata.create_all(iotlab_engine)
return
-
-slab_alchemy = SlabDB(Config())
-slab_engine = slab_alchemy.slab_engine
-slab_dbsession = slab_alchemy.session()
+
+iotlab_alchemy = IotlabDB(Config())
+iotlab_engine = iotlab_alchemy.iotlab_engine
+iotlab_dbsession = iotlab_alchemy.session()
MAXINT = 2L**31-1
-class SlabSlices:
+class IotlabSlices:
rspec_to_slice_tag = {'max_rate':'net_max_rate'}
-
-
+
+
def __init__(self, driver):
"""
Get the reference to the driver here.
"""
self.driver = driver
-
-
+
+
def get_peer(self, xrn):
"""
Find the authority of a resources based on its xrn.
- If the authority is Senslab (local) return None,
- Otherwise, look up in the DB if Senslab is federated with this site
- authority and returns its DB record if it is the case,
+ If the authority is Iotlab (local) return None,
+ Otherwise, look up in the DB if Iotlab is federated with this site
+ authority and returns its DB record if it is the case,
"""
hrn, hrn_type = urn_to_hrn(xrn)
- #Does this slice belong to a local site or a peer senslab site?
+ #Does this slice belong to a local site or a peer iotlab site?
peer = None
-
+
# get this slice's authority (site)
slice_authority = get_authority(hrn)
- #Senslab stuff
+ #Iotlab stuff
#This slice belongs to the current site
- if slice_authority == self.driver.slab_api.root_auth:
+ if slice_authority == self.driver.iotlab_api.root_auth:
site_authority = slice_authority
return None
-
+
site_authority = get_authority(slice_authority).lower()
# get this site's authority (sfa root authority or sub authority)
- logger.debug("SLABSLICES \ get_peer slice_authority %s \
+ logger.debug("IOTLABSLICES \ get_peer slice_authority %s \
site_authority %s hrn %s" %(slice_authority, \
site_authority, hrn))
-
-
+
+
# check if we are already peered with this site_authority
#if so find the peer record
- peers = self.driver.slab_api.GetPeers(peer_filter = site_authority)
+ peers = self.driver.iotlab_api.GetPeers(peer_filter = site_authority)
for peer_record in peers:
-
+
if site_authority == peer_record.hrn:
peer = peer_record
- logger.debug(" SLABSLICES \tget_peer peer %s " %(peer))
+ logger.debug(" IOTLABSLICES \tget_peer peer %s " %(peer))
return peer
def get_sfa_peer(self, xrn):
return sfa_peer
-
+
def verify_slice_leases(self, sfa_slice, requested_jobs_dict, peer):
- """
+ """
Compare requested leases with the leases already scheduled/
running in OAR. If necessary, delete and recreate modified leases,
- and delete no longer requested ones.
-
+ and delete no longer requested ones.
+
:param sfa_slice: sfa slice record
:param requested_jobs_dict: dictionary of requested leases
:param peer: sfa peer
-
+
:type sfa_slice: dict
- :type requested_jobs_dict: dict
+ :type requested_jobs_dict: dict
:type peer:
- :return: leases list of dictionary
+ :return: leases list of dictionary
:rtype: list
-
+
"""
- logger.debug("SLABSLICES verify_slice_leases sfa_slice %s \
+ logger.debug("IOTLABSLICES verify_slice_leases sfa_slice %s \
"%( sfa_slice))
- #First get the list of current leases from OAR
- leases = self.driver.slab_api.GetLeases({'name':sfa_slice['hrn']})
- logger.debug("SLABSLICES verify_slice_leases requested_jobs_dict %s \
+ #First get the list of current leases from OAR
+ leases = self.driver.iotlab_api.GetLeases({'name':sfa_slice['hrn']})
+ logger.debug("IOTLABSLICES verify_slice_leases requested_jobs_dict %s \
leases %s "%(requested_jobs_dict, leases ))
-
+
current_nodes_reserved_by_start_time = {}
requested_nodes_by_start_time = {}
leases_by_start_time = {}
reschedule_jobs_dict = {}
-
- #Create reduced dictionary with key start_time and value
+
+ #Create reduced dictionary with key start_time and value
# the list of nodes
#-for the leases already registered by OAR first
# then for the new leases requested by the user
-
+
#Leases already scheduled/running in OAR
for lease in leases :
current_nodes_reserved_by_start_time[lease['t_from']] = \
lease['reserved_nodes']
leases_by_start_time[lease['t_from']] = lease
-
+
#First remove job whose duration is too short
for job in requested_jobs_dict.values():
- if job['duration'] < self.driver.slab_api.GetLeaseGranularity():
+ if job['duration'] < self.driver.iotlab_api.GetLeaseGranularity():
del requested_jobs_dict[job['start_time']]
-
- #Requested jobs
+
+ #Requested jobs
for start_time in requested_jobs_dict:
requested_nodes_by_start_time[int(start_time)] = \
- requested_jobs_dict[start_time]['hostname']
+ requested_jobs_dict[start_time]['hostname']
#Check if there is any difference between the leases already
- #registered in OAR and the requested jobs.
+ #registered in OAR and the requested jobs.
#Difference could be:
#-Lease deleted in the requested jobs
#-Added/removed nodes
- #-Newly added lease
+ #-Newly added lease
- logger.debug("SLABSLICES verify_slice_leases \
+ logger.debug("IOTLABSLICES verify_slice_leases \
requested_nodes_by_start_time %s \
"%(requested_nodes_by_start_time ))
#Find all deleted leases
for start_time in start_time_list]
-
+
#Find added or removed nodes in exisiting leases
- for start_time in requested_nodes_by_start_time:
- logger.debug("SLABSLICES verify_slice_leases start_time %s \
+ for start_time in requested_nodes_by_start_time:
+ logger.debug("IOTLABSLICES verify_slice_leases start_time %s \
"%( start_time))
if start_time in current_nodes_reserved_by_start_time:
-
+
if requested_nodes_by_start_time[start_time] == \
current_nodes_reserved_by_start_time[start_time]:
continue
-
+
else:
update_node_set = \
set(requested_nodes_by_start_time[start_time])
removed_nodes = \
old_nodes_set.difference(\
requested_nodes_by_start_time[start_time])
- logger.debug("SLABSLICES verify_slice_leases \
+ logger.debug("IOTLABSLICES verify_slice_leases \
shared_nodes %s added_nodes %s removed_nodes %s"\
%(shared_nodes, added_nodes,removed_nodes ))
- #If the lease is modified, delete it before
+ #If the lease is modified, delete it before
#creating it again.
#Add the deleted lease job id in the list
- #WARNING :rescheduling does not work if there is already
- # 2 running/scheduled jobs because deleting a job
+ #WARNING :rescheduling does not work if there is already
+ # 2 running/scheduled jobs because deleting a job
#takes time SA 18/10/2012
if added_nodes or removed_nodes:
deleted_leases.append(\
leases_by_start_time[start_time]['lease_id'])
- #Reschedule the job
+ #Reschedule the job
if added_nodes or shared_nodes:
reschedule_jobs_dict[str(start_time)] = \
requested_jobs_dict[str(start_time)]
- else:
+ else:
#New lease
-
+
job = requested_jobs_dict[str(start_time)]
- logger.debug("SLABSLICES \
+ logger.debug("IOTLABSLICES \
NEWLEASE slice %s job %s"\
- %(sfa_slice, job))
- self.driver.slab_api.AddLeases(job['hostname'], \
+ %(sfa_slice, job))
+ self.driver.iotlab_api.AddLeases(job['hostname'], \
sfa_slice, int(job['start_time']), \
int(job['duration']))
#Deleted leases are the ones with lease id not declared in the Rspec
if deleted_leases:
- self.driver.slab_api.DeleteLeases(deleted_leases, sfa_slice['hrn'])
- logger.debug("SLABSLICES \
+ self.driver.iotlab_api.DeleteLeases(deleted_leases, sfa_slice['hrn'])
+ logger.debug("IOTLABSLICES \
verify_slice_leases slice %s deleted_leases %s"\
%(sfa_slice, deleted_leases))
-
-
- if reschedule_jobs_dict :
+
+
+ if reschedule_jobs_dict :
for start_time in reschedule_jobs_dict:
job = reschedule_jobs_dict[start_time]
- self.driver.slab_api.AddLeases(job['hostname'], \
+ self.driver.iotlab_api.AddLeases(job['hostname'], \
sfa_slice, int(job['start_time']), \
int(job['duration']))
return leases
deleted_nodes = []
if 'node_ids' in sfa_slice:
- nodes = self.driver.slab_api.GetNodes(sfa_slice['list_node_ids'], \
+ nodes = self.driver.iotlab_api.GetNodes(sfa_slice['list_node_ids'], \
['hostname'])
current_slivers = [node['hostname'] for node in nodes]
-
+
# remove nodes not in rspec
deleted_nodes = list(set(current_slivers).\
difference(requested_slivers))
#difference(current_slivers))
- logger.debug("SLABSLICES \tverify_slice_nodes slice %s\
+ logger.debug("IOTLABSLICES \tverify_slice_nodes slice %s\
\r\n \r\n deleted_nodes %s"\
%(sfa_slice, deleted_nodes))
if deleted_nodes:
#Delete the entire experience
- self.driver.slab_api.DeleteSliceFromNodes(sfa_slice)
+ self.driver.iotlab_api.DeleteSliceFromNodes(sfa_slice)
#self.driver.DeleteSliceFromNodes(sfa_slice['slice_hrn'], \
#deleted_nodes)
return nodes
-
+
def free_egre_key(self):
used = set()
- for tag in self.driver.slab_api.GetSliceTags({'tagname': 'egre_key'}):
+ for tag in self.driver.iotlab_api.GetSliceTags({'tagname': 'egre_key'}):
used.add(int(tag['value']))
for i in range(1, 256):
return str(key)
-
-
-
-
+
+
+
+
def verify_slice(self, slice_hrn, slice_record, peer, sfa_peer):
#login_base = slice_hrn.split(".")[0]
slicename = slice_hrn
- slices_list = self.driver.slab_api.GetSlices(slice_filter = slicename, \
- slice_filter_type = 'slice_hrn')
- sfa_slice = None
+ slices_list = self.driver.iotlab_api.GetSlices(slice_filter = slicename, \
+ slice_filter_type = 'slice_hrn')
+ sfa_slice = None
if slices_list:
for sl in slices_list:
-
+
logger.debug("SLABSLICE \tverify_slice slicename %s \
slices_list %s sl %s \ slice_record %s"\
%(slicename, slices_list,sl, \
slice_record))
sfa_slice = sl
sfa_slice.update(slice_record)
-
+
else:
#Search for user in ldap based on email SA 14/11/12
- ldap_user = self.driver.slab_api.ldap.LdapFindUser(\
+ ldap_user = self.driver.iotlab_api.ldap.LdapFindUser(\
slice_record['user'])
- logger.debug(" SLABSLICES \tverify_slice Oups \
+ logger.debug(" IOTLABSLICES \tverify_slice Oups \
slice_record %s sfa_peer %s ldap_user %s"\
%(slice_record, sfa_peer, ldap_user ))
#User already registered in ldap, meaning user should be in SFA db
- #and hrn = sfa_auth+ uid
+ #and hrn = sfa_auth+ uid
sfa_slice = {'hrn': slicename,
- #'url': slice_record.get('url', slice_hrn),
+ #'url': slice_record.get('url', slice_hrn),
#'description': slice_record.get('description', slice_hrn)
'node_list' : [],
'authority' : slice_record['authority'],
'reg-researchers':slice_record['reg-researchers'],
#'record_id_slice': slice_record['record_id'],
'peer_authority':str(sfa_peer)
-
- }
- if ldap_user :
- hrn = self.driver.slab_api.root_auth +'.'+ ldap_user['uid']
-
+
+ }
+ if ldap_user :
+ hrn = self.driver.iotlab_api.root_auth +'.'+ ldap_user['uid']
+
user = self.driver.get_user_record(hrn)
-
- logger.debug(" SLABSLICES \tverify_slice hrn %s USER %s" \
+
+ logger.debug(" IOTLABSLICES \tverify_slice hrn %s USER %s" \
%(hrn, user))
#sfa_slice = {'slice_hrn': slicename,
- ##'url': slice_record.get('url', slice_hrn),
+ ##'url': slice_record.get('url', slice_hrn),
##'description': slice_record.get('description', slice_hrn)
#'node_list' : [],
#'authority' : slice_record['authority'],
#'reg-researchers':slice_record['reg-researchers'],
##'record_id_slice': slice_record['record_id'],
#'peer_authority':str(peer.hrn)
-
+
#}
- # add the slice
+ # add the slice
if sfa_slice :
- self.driver.slab_api.AddSlice(sfa_slice, user)
-
+ self.driver.iotlab_api.AddSlice(sfa_slice, user)
+
if peer:
sfa_slice['slice_id'] = slice_record['record_id']
-
- #slice['slice_id'] = self.driver.slab_api.AddSlice(slice)
- logger.debug("SLABSLICES \tverify_slice ADDSLICE OK")
+
+ #slice['slice_id'] = self.driver.iotlab_api.AddSlice(slice)
+ logger.debug("IOTLABSLICES \tverify_slice ADDSLICE OK")
#slice['node_ids']=[]
#slice['person_ids'] = []
#if peer:
#sfa_slice['peer_slice_id'] = slice_record.get('slice_id', None)
# mark this slice as an sfa peer record
#if sfa_peer:
- #peer_dict = {'type': 'slice', 'hrn': slice_hrn,
+ #peer_dict = {'type': 'slice', 'hrn': slice_hrn,
#'peer_authority': sfa_peer, 'pointer': \
#slice['slice_id']}
#self.registry.register_peer_object(self.credential, peer_dict)
-
-
+
+
return sfa_slice
def verify_persons(self, slice_hrn, slice_record, users, peer, sfa_peer, \
options={}):
- """
- users is a record list. Records can either be local records
- or users records from known and trusted federated sites.
- If the user is from another site that senslab doesn't trust yet,
- then Resolve will raise an error before getting to create_sliver.
"""
- #TODO SA 21/08/12 verify_persons Needs review
-
- logger.debug("SLABSLICES \tverify_persons \tslice_hrn %s \
+ users is a record list. Records can either be local records
+ or users records from known and trusted federated sites.
+ If the user is from another site that iotlab doesn't trust yet,
+ then Resolve will raise an error before getting to create_sliver.
+ """
+ #TODO SA 21/08/12 verify_persons Needs review
+
+ logger.debug("IOTLABSLICES \tverify_persons \tslice_hrn %s \
\t slice_record %s\r\n users %s \t peer %s "\
- %( slice_hrn, slice_record, users, peer))
- users_by_id = {}
- #users_by_hrn = {}
+ %( slice_hrn, slice_record, users, peer))
+ users_by_id = {}
+ #users_by_hrn = {}
users_by_email = {}
#users_dict : dict whose keys can either be the user's hrn or its id.
- #Values contains only id and hrn
+ #Values contains only id and hrn
users_dict = {}
-
+
#First create dicts by hrn and id for each user in the user record list:
for info in users:
-
+
if 'slice_record' in info :
- slice_rec = info['slice_record']
+ slice_rec = info['slice_record']
user = slice_rec['user']
- if 'email' in user:
+ if 'email' in user:
users_by_email[user['email']] = user
users_dict[user['email']] = user
-
+
#if 'hrn' in user:
#users_by_hrn[user['hrn']] = user
#users_dict[user['hrn']] = user
-
+
logger.debug( "SLABSLICE.PY \t verify_person \
users_dict %s \r\n user_by_email %s \r\n \
\tusers_by_id %s " \
%(users_dict,users_by_email, users_by_id))
-
+
existing_user_ids = []
#existing_user_hrns = []
existing_user_emails = []
existing_users = []
- # Check if user is in Senslab LDAP using its hrn.
- # Assuming Senslab is centralised : one LDAP for all sites,
+ # Check if user is in Iotlab LDAP using its hrn.
+ # Assuming Iotlab is centralised : one LDAP for all sites,
# user'as record_id unknown from LDAP
# LDAP does not provide users id, therefore we rely on hrns containing
# the login of the user.
- # If the hrn is not a senslab hrn, the user may not be in LDAP.
+ # If the hrn is not a iotlab hrn, the user may not be in LDAP.
if users_by_email :
#Construct the list of filters (list of dicts) for GetPersons
for email in users_by_email :
filter_user.append (users_by_email[email])
#Check user's in LDAP with GetPersons
- #Needed because what if the user has been deleted in LDAP but
+ #Needed because what if the user has been deleted in LDAP but
#is still in SFA?
- existing_users = self.driver.slab_api.GetPersons(filter_user)
+ existing_users = self.driver.iotlab_api.GetPersons(filter_user)
logger.debug(" \r\n SLABSLICE.PY \tverify_person filter_user \
%s existing_users %s " \
%(filter_user, existing_users))
- #User's in senslab LDAP
+ #User's in iotlab LDAP
if existing_users:
for user in existing_users :
users_dict[user['email']].update(user)
existing_user_emails.append(\
users_dict[user['email']]['email'])
-
-
- # User from another known trusted federated site. Check
- # if a senslab account matching the email has already been created.
- else:
+
+
+ # User from another known trusted federated site. Check
+ # if a iotlab account matching the email has already been created.
+ else:
req = 'mail='
if isinstance(users, list):
-
- req += users[0]['email']
+
+ req += users[0]['email']
else:
req += users['email']
-
- ldap_reslt = self.driver.slab_api.ldap.LdapSearch(req)
-
+
+ ldap_reslt = self.driver.iotlab_api.ldap.LdapSearch(req)
+
if ldap_reslt:
logger.debug(" SLABSLICE.PY \tverify_person users \
- USER already in Senslab \t ldap_reslt %s \
- "%( ldap_reslt))
+ USER already in Iotlab \t ldap_reslt %s \
+ "%( ldap_reslt))
existing_users.append(ldap_reslt[1])
-
+
else:
#User not existing in LDAP
#TODO SA 21/08/12 raise smthg to add user or add it auto ?
#new_record = {}
#new_record['pkey'] = users[0]['keys'][0]
#new_record['mail'] = users[0]['email']
-
+
logger.debug(" SLABSLICE.PY \tverify_person users \
not in ldap ...NEW ACCOUNT NEEDED %s \r\n \t \
ldap_reslt %s " %(users, ldap_reslt))
-
+
requested_user_emails = users_by_email.keys()
requested_user_hrns = \
[users_by_email[user]['hrn'] for user in users_by_email]
logger.debug("SLABSLICE.PY \tverify_person \
- users_by_email %s " %( users_by_email))
+ users_by_email %s " %( users_by_email))
#logger.debug("SLABSLICE.PY \tverify_person \
- #user_by_hrn %s " %( users_by_hrn))
-
-
+ #user_by_hrn %s " %( users_by_hrn))
+
+
#Check that the user of the slice in the slice record
- #matches one of the existing users
+ #matches one of the existing users
try:
if slice_record['PI'][0] in requested_user_hrns:
#if slice_record['record_id_user'] in requested_user_ids and \
#slice_record['PI'][0] in requested_user_hrns:
logger.debug(" SLABSLICE \tverify_person ['PI']\
slice_record %s" %(slice_record))
-
+
except KeyError:
pass
-
-
+
+
# users to be added, removed or updated
- #One user in one senslab slice : there should be no need
+ #One user in one iotlab slice : there should be no need
#to remove/ add any user from/to a slice.
- #However a user from SFA which is not registered in Senslab yet
+ #However a user from SFA which is not registered in Iotlab yet
#should be added to the LDAP.
added_user_emails = set(requested_user_emails).\
difference(set(existing_user_emails))
-
+
#self.verify_keys(existing_slice_users, updated_users_list, \
#peer, append)
added_persons = []
# add new users
-
+
#requested_user_email is in existing_user_emails
if len(added_user_emails) == 0:
-
+
slice_record['login'] = users_dict[requested_user_emails[0]]['uid']
logger.debug(" SLABSLICE \tverify_person QUICK DIRTY %s" \
%(slice_record))
-
-
+
+
for added_user_email in added_user_emails:
- #hrn, type = urn_to_hrn(added_user['urn'])
+ #hrn, type = urn_to_hrn(added_user['urn'])
added_user = users_dict[added_user_email]
logger.debug(" SLABSLICE \r\n \r\n \t THE SECOND verify_person \
added_user %s" %(added_user))
person['email'] = added_user['email']
person['key_ids'] = added_user.get('key_ids', [])
#person['urn'] = added_user['urn']
-
- #person['person_id'] = self.driver.slab_api.AddPerson(person)
- ret = self.driver.slab_api.AddPerson(person)
+
+ #person['person_id'] = self.driver.iotlab_api.AddPerson(person)
+ ret = self.driver.iotlab_api.AddPerson(person)
if type(ret) == int :
- person['uid'] = ret
-
+ person['uid'] = ret
+
logger.debug(" SLABSLICE \r\n \r\n \t THE SECOND verify_person\
personne %s" %(person))
#Update slice_Record with the id now known to LDAP
added_persons.append(person)
-
+
return added_persons
-
+
#Unused
def verify_keys(self, persons, users, peer, options={}):
- # existing keys
+ # existing keys
key_ids = []
for person in persons:
key_ids.extend(person['key_ids'])
- keylist = self.driver.slab_api.GetKeys(key_ids, ['key_id', 'key'])
-
+ keylist = self.driver.iotlab_api.GetKeys(key_ids, ['key_id', 'key'])
+
keydict = {}
for key in keylist:
- keydict[key['key']] = key['key_id']
+ keydict[key['key']] = key['key_id']
existing_keys = keydict.keys()
-
+
persondict = {}
for person in persons:
- persondict[person['email']] = person
-
+ persondict[person['email']] = person
+
# add new keys
requested_keys = []
updated_persons = []
#try:
##if peer:
#person = persondict[user['email']]
- #self.driver.slab_api.UnBindObjectFromPeer('person',
+ #self.driver.iotlab_api.UnBindObjectFromPeer('person',
#person['person_id'], peer['shortname'])
- ret = self.driver.slab_api.AddPersonKey(\
+ ret = self.driver.iotlab_api.AddPersonKey(\
user['email'], key)
#if peer:
#key_index = user_keys.index(key['key'])
#remote_key_id = user['key_ids'][key_index]
- #self.driver.slab_api.BindObjectToPeer('key', \
+ #self.driver.iotlab_api.BindObjectToPeer('key', \
#key['key_id'], peer['shortname'], \
#remote_key_id)
-
+
#finally:
#if peer:
- #self.driver.slab_api.BindObjectToPeer('person', \
+ #self.driver.iotlab_api.BindObjectToPeer('person', \
#person['person_id'], peer['shortname'], \
#user['person_id'])
-
+
# remove old keys (only if we are not appending)
append = options.get('append', True)
- if append == False:
+ if append == False:
removed_keys = set(existing_keys).difference(requested_keys)
for key in removed_keys:
#if peer:
- #self.driver.slab_api.UnBindObjectFromPeer('key', \
+ #self.driver.iotlab_api.UnBindObjectFromPeer('key', \
#key, peer['shortname'])
user = users_by_key_string[key]
- self.driver.slab_api.DeleteKey(user, key)
-
+ self.driver.iotlab_api.DeleteKey(user, key)
+
return
-
\ No newline at end of file
-class Slabv1Lease:
+class Iotlabv1Lease:
@staticmethod
def add_leases(xml, leases):
-
+
network_elems = xml.xpath('//network')
if len(network_elems) > 0:
network_elem = network_elems[0]
network_elem = xml.add_element('network', name = network_urn)
else:
network_elem = xml
-
- lease_elems = []
+
+ lease_elems = []
for lease in leases:
lease['start_time'] = datetime_to_string(utcparse(lease['start_time']))
def get_leases(xml, filter={}):
xpath = '//lease%s | //default:lease%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter))
lease_elems = xml.xpath(xpath)
- return Slabv1Lease.get_lease_objs(lease_elems)
+ return Iotlabv1Lease.get_lease_objs(lease_elems)
@staticmethod
def get_lease_objs(lease_elems):
from sfa.rspecs.elements.hardware_type import HardwareType
from sfa.rspecs.elements.element import Element
from sfa.rspecs.elements.interface import Interface
-from sfa.rspecs.elements.versions.slabv1Sliver import Slabv1Sliver
+from sfa.rspecs.elements.versions.iotlabv1Sliver import Iotlabv1Sliver
from sfa.util.sfalogging import logger
+<<<<<<< HEAD:sfa/rspecs/elements/versions/slabv1Node.py
class SlabNode(NodeElement):
#First get the fields already defined in the class Node
fields = list(NodeElement.fields)
#Extend it with senslab's specific fields
+=======
+class IotlabNode(Node):
+ #First get the fields already defined in the class Node
+ fields = list(Node.fields)
+ #Extend it with iotlab's specific fields
+>>>>>>> 7cb1e78... Renaming Senslab into Iotlab.:sfa/rspecs/elements/versions/iotlabv1Node.py
fields.extend (['archi', 'radio', 'mobile','position'])
-
-class SlabPosition(Element):
+
+class IotlabPosition(Element):
fields = ['posx', 'posy','posz']
-
-class SlabLocation(Location):
+
+class IotlabLocation(Location):
fields = list(Location.fields)
fields.extend (['site'])
-
-class Slabv1Node:
-
+
+class Iotlabv1Node:
+
@staticmethod
def add_connection_information(xml, ldap_username, sites_set):
- """ Adds login and ssh connection info in the network item in
- the xml. Does not create the network element, therefore
+ """ Adds login and ssh connection info in the network item in
+ the xml. Does not create the network element, therefore
should be used after add_nodes, which creates the network item.
-
+
"""
logger.debug(" add_connection_information " )
#Get network item in the xml
- network_elems = xml.xpath('//network')
+ network_elems = xml.xpath('//network')
if len(network_elems) > 0:
network_elem = network_elems[0]
- slab_network_dict = {}
- slab_network_dict['login'] = ldap_username
-
- slab_network_dict['ssh'] = \
- ['ssh ' + ldap_username + '@'+site+'.senslab.info' \
+ iotlab_network_dict = {}
+ iotlab_network_dict['login'] = ldap_username
+
+ iotlab_network_dict['ssh'] = \
+ ['ssh ' + ldap_username + '@'+site+'.iotlab.info' \
for site in sites_set]
network_elem.set('ssh', \
- unicode(slab_network_dict['ssh']))
- network_elem.set('login', unicode( slab_network_dict['login']))
+ unicode(iotlab_network_dict['ssh']))
+ network_elem.set('login', unicode( iotlab_network_dict['login']))
+
-
@staticmethod
def add_nodes(xml, nodes):
#Add network item in the xml
name = Xrn(network_urn).get_hrn())
else:
network_elem = xml
-
- logger.debug("slabv1Node \t add_nodes nodes %s \r\n "%(nodes[0]))
+
+ logger.debug("iotlabv1Node \t add_nodes nodes %s \r\n "%(nodes[0]))
node_elems = []
#Then add nodes items to the network item in the xml
for node in nodes:
'boot_state', 'mobile']
node_elem = network_elem.add_instance('node', node, node_fields)
node_elems.append(node_elem)
-
+
#Set the attibutes of this node element
- for attribute in node:
+ for attribute in node:
# set component name
if attribute is 'component_id':
component_name = node['component_name']
node_elem.set('component_name', component_name)
-
- # set hardware types, extend fields to add Senslab's architecture
+
+ # set hardware types, extend fields to add Iotlab's architecture
#and radio type
-
+
if attribute is 'hardware_types':
- for hardware_type in node.get('hardware_types', []):
+ for hardware_type in node.get('hardware_types', []):
fields = HardwareType.fields
fields.extend(['archi','radio'])
node_elem.add_instance('hardware_types', node, fields)
# set location
if attribute is 'location':
node_elem.add_instance('location', node['location'], \
- SlabLocation.fields)
+ IotlabLocation.fields)
# add granularity of the reservation system
#TODO put the granularity in network instead SA 18/07/12
if attribute is 'granularity' :
if granularity:
node_elem.add_instance('granularity', \
granularity, granularity.fields)
-
-
+
+
# set available element
if attribute is 'boot_state':
if node.get('boot_state').lower() == 'alive':
available_elem = node_elem.add_element('available', \
now='false')
- #set position
+ #set position
if attribute is 'position':
node_elem.add_instance('position', node['position'], \
- SlabPosition.fields)
+ IotlabPosition.fields)
## add services
- #PGv2Services.add_services(node_elem, node.get('services', []))
+ #PGv2Services.add_services(node_elem, node.get('services', []))
# add slivers
if attribute is 'slivers':
slivers = node.get('slivers', [])
if not slivers:
# we must still advertise the available sliver types
- slivers = Sliver({'type': 'slab-node'})
+ slivers = Sliver({'type': 'iotlab-node'})
# we must also advertise the available initscripts
#slivers['tags'] = []
- #if node.get('pl_initscripts'):
+ #if node.get('pl_initscripts'):
#for initscript in node.get('pl_initscripts', []):
#slivers['tags'].append({'name': 'initscript', \
#'value': initscript['name']})
-
- Slabv1Sliver.add_slivers(node_elem, slivers)
+
+ Iotlabv1Sliver.add_slivers(node_elem, slivers)
return node_elems
-
-
+
+
@staticmethod
def get_nodes(xml, filter={}):
xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), \
XpathFilter.xpath(filter))
- node_elems = xml.xpath(xpath)
- return Slabv1Node.get_node_objs(node_elems)
+ node_elems = xml.xpath(xpath)
+ return Iotlabv1Node.get_node_objs(node_elems)
- @staticmethod
+ @staticmethod
def get_nodes_with_slivers(xml, sliver_filter={}):
xpath = '//node[count(sliver)>0] | \
- //default:node[count(default:sliver) > 0]'
- node_elems = xml.xpath(xpath)
+ //default:node[count(default:sliver) > 0]'
+ node_elems = xml.xpath(xpath)
logger.debug("SLABV1NODE \tget_nodes_with_slivers \
node_elems %s"%(node_elems))
- return Slabv1Node.get_node_objs(node_elems)
+ return Iotlabv1Node.get_node_objs(node_elems)
@staticmethod
def get_node_objs(node_elems):
nodes = []
for node_elem in node_elems:
+<<<<<<< HEAD:sfa/rspecs/elements/versions/slabv1Node.py
node = NodeElement(node_elem.attrib, node_elem)
nodes.append(node)
+=======
+ node = Node(node_elem.attrib, node_elem)
+ nodes.append(node)
+>>>>>>> 7cb1e78... Renaming Senslab into Iotlab.:sfa/rspecs/elements/versions/iotlabv1Node.py
if 'component_id' in node_elem.attrib:
node['authority_id'] = \
Xrn(node_elem.attrib['component_id']).get_authority_urn()
-
+
# get hardware types
hardware_type_elems = node_elem.xpath('./default:hardware_type | \
./hardware_type')
node['hardware_types'] = [hw_type.get_instance(HardwareType) \
for hw_type in hardware_type_elems]
-
+
# get location
location_elems = node_elem.xpath('./default:location | ./location')
locations = [location_elem.get_instance(Location) \
for location_elem in location_elems]
if len(locations) > 0:
node['location'] = locations[0]
-
-
+
+
# get interfaces
iface_elems = node_elem.xpath('./default:interface | ./interface')
node['interfaces'] = [iface_elem.get_instance(Interface) \
#node['services'] = PGv2Services.get_services(node_elem)
# get slivers
- node['slivers'] = Slabv1Sliver.get_slivers(node_elem)
+ node['slivers'] = Iotlabv1Sliver.get_slivers(node_elem)
available_elems = node_elem.xpath('./default:available | \
./available')
if len(available_elems) > 0 and 'name' in available_elems[0].attrib:
- if available_elems[0].attrib.get('now', '').lower() == 'true':
+ if available_elems[0].attrib.get('now', '').lower() == 'true':
node['boot_state'] = 'boot'
- else:
- node['boot_state'] = 'disabled'
-
+ else:
+ node['boot_state'] = 'disabled'
+
logger.debug("SLABV1NODE \tget_nodes_objs \
#nodes %s"%(nodes))
return nodes
@staticmethod
def add_slivers(xml, slivers):
- logger.debug("SLABv1NODE \tadd_slivers ")
+ logger.debug("Iotlabv1NODE \tadd_slivers ")
component_ids = []
for sliver in slivers:
filter_sliver = {}
sliver = {}
elif 'component_id' in sliver and sliver['component_id']:
filter_sliver['component_id'] = '*%s*' % sliver['component_id']
- if not filter_sliver:
+ if not filter_sliver:
continue
- nodes = Slabv1Node.get_nodes(xml, filter_sliver)
+ nodes = Iotlabv1Node.get_nodes(xml, filter_sliver)
if not nodes:
continue
node = nodes[0]
- Slabv1Sliver.add_slivers(node, sliver)
+ Iotlabv1Sliver.add_slivers(node, sliver)
@staticmethod
def remove_slivers(xml, hostnames):
for hostname in hostnames:
- nodes = Slabv1Node.get_nodes(xml, \
+ nodes = Iotlabv1Node.get_nodes(xml, \
{'component_id': '*%s*' % hostname})
for node in nodes:
- slivers = Slabv1Sliver.get_slivers(node.element)
+ slivers = Iotlabv1Sliver.get_slivers(node.element)
for sliver in slivers:
- node.element.remove(sliver.element)
+ node.element.remove(sliver.element)
+
+
-
-
#from sfa.rspecs.elements.versions.pgv2DiskImage import PGv2DiskImage
import sys
-class Slabv1Sliver:
+class Iotlabv1Sliver:
@staticmethod
def add_slivers(xml, slivers):
if not slivers:
- return
+ return
if not isinstance(slivers, list):
slivers = [slivers]
- for sliver in slivers:
+ for sliver in slivers:
#sliver_elem = xml.add_element('sliver_type')
sliver_elem = xml.add_element('sliver')
if sliver.get('type'):
sliver_elem.set('client_id', sliver['client_id'])
#images = sliver.get('disk_images')
#if images and isinstance(images, list):
- #Slabv1DiskImage.add_images(sliver_elem, images)
- Slabv1Sliver.add_sliver_attributes(sliver_elem, sliver.get('tags', []))
-
+ #Iotlabv1DiskImage.add_images(sliver_elem, images)
+ Iotlabv1Sliver.add_sliver_attributes(sliver_elem, sliver.get('tags', []))
+
@staticmethod
def add_sliver_attributes(xml, attributes):
- if attributes:
+ if attributes:
for attribute in attributes:
if attribute['name'] == 'initscript':
xml.add_element('{%s}initscript' % xml.namespaces['planetlab'], name=attribute['value'])
attrib_elem = xml.add_element('{%s}info' % self.namespaces['flack'])
attrib_dict = eval(tag['value'])
for (key, value) in attrib_dict.items():
- attrib_elem.set(key, value)
+ attrib_elem.set(key, value)
@staticmethod
def get_slivers(xml, filter={}):
xpath = './default:sliver | ./sliver'
-
+
sliver_elems = xml.xpath(xpath)
slivers = []
- for sliver_elem in sliver_elems:
+ for sliver_elem in sliver_elems:
sliver = Sliver(sliver_elem.attrib,sliver_elem)
- if 'component_id' in xml.attrib:
+ if 'component_id' in xml.attrib:
sliver['component_id'] = xml.attrib['component_id']
if 'name' in sliver_elem.attrib:
sliver['type'] = sliver_elem.attrib['name']
- #sliver['images'] = Slabv1DiskImage.get_images(sliver_elem)
-
+ #sliver['images'] = Iotlabv1DiskImage.get_images(sliver_elem)
+
print>>sys.stderr, "\r\n \r\n SLABV1SLIVER.PY \t\t\t get_slivers sliver %s " %( sliver)
slivers.append(sliver)
return slivers
@staticmethod
def get_sliver_attributes(xml, filter={}):
- return []
\ No newline at end of file
+ return []
\ No newline at end of file
from sfa.rspecs.version import RSpecVersion
import sys
-from sfa.rspecs.elements.versions.slabv1Lease import Slabv1Lease
-from sfa.rspecs.elements.versions.slabv1Node import Slabv1Node
-from sfa.rspecs.elements.versions.slabv1Sliver import Slabv1Sliver
+from sfa.rspecs.elements.versions.iotlabv1Lease import Iotlabv1Lease
+from sfa.rspecs.elements.versions.iotlabv1Node import Iotlabv1Node
+from sfa.rspecs.elements.versions.iotlabv1Sliver import Iotlabv1Sliver
from sfa.rspecs.elements.versions.sfav1Lease import SFAv1Lease
from sfa.util.sfalogging import logger
-
-class Slabv1(RSpecVersion):
+
+class Iotlabv1(RSpecVersion):
#enabled = True
type = 'Slab'
content_type = 'ad'
}
namespaces = dict(extensions.items() + [('default', namespace)])
elements = []
-
- # Network
+
+ # Network
def get_networks(self):
- #WARNING Added //default:network to the xpath
+ #WARNING Added //default:network to the xpath
#otherwise network element not detected 16/07/12 SA
-
- network_elems = self.xml.xpath('//network | //default:network')
+
+ network_elems = self.xml.xpath('//network | //default:network')
networks = [network_elem.get_instance(fields=['name', 'slice']) for \
network_elem in network_elems]
- return networks
+ return networks
def add_network(self, network):
network_tag = network_tags[0]
return network_tag
-
+
# Nodes
def get_nodes(self, filter=None):
- return Slabv1Node.get_nodes(self.xml, filter)
+ return Iotlabv1Node.get_nodes(self.xml, filter)
def get_nodes_with_slivers(self):
- return Slabv1Node.get_nodes_with_slivers(self.xml)
-
+ return Iotlabv1Node.get_nodes_with_slivers(self.xml)
+
def get_slice_timeslot(self ):
- return Slabv1Timeslot.get_slice_timeslot(self.xml)
-
+ return Iotlabv1Timeslot.get_slice_timeslot(self.xml)
+
def add_connection_information(self, ldap_username, sites_set):
- return Slabv1Node.add_connection_information(self.xml,ldap_username, sites_set)
-
+ return Iotlabv1Node.add_connection_information(self.xml,ldap_username, sites_set)
+
def add_nodes(self, nodes, check_for_dupes=False):
- return Slabv1Node.add_nodes(self.xml,nodes )
-
+ return Iotlabv1Node.add_nodes(self.xml,nodes )
+
def merge_node(self, source_node_tag, network, no_dupes = False):
logger.debug("SLABV1 merge_node")
#if no_dupes and self.get_node_element(node['hostname']):
network_tag.append(deepcopy(source_node_tag))
# Slivers
-
- def get_sliver_attributes(self, hostname, node, network=None):
+
+ def get_sliver_attributes(self, hostname, node, network=None):
print>>sys.stderr, "\r\n \r\n \r\n \t\t SLABV1.PY get_sliver_attributes hostname %s " %(hostname)
nodes = self.get_nodes({'component_id': '*%s*' %hostname})
- attribs = []
+ attribs = []
print>>sys.stderr, "\r\n \r\n \r\n \t\t SLABV1.PY get_sliver_attributes-----------------nodes %s " %(nodes)
if nodes is not None and isinstance(nodes, list) and len(nodes) > 0:
node = nodes[0]
- #if node :
+ #if node :
#sliver = node.xpath('./default:sliver | ./sliver')
#sliver = node.xpath('./default:sliver', namespaces=self.namespaces)
sliver = node['slivers']
-
+
if sliver is not None and isinstance(sliver, list) and len(sliver) > 0:
sliver = sliver[0]
attribs = sliver
return attribs
def get_slice_attributes(self, network=None):
-
+
slice_attributes = []
nodes_with_slivers = self.get_nodes_with_slivers()
value = text
attribute = {'name': 'initscript', 'value': value, 'node_id': node}
slice_attributes.append(attribute)
-
+
return slice_attributes
def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False):
# all nodes hould already be present in the rspec. Remove all
# nodes that done have slivers
- print>>sys.stderr, "\r\n \r\n \r\n \t\t\t SLABv1.PY add_slivers ----->get_node "
+ print>>sys.stderr, "\r\n \r\n \r\n \t\t\t Iotlabv1.PY add_slivers ----->get_node "
for hostname in hostnames:
node_elems = self.get_nodes({'component_id': '*%s*' % hostname})
if not node_elems:
continue
node_elem = node_elems[0]
-
+
# determine sliver types for this node
#TODO : add_slivers valid type of sliver needs to be changed 13/07/12 SA
- valid_sliver_types = ['slab-node', 'emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode']
+ valid_sliver_types = ['iotlab-node', 'emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode']
#valid_sliver_types = ['emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode']
requested_sliver_type = None
for sliver_type in node_elem.get('slivers', []):
if sliver_type.get('type') in valid_sliver_types:
requested_sliver_type = sliver_type['type']
-
+
if not requested_sliver_type:
continue
sliver = {'type': requested_sliver_type,
'pl_tags': attributes}
- print>>sys.stderr, "\r\n \r\n \r\n \t\t\t SLABv1.PY add_slivers node_elem %s sliver_type %s \r\n \r\n " %(node_elem, sliver_type)
+ print>>sys.stderr, "\r\n \r\n \r\n \t\t\t Iotlabv1.PY add_slivers node_elem %s sliver_type %s \r\n \r\n " %(node_elem, sliver_type)
# remove available element
for available_elem in node_elem.xpath('./default:available | ./available'):
node_elem.remove(available_elem)
-
+
# remove interface elements
for interface_elem in node_elem.xpath('./default:interface | ./interface'):
node_elem.remove(interface_elem)
-
+
# remove existing sliver_type elements
for sliver_type in node_elem.get('slivers', []):
node_elem.element.remove(sliver_type.element)
#node_elem.set('sliver_id', sliver_id)
# add the sliver type elemnt
- Slabv1Sliver.add_slivers(node_elem.element, sliver)
- #Slabv1SliverType.add_slivers(node_elem.element, sliver)
+ Iotlabv1Sliver.add_slivers(node_elem.element, sliver)
+ #Iotlabv1SliverType.add_slivers(node_elem.element, sliver)
# remove all nodes without slivers
if not append:
parent.remove(node_elem.element)
def remove_slivers(self, slivers, network=None, no_dupes=False):
- Slabv1Node.remove_slivers(self.xml, slivers)
-
-
+ Iotlabv1Node.remove_slivers(self.xml, slivers)
+
+
# Utility
-
+
def merge(self, in_rspec):
"""
Merge contents for specified rspec with current rspec
if not in_rspec:
return
-
+
from sfa.rspecs.rspec import RSpec
-
+
if isinstance(in_rspec, RSpec):
rspec = in_rspec
else:
rspec = RSpec(in_rspec)
# just copy over all networks
#Attention special get_networks using //default:network xpath
- current_networks = self.get_networks()
+ current_networks = self.get_networks()
networks = rspec.version.get_networks()
for network in networks:
current_network = network.get('name')
-
+
# Leases
def get_leases(self, lease_filter=None):
return SFAv1Lease.get_leases(self.xml, lease_filter)
- #return Slabv1Lease.get_leases(self.xml, lease_filter)
+ #return Iotlabv1Lease.get_leases(self.xml, lease_filter)
def add_leases(self, leases, network = None, no_dupes=False):
SFAv1Lease.add_leases(self.xml, leases)
- #Slabv1Lease.add_leases(self.xml, leases)
+ #Iotlabv1Lease.add_leases(self.xml, leases)
def cleanup(self):
# remove unncecessary elements, attributes
if self.type in ['request', 'manifest']:
# remove 'available' element from remaining node elements
self.xml.remove_element('//default:available | //available')
-
-
-class Slabv1Ad(Slabv1):
+
+
+class Iotlabv1Ad(Iotlabv1):
enabled = True
content_type = 'ad'
schema = 'http://senslab.info/resources/rspec/1/ad.xsd'
#http://www.geni.net/resources/rspec/3/ad.xsd'
template = '<rspec type="advertisement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/ad.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'
-class Slabv1Request(Slabv1):
+class Iotlabv1Request(Iotlabv1):
enabled = True
content_type = 'request'
schema = 'http://senslab.info/resources/rspec/1/request.xsd'
#http://www.geni.net/resources/rspec/3/request.xsd
template = '<rspec type="request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/request.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'
-class Slabv1Manifest(Slabv1):
+class Iotlabv1Manifest(Iotlabv1):
enabled = True
content_type = 'manifest'
schema = 'http://senslab.info/resources/rspec/1/manifest.xsd'
if __name__ == '__main__':
from sfa.rspecs.rspec import RSpec
from sfa.rspecs.rspec_elements import *
- r = RSpec('/tmp/slab.rspec')
- r.load_rspec_elements(Slabv1.elements)
- r.namespaces = Slabv1.namespaces
+ r = RSpec('/tmp/iotlab.rspec')
+ r.load_rspec_elements(Iotlabv1.elements)
+ r.namespaces = Iotlabv1.namespaces
print r.get(RSpecElements.NODE)
###########################################################################
-# Copyright (C) 2012 by
-# <savakian@sfa2.grenoble.senslab.info>
+# Copyright (C) 2012 by
+# <savakian@sfa2.grenoble.iotlab.info>
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################
-#LDAP import
-from sfa.senslab.LDAPapi import LDAPapi
+#LDAP import
+from sfa.iotlab.LDAPapi import LDAPapi
import ldap.modlist as modlist
#OAR imports
from datetime import datetime
-from sfa.senslab.OARrestapi import OARrestapi
+from sfa.iotlab.OARrestapi import OARrestapi
-#Test slabdriver
-from sfa.senslab.slabdriver import SlabDriver
+#Test iotlabdriver
+from sfa.iotlab.iotlabdriver import IotlabDriver
from sfa.util.config import Config
import sys
-
+
def parse_options():
-
+
#arguments supplied
if len(sys.argv) > 1 :
options_list = sys.argv[1:]
valid_options_dict = {}
value_list = []
#Passing options to the script should be done like this :
- #-10 OAR -2 SlabDriver
+ #-10 OAR -2 IotlabDriver
for option in options_list:
if option in supported_options:
- #update the values used for the fonctions associated
+ #update the values used for the fonctions associated
#with the options
-
+
valid_options_dict[option] = value_list
#empty the values list for next option
value_list = []
print "value_list", value_list
- return valid_options_dict
-
+ return valid_options_dict
+
def TestLdap(job_id = None):
logger.setLevelDebug()
ldap_server = LDAPapi()
ret = ldap_server.conn.connect(bind=True)
- ldap_server.conn.close()
+ ldap_server.conn.close()
print "TEST ldap_server.conn.connect(bind=True)" , ret
-
+
ret = ldap_server.conn.connect(bind=False)
ldap_server.conn.close()
print "TEST ldap_server.conn.connect(bind=False)", ret
ret = ldap_server.LdapSearch()
print "TEST ldap_server.LdapSearch ALL", ret
-
+
ret = ldap_server.LdapSearch('(uid=avakian)', [])
print "\r\n TEST ldap_server.LdapSearch ids = avakian", ret
password = ldap_server.generate_password()
- print "\r\n TEST generate_password ", password
-
+ print "\r\n TEST generate_password ", password
+
maxi = ldap_server.find_max_uidNumber()
print "\r\n TEST find_max_uidNumber " , maxi
data['first_name'] = "Tim"
data['givenName'] = data['first_name']
data['mail'] = "robin@arkham.fr"
-
+
record = {}
- record['hrn'] = 'senslab.drake'
+ record['hrn'] = 'iotlab.drake'
record['last_name'] = "Drake"
record['first_name'] = "Tim"
record['mail'] = "robin@arkham.fr"
-
-
+
+
login = ldap_server.generate_login(data)
print "\r\n Robin \tgenerate_login ", ret, login
-
+
ret = ldap_server.LdapAddUser(data)
print "\r\n Robin \tLdapAddUser ", ret
req_ldap = '(uid=' + login + ')'
ret = ldap_server.LdapSearch(req_ldap, [])
print "\r\n Robin \tldap_server.LdapSearch ids = %s %s" % (login, ret)
-
+
password = "Thridrobin"
enc = ldap_server.encrypt_password(password)
print "\r\n Robin \tencrypt_password ", enc
-
+
ret = ldap_server.LdapModifyUser(record, {'userPassword':enc})
print "\r\n Robin \tChange password LdapModifyUser ", ret
-
+
#dn = 'uid=' + login + ',' + ldap_server.baseDN
#ret = ldap_server.LdapDelete(dn)
#print "\r\n Robin \tLdapDelete ", ret
-
+
datanight = {}
datanight['last_name'] = "Grayson"
datanight['first_name'] = "Dick"
datanight['givenName'] = datanight['first_name']
datanight['mail'] = "nightwing@arkham.fr"
-
-
+
+
record_night = {}
- record_night['hrn'] = 'senslab.grayson'
+ record_night['hrn'] = 'iotlab.grayson'
record_night['last_name'] = datanight['last_name']
record_night['first_name'] = datanight['first_name']
record_night['mail'] = datanight['mail']
-
+
ret = ldap_server.LdapFindUser(record_night)
print "\r\n Nightwing \tldap_server.LdapFindUser %s : %s" % (record_night, ret)
-
+
#ret = ldap_server.LdapSearch('(uid=grayson)', [])
#print "\r\n Nightwing \tldap_server.LdapSearch ids = %s %s" %('grayson',ret )
#ret = ldap_server.LdapAddUser(datanight)
- #print "\r\n Nightwing \tLdapAddUser ", ret
-
+ #print "\r\n Nightwing \tLdapAddUser ", ret
+
#ret = ldap_server.LdapResetPassword(record_night)
#print "\r\n Nightwing \tLdapResetPassword de %s : %s" % (record_night, ret)
-
+
ret = ldap_server.LdapDeleteUser(record_night)
- print "\r\n Nightwing \tLdapDeleteUser ", ret
-
-
+ print "\r\n Nightwing \tLdapDeleteUser ", ret
+
+
#record_avakian = {}
- #record_avakian['hrn']= 'senslab.avakian'
+ #record_avakian['hrn']= 'iotlab.avakian'
#record_avakian['last_name'] = 'avakian'
#record_avakian['first_name'] = 'sandrine'
#record_avakian['mail'] = 'sandrine.avakian@inria.fr'
- #pubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwSUkJ+cr3xM47h8lFkIXJoJhg4wHakTaLJmgTXkzvUmQsQeFB2MjUZ6WAelMXj/EFz2+XkK+bcWNXwfbrLptJQ+XwGpPZlu9YV/kzO63ghVrAyEg0+p7Pn1TO9f1ZYg4R6JfP/3qwH1AsE+X3PNpIewsuEIKwd2wUCJDf5RXJTpl39GizcBFemrRqgs0bdqAN/vUT9YvtWn8fCYR5EfJHVXOK8P1KmnbuGZpk7ryz21pDMlgw13+8aYB+LPkxdv5zG54A5c6o9N3zOCblvRFWaNBqathS8y04cOYWPmyu+Q0Xccwi7vM3Ktm8RoJw+raQNwsmneJOm6KXKnjoOQeiQ== savakian@sfa2.grenoble.senslab.info"
+ #pubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwSUkJ+cr3xM47h8lFkIXJoJhg4wHakTaLJmgTXkzvUmQsQeFB2MjUZ6WAelMXj/EFz2+XkK+bcWNXwfbrLptJQ+XwGpPZlu9YV/kzO63ghVrAyEg0+p7Pn1TO9f1ZYg4R6JfP/3qwH1AsE+X3PNpIewsuEIKwd2wUCJDf5RXJTpl39GizcBFemrRqgs0bdqAN/vUT9YvtWn8fCYR5EfJHVXOK8P1KmnbuGZpk7ryz21pDMlgw13+8aYB+LPkxdv5zG54A5c6o9N3zOCblvRFWaNBqathS8y04cOYWPmyu+Q0Xccwi7vM3Ktm8RoJw+raQNwsmneJOm6KXKnjoOQeiQ== savakian@sfa2.grenoble.iotlab.info"
#ret = ldap_server.LdapModifyUser(record_night, {'sshPublicKey':pubkey})
- #print "\r\n Sandrine \tChange pubkey LdapModifyUser ", ret
-
+ #print "\r\n Sandrine \tChange pubkey LdapModifyUser ", ret
+
#record_myslice = {}
- #record_myslice['hrn']= 'senslab.myslice'
+ #record_myslice['hrn']= 'iotlab.myslice'
#record_myslice['last_name'] = 'myslice'
#record_myslice['first_name'] = 'myslice'
#record_myslice['mail'] = 'nturro@inria.fr'
#pubkeymyslice = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuyRPwn8PZxjdhu+ciRuPyM0eVBn7XS7i3tym9F30UVhaCd09a/UEmGn7WJZdfsxV3hXqG1Wc766FEst97NuzHzELSuvy/rT96J0UHG4wae4pnzOLd6NwFdZh7pkPsgHMHxK9ALVE68Puu+EDSOB5bBZ9Q624wCIGxEpmuS/+X+dDBTKgG5Hi0WA1uKJwhLSbbXb38auh4FlYgXPsdpljTIJatt+zGL0Zsy6fdrsVRc5W8kr3/SmE4OMNyabKBNyxioSEuYhRSjoQAHnYoevEjZniP8IzscKK7qwelzGUfnJEzexikhsQamhAFti2ReiFfoHBRZxnSc49ioH7Kaci5w== root@rhoecos3.ipv6.lip6.fr"
-
+
#pubkeytestuser = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYS8tzufciTm6GdNUGHQc64OfTxFebMYUwh/Jl04IPTvjjr26uakbM0M2v33HxZ5Q7PnmPN9pB/w+a+f7a7J4cNs/tApOMg2hb6UrLaOrdnDMOs4KZlfElyDsF3Zx5QwxPYvzsKADAbDVoX4NF9PttuDLdm2l3nLSvm89jfla00GBg+K8grdOCHyYZVX/Wt7kxhXDK3AidQhKJgn+iD5GxvtWMBE+7S5kJGdRW1W10lSLBW3+VNsCrKJB2s8L55Xz/l2HNBScU7T0VcMQJrFxEXKzLPagZsMz0lfLzHESoGHIZ3Tz85DfECbTtMxLts/4KoAEc3EE+PYr2VDeAggDx testuser@myslice"
-
-
+
+
#password = "ReptileFight"
#enc = ldap_server.encrypt_password(password)
#print "\r\n sandrine \tencrypt_password ", enc
-
+
#ret = ldap_server.LdapModifyUser(record_avakian, {'userPassword':enc})
- #print "\r\n sandrine \tChange password LdapModifyUser ", ret
+ #print "\r\n sandrine \tChange password LdapModifyUser ", ret
return
def get_stuff(oar, uri):
import httplib
- import json
+ import json
headers = {}
- data = json.dumps({})
-
- headers['X-REMOTE_IDENT'] = 'avakian'
-
+ data = json.dumps({})
+
+ headers['X-REMOTE_IDENT'] = 'avakian'
+
headers['content-length'] = '0' #seems that it does not work if we don't add this
-
+
conn = httplib.HTTPConnection(oar.oarserver['ip'], oar.oarserver['port'])
conn.request("GET", uri, data , headers )
resp = ( conn.getresponse()).read()
conn.close()
-
+
js = json.loads(resp)
return js
-
-
+
+
def TestOAR(job_id = None):
- print "JOB_ID", job_id
+ print "JOB_ID", job_id
if isinstance(job_id, list) :
if len(job_id) >= 1:
job_id = job_id[0]
else:
job_id = '1'
else:
- job_id = '1'
- print "JOB_ID", job_id
+ job_id = '1'
+ print "JOB_ID", job_id
oar = OARrestapi()
- jobs = oar.parser.SendRequest("GET_reserved_nodes", username = 'avakian')
+ jobs = oar.parser.SendRequest("GET_reserved_nodes", username = 'avakian')
print "\r\n OAR GET_reserved_nodes ", jobs
-
-
- jobs = oar.parser.SendRequest("GET_jobs")
+
+
+ jobs = oar.parser.SendRequest("GET_jobs")
print "\r\n OAR GET_jobs ", jobs
-
-
+
+
jobs = oar.parser.SendRequest("GET_jobs_id", job_id, 'avakian')
print "\r\n OAR GET_jobs_id ", jobs
-
- uri = '/oarapi/jobs/details.json?state=Running,Waiting,Launching&user=avakian'
+
+ uri = '/oarapi/jobs/details.json?state=Running,Waiting,Launching&user=avakian'
raw_json = get_stuff(oar, uri)
print "\r\nOAR ", uri, raw_json, "\r\n KKK \t", raw_json.keys()
-
+
uri = '/oarapi/jobs/' + job_id +'.json'
- raw_json = get_stuff(oar, uri)
+ raw_json = get_stuff(oar, uri)
print "\r\n OAR ", uri, raw_json, "\r\n KKK \t", raw_json.keys()
-
+
uri = '/oarapi/jobs/' + job_id + '/resources.json'
raw_json = get_stuff(oar, uri)
print "\r\n OAR ", uri, raw_json, "\r\n KKK \t", raw_json.keys()
-
+
time_format = "%Y-%m-%d %H:%M:%S"
-
+
server_timestamp, server_tz = oar.parser.SendRequest("GET_timezone")
-
+
print "\r\n OAR GetTimezone ", server_timestamp, server_tz
print(datetime.fromtimestamp(int(server_timestamp)).strftime('%Y-%m-%d %H:%M:%S'))
uri = '/oarapi/resources/full.json'
raw_json = get_stuff(oar, uri)
print "\r\n OAR ", uri, raw_json, "\r\n KKK \t", raw_json.keys()
-
- uri = '/oarapi/jobs.json?user=avakian'
+
+ uri = '/oarapi/jobs.json?user=avakian'
raw_json = get_stuff(oar, uri)
print "\r\nOAR ", uri, raw_json, "\r\n KKK \t", raw_json.keys()
return
-
-
-
-def TestSlabDriver(job_id = None):
+
+
+
+def TestIotlabDriver(job_id = None):
if job_id is None:
job_id = 1
-
+
if isinstance(job_id, list) and len(job_id) == 1:
job_id = job_id[0]
- slabdriver = SlabDriver(Config())
-
- #nodes = slabdriver.slab_api.GetReservedNodes()
+ iotlabdriver = IotlabDriver(Config())
+
+ #nodes = iotlabdriver.iotlab_api.GetReservedNodes()
#print " \r\n \r\n GetReservedNodes", nodes
-
- #sl = slabdriver.slab_api.GetSlices(slice_filter='senslab.avakian_slice', slice_filter_type='slice_hrn')
+
+ #sl = iotlabdriver.iotlab_api.GetSlices(slice_filter='iotlab.avakian_slice', slice_filter_type='slice_hrn')
#print "\r\n \r\nGetSlices", sl[0]
-
- #sl = slabdriver.slab_api.GetSlices(slice_filter='20', slice_filter_type='record_id_user')
+
+ #sl = iotlabdriver.iotlab_api.GetSlices(slice_filter='20', slice_filter_type='record_id_user')
#print "\r\n \r\nGetSlices", sl
-
- #sl = slabdriver.slab_api.GetSlices()
+
+ #sl = iotlabdriver.iotlab_api.GetSlices()
#print "\r\n \r\nGetSlices", sl
-
- persons = slabdriver.slab_api.GetPersons()
+
+ persons = iotlabdriver.iotlab_api.GetPersons()
print "\r\n \r\n GetPersons", persons
-
- leases = slabdriver.slab_api.GetLeases(login='avakian')
+
+ leases = iotlabdriver.iotlab_api.GetLeases(login='avakian')
print "\r\n \r\n GetLeases", leases
-
+
def TestSfi(filename = None):
if filename is None:
filename = "/home/savakian/flab-sfa/test_rspec/my_lyon_nodes.rspec"
print " ================= SFI.PY RESOURCES =============", \
- os.system("sfi.py list senslab")
-
+ os.system("sfi.py list iotlab")
+
print os.system("sfi.py resources")
- print os.system("sfi.py resources -r slab")
+ print os.system("sfi.py resources -r iotlab")
print os.system("sfi.py resources -l all")
-
-
+
+
print "================ SFI.PY RESOURCES -R SLAB -L ALL ============\r\n", \
- os.system("sfi.py resources -r slab -l all")
-
+ os.system("sfi.py resources -r iotlab -l all")
+
print "================ WRITING sfi.py resources -l all ===========\r\n", \
filename
-
+
filename = filename.split(".")[0]+"_out.rspec"
rspecfile = open(filename,"w")
- r = os.popen("sfi.py resources -l all")
+ r = os.popen("sfi.py resources -l all")
for i in r.readlines():
rspecfile.write(i)
rspecfile.close()
-
+
print " ================= SFI.PY SHOW SLICE ============= \r\n", \
- os.system("sfi.py resources senslab.avakian_slice")
-
+ os.system("sfi.py resources iotlab.avakian_slice")
+
print " ================= SFI.PY SHOW USER =============\r\n", \
- os.system("sfi.py show senslab.avakian_slice")
+ os.system("sfi.py show iotlab.avakian_slice")
print " ================= SFI.PY SHOW NODE =============\r\n", \
- os.system("sfi.py show senslab.avakian")
+ os.system("sfi.py show iotlab.avakian")
print " ================= SFI.PY SLICES =============\r\n", \
- os.system("sfi.py show senslab.node6.devlille.senslab.info")
+ os.system("sfi.py show iotlab.node6.devlille.iotlab.info")
print " ================= SFI.PY LIST SLICE =============\r\n", \
os.system("sfi.py slices")
print " ================= SFI.PY STATUS SLICE =============\r\n", \
- os.system("sfi.py status senslab.avakian_slice")
-
+ os.system("sfi.py status iotlab.avakian_slice")
+
print " ================= SFI.PY DELETE SLICE =============\r\n", \
- os.system("sfi.py delete senslab.avakian_slice")
-
+ os.system("sfi.py delete iotlab.avakian_slice")
+
print " ================= SFI.PY CREATE SLICE =============\r\n", \
- os.system("sfi.py create senslab.avakian_slice \
+ os.system("sfi.py create iotlab.avakian_slice \
/home/savakian/flab-sfa/test_rspec/my_lyon_nodes.rspec")
-
+
def TestSQL(arg = None):
from sfa.storage.model import make_record, RegSlice, RegRecord
from sfa.storage.alchemy import dbsession
- from sqlalchemy.orm.collections import InstrumentedList
-
- from sqlalchemy.orm import joinedload
-
- #solo_query_slice_list = dbsession.query(RegSlice).options(joinedload('reg_researchers')).filter_by(hrn='senslab.avakian_slice').first()
+ from sqlalchemy.orm.collections import InstrumentedList
+
+ from sqlalchemy.orm import joinedload
+
+ #solo_query_slice_list = dbsession.query(RegSlice).options(joinedload('reg_researchers')).filter_by(hrn='iotlab.avakian_slice').first()
#print "\r\n \r\n =========== query_slice_list RegSlice \
- #joinedload('reg_researchers') senslab.avakian first \r\n \t ", \
+ #joinedload('reg_researchers') iotlab.avakian first \r\n \t ", \
#solo_query_slice_list.__dict__
-
- #query_slice_list = dbsession.query(RegSlice).options(joinedload('reg_researchers')).all()
+
+ #query_slice_list = dbsession.query(RegSlice).options(joinedload('reg_researchers')).all()
#print "\r\n \r\n =========== query_slice_list RegSlice \
#joinedload('reg_researchers') ALL \r\n \t", \
- #query_slice_list[0].__dict__
-
+ #query_slice_list[0].__dict__
+
#return_slicerec_dictlist = []
#record = query_slice_list[0]
- #print "\r\n \r\n =========== \r\n \t", record
-
+ #print "\r\n \r\n =========== \r\n \t", record
+
#tmp = record.__dict__
- #print "\r\n \r\n =========== \r\n \t", tmp
+ #print "\r\n \r\n =========== \r\n \t", tmp
#tmp['reg_researchers'] = tmp['reg_researchers'][0].__dict__
- #print "\r\n \r\n =========== \r\n \t", tmp
+ #print "\r\n \r\n =========== \r\n \t", tmp
##del tmp['reg_researchers']['_sa_instance_state']
#return_slicerec_dictlist.append(tmp)
-
+
#print "\r\n \r\n =========== \r\n \t", return_slicerec_dictlist
-
+
all_records = dbsession.query(RegRecord).all()
-
- #create hash by (type,hrn)
- #used to know if a given record is already known to SFA
-
+
+ #create hash by (type,hrn)
+ #used to know if a given record is already known to SFA
+
records_by_type_hrn = \
dict ( [ ( (record.type,record.hrn) , record ) for record in all_records ] )
for (rec_type, rec) in records_by_type_hrn :
if rec_type == 'user':
- print >>sys.stderr,"\r\n SLABIMPORT \t keys %s rec %s \r\n" %(rec_type, rec )
-
+ print >>sys.stderr,"\r\n IOTLABIMPORT \t keys %s rec %s \r\n" %(rec_type, rec )
+
users_rec_by_email = \
dict ( [ (record.email, record) for record in all_records if record.type == 'user' ] )
-
-
+
+
def RunAll( arg ):
TestLdap()
TestOAR()
- TestSlabDriver()
+ TestIotlabDriver()
TestSfi()
-
-
+
+
supported_options = {
'OAR' : TestOAR,
'LDAP': TestLdap,
- 'driver': TestSlabDriver,
+ 'driver': TestIotlabDriver,
'sfi':TestSfi,
'sql':TestSQL,
'all' : RunAll }
-
+
def main():
opts = parse_options()
print opts
for opt in opts:
supported_options[opt](opts[opt])
-
+
if __name__ == "__main__":
- main()
\ No newline at end of file
+ main()
\ No newline at end of file
-#!/bin/bash
+#!/bin/bash
if (( ! $# == 2 ))
then
echo " Usage : bash_test takes 2 arguments : one jobid and one of the following:"
sfi.py resources
echo " ================= SFI.PY RESOURCES -R SLAB ============="
-sfi.py resources -r slab
+sfi.py resources -r iotlab
echo " ================= SFI.PY RESOURCES -L ALL ============="
sfi.py resources -l all
echo " ================= SFI.PY RESOURCES -R SLAB -L ALL ============="
-sfi.py resources -r slab -l all
+sfi.py resources -r iotlab -l all
echo " ================= SFI.PY RESOURCES -L ALL > avakian_adv.rspec ============="
sfi.py resources -l all > /home/savakian/flab-sfa/avakian_adv.rspec