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