Example #1
0
def ssh_keys():
    """List ssh keys configured into user's iot-lab account"""

    api = Api(*get_user_credentials())
    keys_json = api.get_ssh_keys()

    print("SSH keys:")
    for key in keys_json['sshkeys']:
        print(key)
Example #2
0
def robot_get_map(site):
    """ Download all robot map files

    Download robot site config, map and docks list """
    map_cfg = {}

    map_cfg['config'] = Api.get_robot_mapfile(site, 'mapconfig')
    map_cfg['image'] = Api.get_robot_mapfile(site, 'mapimage')
    map_cfg['dock'] = Api.get_robot_mapfile(site, 'dockconfig')

    return map_cfg
Example #3
0
def robot_get_map(site):
    """ Download all robot map files

    Download robot site config, map and docks list """
    map_cfg = {}

    map_cfg['config'] = Api.get_robot_mapfile(site, 'mapconfig')
    map_cfg['image'] = Api.get_robot_mapfile(site, 'mapimage')
    map_cfg['dock'] = Api.get_robot_mapfile(site, 'dockconfig')

    return map_cfg
Example #4
0
 def stop(self):
     """If running stop the experiment"""
     ret = None
     if self.exp_id is not None:
         ret = stop_experiment(Api(*self.user_credentials()), self.exp_id)
         self.exp_id = None
     return ret
Example #5
0
def api_mock(ret=None):
    """ Return a mock of an api object
    returned value for api methods will be 'ret' parameter or API_RET
    """
    ret = ret or API_RET
    ret_val = RequestRet(content=json_dumps(ret), status_code=200)  # HTTP OK
    patch('requests.request', return_value=ret_val).start()
    api_class = patch('iotlabcli.rest.Api').start()
    api_class.return_value = Mock(wraps=Api('user', 'password'))
    return api_class.return_value
Example #6
0
def add_ssh_key(identity_file=None):
    """Install ssh key into user's iot-lab account"""

    if identity_file is None:
        identity_file = IDENTITY_FILE

    api = Api(*get_user_credentials())
    keys_json = api.get_ssh_keys()
    pub_key = identity_file + '.pub'
    with open(pub_key) as key_fh:
        key = key_fh.read().strip()

    keys = keys_json['sshkeys']
    if key in keys:
        msg = f'Key is already configured:\n"{key}"'
        raise ValueError(msg)

    keys.append(key)

    api.set_ssh_keys(keys_json)
Example #7
0
 def _submit(self, site, duration):
     """Submit an experiment with required nodes"""
     api = Api(*self.user_credentials())
     resources = []
     for ctrl in self.ctrls:
         if ctrl.env.get('IOTLAB_NODE') is not None:
             resources.append(exp_resources([ctrl.env.get('IOTLAB_NODE')]))
         elif ctrl.board() is not None:
             board = IoTLABExperiment._archi_from_board(ctrl.board())
             alias = AliasNodes(1, site, board)
             resources.append(exp_resources(alias))
         else:
             raise ValueError("neither BOARD or IOTLAB_NODE are set")
     return submit_experiment(api, self.name, duration, resources)['id']
 async def authenticate(self, handler, data):
     _username = data['username'].strip()
     _password = data['password']
     if '@' in _username:
         # Prevent use of email as login
         return None
     api = Api(_username, _password)
     try:
         if api.check_credential():
             ret = {
                 'name': _username,
                 'auth_state': {
                     'userdata': {
                         'authenticator': 'iotlab',
                         'username': _username,
                         'password': _password,
                     }
                 }
             }
             return ret
     except:
         pass
     return None
Example #9
0
def main():
    """ Launch serial aggregator and aggregate serial links
    of all nodes.
    """
    parser = opts_parser()
    opts = parser.parse_args()
    api = Api(*get_user_credentials())
    opts.with_a8 = True
    try:
        nodes = SerialAggregator.select_nodes(opts)
    except RuntimeError as err:
        print(err)
        exit(1)
    if opts.experiment_id:
        exp_id = opts.experiment_id
    else:
        exp_id = iotlabcli.get_current_experiment(api)
    print("Running radio logger ...")
    run_radio_logger(exp_id, opts, nodes)
Example #10
0
def check_user_credentials(username, password):
    """ Check that the given credentials are valid """
    api = Api(username, password)
    return api.check_credential()
Example #11
0
def check_user_credentials(username, password):
    """ Check that the given credentials are valid """
    api = Api(username, password)
    return api.check_credential()
Example #12
0
 def _get_nodes(self):
     """Return all nodes reserved by the experiment"""
     ret = get_experiment(Api(*self.user_credentials()), self.exp_id)
     return ret['nodes']
Example #13
0
 def _wait(self):
     """Wait for the experiment to finish launching"""
     ret = wait_experiment(Api(*self.user_credentials()), self.exp_id)
     return ret