Example #1
0
    def test_info_experiment(self):
        """ Test experiment.get_resources """
        experiment.info_experiment(self.api)
        self.api.get_resources.assert_called_with(False, None)

        experiment.info_experiment(self.api, list_id=True, site='grenoble')
        self.api.get_resources.assert_called_with(True, 'grenoble')
Example #2
0
    def test_info_experiment(self):
        """ Test experiment.get_resources """
        experiment.info_experiment(self.api)
        self.api.get_resources.assert_called_with(False, None)

        experiment.info_experiment(self.api, list_id=True, site='grenoble')
        self.api.get_resources.assert_called_with(True, 'grenoble')
Example #3
0
def info_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'info' command """
    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)

    selection = dict(opts.info_selection or ())
    return experiment.info_experiment(api, opts.list_id, **selection)
Example #4
0
def info_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'info' command """
    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)

    selection = dict(opts.info_selection or ())
    return experiment.info_experiment(api, opts.list_id, **selection)
Example #5
0
    def get_nodes(self):
        """
        Get all OAR nodes
        :returns: nodes with OAR properties
        :rtype: dict

        :Example:
        {"items": [
            {"archi": "a8:at86rf231",
             "mobile": 0,
             "mobility_type": " ",
             "network_address": "a8-53.grenoble.iot-lab.info",
             "site": "paris",
             "state": "Alive",
             "uid": "9856",
             "x": "0.37",
             "y": "5.44",
             "z": "2.33"
            },
            {"archi= ...}
          ]
        {
        """
        logger.warning("iotlashell get_nodes")
        nodes_dict = {}
        try:
            nodes = experiment.info_experiment(self.api)
        except HTTPError as err:
            logger.warning("iotlashell get_nodes error %s" % err.reason)
            return {'error' : err.reason}
        for node in nodes['items']:
            nodes_dict[node['network_address']] = node
        return nodes_dict
Example #6
0
def launch_experiment(deployment_site, number_of_nodes, experiment_time,
                      corridor):
    settings = settings_reader.SettingsReader(deployment_site)

    ids_text = extract_nodes_ids(str(settings.get_parameter(corridor)))
    nodes_ids = []
    for item in ids_text:
        id_begin, id_end = (int(x) for x in item.split("-"))
        nodes_ids.extend(np.arange(id_begin, id_end + 1, 1).tolist())

    json_data = json.loads(
        experiment.info_experiment(request, site=deployment_site))
    nodes_to_reserve = select_candidates(json_data, nodes_ids, number_of_nodes,
                                         deployment_site)

    resources = experiment.exp_resources(nodes_to_reserve)
    experiment_id = json.loads(
        experiment.submit_experiment(
            request, '', experiment_time + int(
                settings_reader.SettingsReader('experiment').get_parameter(
                    "extra_time")), resources))["id"]

    print_log("Starting new Experiment ({})".format(experiment_id))
    print_log("Selected nodes: {}".format(" ".join(nodes_to_reserve)),
              header=False)

    experiment.wait_experiment(request, experiment_id)
    return experiment_id
Example #7
0
def oar_uids(api):
    """ Extract nodes uids from oar infos """
    oar_uids_dict = {}
    resources = experiment.info_experiment(api)
    for node in resources['items']:
        uid = node['uid'].lower().strip()
        oar_uids_dict[node['network_address']] = uid

    return oar_uids_dict
Example #8
0
def oar_uids(api):
    """ Extract nodes uids from oar infos """
    oar_uids_dict = {}
    resources = experiment.info_experiment(api)
    for node in resources['items']:
        uid = node['uid'].lower().strip()
        oar_uids_dict[node['network_address']] = uid

    return oar_uids_dict
    def site_archi_dict(api):
        """ Returns a dict {'site': ['archi', 'archi2']} """
        _sites_dict = {}
        res_list = experiment.info_experiment(api, False)['items']

        site_archi = ((res['network_address'].split('.')[1], res['archi'])
                      for res in res_list)
        for site, archi in set(site_archi):
            archis = _sites_dict.setdefault(site, [])
            archis.append(archi)
            archis.sort()
        return _sites_dict
Example #10
0
    def site_archi_dict(api):
        """ Returns a dict {'site': ['archi', 'archi2']} """
        _sites_dict = {}
        res_list = experiment.info_experiment(api, False)['items']

        site_archi = ((res['network_address'].split('.')[1], res['archi'])
                      for res in res_list)
        for site, archi in set(site_archi):
            archis = _sites_dict.setdefault(site, [])
            archis.append(archi)
            archis.sort()
        return _sites_dict
    def _get_nodes_list(self, site, archi):
        """ Return a list of nodes for site, archi, state.
        If `state` defined restrict to this state,
        either choose bookable nodes """
        nodes = []

        res_list = experiment.info_experiment(self.api, False, site)['items']
        for res in res_list:
            if res['archi'] != archi:  # filter archis
                continue
            if res['state'] not in self.states:  # filter state
                continue
            nodes.append(res['network_address'])
        return nodes
Example #12
0
    def _get_nodes_list(self, site, archi):
        """ Return a list of nodes for site, archi, state.
        If `state` defined restrict to this state,
        either choose bookable nodes """
        nodes = []

        res_list = experiment.info_experiment(self.api, False, site)['items']
        for res in res_list:
            if res['archi'] != archi:  # filter archis
                continue
            if res['state'] not in self.states:  # filter state
                continue
            nodes.append(res['network_address'])
        return nodes
Example #13
0
    def test_info_experiment(self):
        """Test experiment.get_nodes."""
        experiment.info_experiment(self.api)
        self.api.get_nodes.assert_called_with(False, None)

        experiment.info_experiment(self.api, list_id=True, site='grenoble')
        self.api.get_nodes.assert_called_with(True, 'grenoble')

        experiment.info_experiment(self.api, site='grenoble', archi='m3')
        self.api.get_nodes.assert_called_with(False, 'grenoble', archi='m3')
#!/usr/bin/env python
import random
from math import sqrt, inf

from iotlabcli import auth, rest, experiment

user, passwd = auth.get_user_credentials()
api = rest.Api(user, passwd)

number_nodes = 64

nodes = experiment.info_experiment(api,
                                   site='lille',
                                   archi='m3',
                                   state='Alive')['items']
for node in list(nodes):
    try:
        node['x'] = float(node['x'])
        node['y'] = float(node['y'])
        node['z'] = float(node['z'])
    except ValueError:
        nodes.remove(node)

node_idx = random.randint(0, len(nodes) - 1)
selected_nodes = [nodes.pop(node_idx)]


def dist(node1, node2):
    return sqrt(pow(node1['x'] - node2['x'],2)\
                + pow(node1['y'] - node2['y'], 2)\
                + pow(node1['z'] - node2['z'], 2))