From e09eeec50a96e492e5180de3256f832ff6c1353c Mon Sep 17 00:00:00 2001 From: Sandrine Avakian Date: Tue, 19 Nov 2013 10:37:13 +0100 Subject: [PATCH] Cleaning and documenting cortexlabdriver. --- sfa/cortexlab/cortexlabaggregate.py | 22 +++++------ sfa/cortexlab/cortexlabnodes.py | 59 ++++++++++++++++++----------- sfa/cortexlab/cortexlabshell.py | 4 +- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/sfa/cortexlab/cortexlabaggregate.py b/sfa/cortexlab/cortexlabaggregate.py index f58acc66..7cc1294d 100644 --- a/sfa/cortexlab/cortexlabaggregate.py +++ b/sfa/cortexlab/cortexlabaggregate.py @@ -68,14 +68,13 @@ class CortexlabAggregate: self.driver = driver def get_slice_and_slivers(self, slice_xrn, login=None): - """ + """Returns a dict of slivers based on the sliver's node_id. + Get the slices and the associated leases if any, from the cortexlab - testbed. One slice can have mutliple leases. - For each slice, get the nodes in the associated lease - and create a sliver with the necessary info and insert it into the - sliver dictionary, keyed on the node hostnames. - Returns a dict of slivers based on the sliver's node_id. - Called by get_rspec. + testbed. One slice can have mutliple leases. For each slice, get the + nodes in the associated lease and create a sliver with the necessary + info and insert it into the sliver dictionary, keyed on the node + hostnames.Called by get_rspec. :param slice_xrn: xrn of the slice @@ -279,13 +278,12 @@ class CortexlabAggregate: def get_all_leases(self, ldap_username): """ - - Get list of lease dictionaries which all have the mandatory keys - ('lease_id', 'hostname', 'site_id', 'name', 'start_time', 'duration'). - All the leases running or scheduled are returned. + Get list of lease dictionaries which all have the following + mandatory keys ('lease_id', 'hostname', 'site_id', 'name', 'start_time', + 'duration'). All the leases running or scheduled are returned. :param ldap_username: if ldap uid is not None, looks for the leases - belonging to this user. + belonging to this user. :type ldap_username: string :returns: rspec lease dictionary with keys lease_id, component_id, slice_id, start_time, duration. diff --git a/sfa/cortexlab/cortexlabnodes.py b/sfa/cortexlab/cortexlabnodes.py index 15ef6e62..d8bbae46 100644 --- a/sfa/cortexlab/cortexlabnodes.py +++ b/sfa/cortexlab/cortexlabnodes.py @@ -2,36 +2,39 @@ File used to handle all the nodes querying: - get nodes list along with their properties """ +from sfa.util.sfalogging import logger -class CortexlabQueryNodes: +class CortexlabQueryTestbed: def __init__(self): pass def get_all_nodes(self, node_filter_dict=None, return_fields_list=None): - """ - Get all the nodes and their properties. Called by GetNodes. + """Get all the nodes and their properties. Called by GetNodes. + Filtering on nodes properties can be done here or in GetNodes. - Search for specific nodes if some filters are - specified.Returns all the nodes properties if no return_fields_list - given. - TODO: Define which properties have to be listed here. Useful ones: - node architecture, radio type, position (x,y,z) + Search for specific nodes if some filters are specified. Returns all + the nodes properties if no return_fields_list given. + :param node_filter_dict: dictionary of lists with node properties. For - instance, if you want to look for a specific node with its hrn, - the node_filter_dict should be {'hrn': [hrn_of_the_node]} + instance, if you want to look for a specific node with its hrn, the + node_filter_dict should be {'hrn': [hrn_of_the_node]}. :type node_filter_dict: dict :param return_fields_list: list of specific fields the user wants to be returned. :type return_fields_list: list :returns: list of dictionaries with node properties :rtype: list + + TODO: Define which properties have to be listed here. Useful ones: + node architecture, radio type, position (x,y,z) """ node_dict_list = None # Get the nodes here, eventually filter here # See iotlabapi.py GetNodes to get the filtering (node_filter_dict and # return_fields_list ) part, if necessary + # Format example node_dict_list = [ {'hrn': 'iotlab.wsn430-11.devlille.iot-lab.info', 'archi': 'wsn430', 'mobile': 'True', @@ -69,6 +72,7 @@ class CortexlabQueryNodes: :param return_fields_list: fields that has to be returned :type site_filter_name_list: list :type return_fields_list: list + :rtype: list of dictionaries """ site_dict_list = None site_dict_list = [ @@ -88,47 +92,58 @@ class CortexlabQueryNodes: def get_reserved_nodes(self, username): - """Get list of leases. Get the leases for the username if specified, - otherwise get all the leases. + """Get list of leases. + + Get the leases for the username if specified, otherwise get all the + leases. + :param username: user's LDAP login :type username: string :returns: list of reservations dict - :rtype: dict list + :rtype: list of dictionaries """ reserved_nodes_list_dict = None + + reserved_nodes_list_dict = [{'lease_id': 1658, + 'reserved_nodes': [ 'wsn430-11.devlille.iot-lab.info'], 'state': + 'Waiting', 'user': 'avakian', 'resource_ids': [11], + 't_from': 1412938800, 't_until': 1412942640}] + return reserved_nodes_list_dict def schedule_experiment(self, lease_dict): """Schedule/ run an experiment based on the information provided in the lease dictionary. - :param lease_dict: contains lease_start_time, - lease_duration, added_nodes, slice_name , slice_user, grain: + :param lease_dict: contains lease_start_time, lease_duration, + added_nodes, slice_name , slice_user, grain: :type lease_dict: dictionary - + :rtype: dict """ answer = {} answer['id'] = None #experiment id answer['msg'] = None #message in case of error + + answer['id'] = 1659 + # Launch the experiment here return answer def delete_experiment(self, experiment_id, username): - """ - Delete the experiment designated by its experiment id and its - user. - TODO: If the username is not necessary to delete the lease, then you can - remove it from the parameters, given that you propagate the changes + """Delete the experiment designated by its experiment id and its user. :param experiment_id: experiment identifier - :type experiment_id : integer :param username: user's LDAP login + :type experiment_id: integer :type username: string :returns: dict with delete status {'status': True of False} :rtype: dict + + TODO: If the username is not necessary to delete the lease, then you can + remove it from the parameters, given that you propagate the changes """ # Delete the experiment here. Ret['status'] should be True or False # depending if the delete was effective or not. diff --git a/sfa/cortexlab/cortexlabshell.py b/sfa/cortexlab/cortexlabshell.py index 54c637a5..d68f6357 100644 --- a/sfa/cortexlab/cortexlabshell.py +++ b/sfa/cortexlab/cortexlabshell.py @@ -22,7 +22,7 @@ from sfa.trust.gid import create_uuid from sfa.trust.hierarchy import Hierarchy from sfa.iotlab.iotlabaggregate import iotlab_xrn_object -from sfa.cortexlab.cortexlabnodes import CortexlabQueryNodes +from sfa.cortexlab.cortexlabnodes import CortexlabQueryTestbed class CortexlabShell(): """ Class enabled to use LDAP and OAR api calls. """ @@ -39,7 +39,7 @@ class CortexlabShell(): :type config: Config object """ self.leases_db = TestbedAdditionalSfaDB(config) - self.query_sites = CortexlabQueryNodes() + self.query_sites = CortexlabQueryTestbed() self.ldap = LDAPapi() self.time_format = "%Y-%m-%d %H:%M:%S" self.root_auth = config.SFA_REGISTRY_ROOT_AUTH -- 2.43.0