Adding file to be completed by cortexlab testbed calls to get the nodes,
[sfa.git] / sfa / cortexlab / cortexlabnodes.py
1 """
2 File used to handle all the nodes querying:
3 - get nodes list along with their properties
4 """
5
6 class CortexlabQueryNodes:
7     def __init__(self):
8
9         pass
10
11     def get_all_nodes(self, node_filter_dict=None, return_fields_list=None):
12         """
13         Get all the nodes and their properties. Called by GetNodes.
14         Filtering on nodes properties can be done here or in GetNodes.
15         Search for specific nodes if some filters are
16         specified.Returns all the nodes properties if no return_fields_list
17         given.
18         TODO: Define which properties have to be listed here. Useful ones:
19         node architecture, radio type, position (x,y,z)
20
21         :param node_filter_dict: dictionary of lists with node properties. For
22             instance, if you want to look for a specific node with its hrn,
23             the node_filter_dict should be {'hrn': [hrn_of_the_node]}
24         :type node_filter_dict: dict
25         :param return_fields_list: list of specific fields the user wants to be
26             returned.
27         :type return_fields_list: list
28         :returns: list of dictionaries with node properties
29         :rtype: list
30         """
31         node_dict_list = None
32         # Get the nodes here, eventually filter here
33         # See iotlabapi.py GetNodes to get the filtering (node_filter_dict and
34         # return_fields_list ) part, if necessary
35         node_dict_list = [
36         {'hrn': 'iotlab.wsn430-11.devlille.iot-lab.info',
37         'archi': 'wsn430', 'mobile': 'True',
38         'hostname': 'wsn430-11.devlille.iot-lab.info',
39          'site': 'devlille', 'mobility_type': 'None',
40          'boot_state': 'Suspected',
41          'node_id': 'wsn430-11.devlille.iot-lab.info',
42          'radio': 'cc2420', 'posx': '2.3', 'posy': '2.3',
43          'node_number': 11, 'posz': '1'},
44          {'hrn': 'iotlab.wsn430-10.devlille.iot-lab.info',
45          'archi': 'wsn430', 'mobile': 'True',
46          'hostname': 'wsn430-10.devlille.iot-lab.info',
47          'site': 'devlille', 'mobility_type': 'None',
48          'boot_state': 'Alive', 'node_id': 'wsn430-10.devlille.iot-lab.info',
49          'radio': 'cc2420', 'posx': '1.3', 'posy': '2.3', 'node_number': 10,
50          'posz': '1'},
51          {'hrn': 'iotlab.wsn430-1.devlille.iot-lab.info',
52          'archi': 'wsn430', 'mobile': 'False',
53          'hostname': 'wsn430-1.devlille.iot-lab.info',
54          'site': 'devlille', 'mobility_type': 'None',
55          'boot_state': 'Alive', 'node_id': 'wsn430-1.devlille.iot-lab.info',
56          'radio': 'cc2420', 'posx': '0.3', 'posy': '0.3', 'node_number': 1,
57          'posz': '1'} ]
58         return node_dict_list
59
60
61
62
63     def get_sites(self, site_filter_name_list=None, return_fields_list=None):
64
65         """Get the different cortexlab sites and for each sites, the nodes
66         hostnames on this site.
67
68         :param site_filter_name_list: used to specify specific sites
69         :param return_fields_list: fields that has to be returned
70         :type site_filter_name_list: list
71         :type return_fields_list: list
72         """
73         site_dict_list = None
74         site_dict_list = [
75         {'address_ids': [], 'slice_ids': [], 'name': 'iotlab',
76         'node_ids': [u'wsn430-11.devlille.iot-lab.info',
77         u'wsn430-10.devlille.iot-lab.info', u'wsn430-1.devlille.iot-lab.info'],
78         'url': 'https://portal.senslab.info', 'person_ids': [],
79         'site_tag_ids': [], 'enabled': True, 'site': 'devlille',
80         'longitude': '- 2.10336', 'pcu_ids': [], 'max_slivers': None,
81         'max_slices': None, 'ext_consortium_id': None, 'date_created': None,
82         'latitude': '48.83726', 'is_public': True, 'peer_site_id': None,
83         'peer_id': None, 'abbreviated_name': 'iotlab'}]
84         # list of dict with mandatory keys  ['name', 'node_ids', 'longitude',
85         # 'site' ]. Value for key node_ids is a hostname list.
86         # See iotlabapi.py GetSites to get the filtering
87         return site_dict_list
88
89
90     def get_reserved_nodes(self, username):
91         """Get list of leases. Get the leases for the username if specified,
92         otherwise get all the leases.
93         :param username: user's LDAP login
94         :type username: string
95         :returns: list of reservations dict
96         :rtype: dict list
97
98         """
99         reserved_nodes_list_dict = None
100         return reserved_nodes_list_dict
101
102     def schedule_experiment(self, lease_dict):
103         """Schedule/ run an experiment based on the information provided in the
104         lease dictionary.
105
106         :param lease_dict: contains  lease_start_time,
107         lease_duration, added_nodes, slice_name , slice_user, grain:
108         :type lease_dict: dictionary
109
110         """
111         answer = {}
112         answer['id'] = None #experiment id
113         answer['msg'] = None #message in case of error
114
115         # Launch the experiment here
116
117         return answer
118
119     def delete_experiment(self, experiment_id, username):
120         """
121         Delete the experiment designated by its experiment id and its
122         user.
123         TODO: If the username is not necessary to delete the lease, then you can
124         remove it from the parameters, given that you propagate the changes
125
126         :param experiment_id: experiment identifier
127         :type experiment_id : integer
128         :param username: user's LDAP login
129         :type username: string
130         :returns: dict with delete status {'status': True of False}
131         :rtype: dict
132         """
133         # Delete the experiment here. Ret['status'] should be True or False
134         # depending if the delete was effective or not.
135         ret = {}
136         ret['status'] = None
137         return ret