Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bbbda1eb authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files
parent 7d363747
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:b46992a6-b75c-45d8-bacb-a8d54ea8de44 tags:
 
# One time setup for use in labs.iot-lab.info
 
---
 
- Website: https://discovery.gitlabpages.inria.fr/enoslib/index.html
- Instant chat: https://framateam.org/enoslib
- Source code: https://gitlab.inria.fr/discovery/enoslib
 
---
 
 
Prerequisites:
 
- Connect to this Jupyter lab instance https://labs.iot-lab.info
- Clone the enoslib tutorias source: `git clone https://gitlab.inria.fr/msimonin/enoslib-tutorials` at the root of the jupyter lab instance
- Open this notebook at `enoslib-tutorials/`
 
![overview.png](attachment:f8a0b9c9-9ffe-470a-bd8b-83cd3b209be0.png)
 
In this setup the control machine is the jupyter instance running at https://labs.iot-lab.info
 
%% Cell type:markdown id:9499ca23-b2c7-4b52-a5f2-6c661e8e3497 tags:
 
## Software dependencies
 
First things first, you'll need EnOSlib library to go through this tutorial.
 
- Launch the following
- Restart the kernel
 
%% Cell type:code id:f78e397c-52bd-4c78-94ef-eacc16170832 tags:
 
``` python
# pick one
!pip install -U pip
 
# pick one
# latest stable
# !pip install -U --user enoslib
# !pip install -U --user enoslib[silecs]
 
# latest alpha version
# !pip install -U --user --pre enoslib
# !pip install -U --user --pre enoslib[silecs]
 
# master version (might be wild)
!pip install -U --user git+https://gitlab.inria.fr/discovery/enoslib
!pip install -U --user enoslib[silecs]@git+https://gitlab.inria.fr/discovery/enoslib
```
 
%% Cell type:code id:c1f7a79e-9d32-44b1-a805-88cbdcea174c tags:
 
``` python
# This must not fail (restart the kernel after installing the library)
import enoslib as en
```
 
%% Cell type:markdown id:840f2c4c-0e54-4b8f-ad5b-e10644dc0b4e tags:
 
### Setup access to Grid'5000
 
We need two kind of accesses to the Grid'5000 platform:
- REST API Access to interact with Grid'5000 exposed resources (jobs, nodes, networks, firewall ....)
- SSH Access to control the remote machine once acquired
 
---
#### REST API Access
The REST API access is performed using HTTP request using BasicAuth Authentication mecanism through the [`python-grid5000`](https://pypi.org/project/python-grid5000/) wrapper.
This requires to store the username/password in a file located in your home directory.
 
%% Cell type:code id:71b8d3a8-a8bb-4d49-83fe-b2334aa29167 tags:
 
``` python
from grid5000.cli import auth
# CHANGE ME!
G5K_USER = "msimonin"
# will prompt for the password and write the authentication file
auth(G5K_USER)
```
 
%% Cell type:code id:3320e287-270f-4122-a7cb-688e2705bf13 tags:
 
``` python
# Test the api access
from grid5000 import Grid5000
from pathlib import Path
conf_file = Path.home() / ".python-grid5000.yaml"
gk = Grid5000.from_yaml(conf_file)
gk.sites.list()
```
 
%% Cell type:code id:241809aa-41bc-4171-a0f5-874f82425aaf tags:
 
``` python
# have some fun with the g5k python client ...
gk.sites["rennes"].clusters.list()
```
 
%% Cell type:code id:6b246f33-2a09-456d-9330-58d8c48d7375 tags:
 
``` python
print(gk.sites["rennes"].clusters["paravance"].nodes.list()[0])
```
 
%% Cell type:markdown id:3f0a7522-7c68-4c8f-8197-002b7959c9d6 tags:
 
---
#### SSH access
The SSH access relies on SSH key authentication.
Add the content of the public key in the Grid'5000 interface in [your Grid'5000 account](https://api.grid5000.fr/stable/users/) > ssh_keys
 
%% Cell type:code id:3e3564b4-b675-4e37-a731-16e0d274f1ad tags:
 
``` python
!cat ~/.ssh/id_rsa.pub
```
 
%% Cell type:markdown id:5b86261e-357a-4c5f-aeaa-f26c26fdb3ef tags:
 
<div class="alert alert-block alert-warning">
Note that you don't own the corresponding private key, so that's probably better to remove it from <a href="https://api.grid5000.fr/stable/users/">your Grid'5000 account</a> as soon as possible.
</div>
 
%% Cell type:markdown id:cf150071-950b-44e4-a2f2-499d00fe1a46 tags:
 
#### Set a SSH config to ease the connection to G5K
 
For instance this eases the direct connection to unconstrained node (A8, Rpi ...) that run a SSH server.
 
%% Cell type:code id:0e4d6cf8-65ae-474e-8549-0a7709133770 tags:
 
``` python
from pathlib import Path
 
config = Path.home() / ".ssh/config"
 
# Access to machines inside G5K
config_g5k = f"""Host !access.grid5000.fr *.grid5000.fr
User {G5K_USER}
ProxyJump {G5K_USER}@access.grid5000.fr
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
ForwardAgent yes
 
Host access.grid5000.fr
User {G5K_USER}
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
ForwardAgent yes
"""
 
 
FIT_USER = "simonin"
configs_iot = []
for site in ["grenoble", "lille", "saclay", "strasbourg"]:
configs_iot.append(f"""Host !{site}.iot-lab.info *.{site}.iot-lab.info
User {FIT_USER}
ProxyJump {FIT_USER}@{site}.iot-lab.info
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
ForwardAgent yes
 
Host {site}.iot-lab.info
User {FIT_USER}
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
ForwardAgent yes
"""
)
 
configs = [config_g5k] + configs_iot
config.write_text("\n".join(configs))
```
 
%% Cell type:code id:b0d7da19-ea57-40e4-9314-ad628ffbd6ff tags:
 
``` python
# This must work
!ssh rennes.grid5000.fr hostname
```
 
%% Cell type:code id:c49e26a9-965b-4501-afa2-e689ef88e2c3 tags:
 
``` python
# Testing the ssh connection to g5k using the lib
import enoslib as en
 
en.init_logging()
 
frontend = en.Host("rennes.grid5000.fr", user=G5K_USER)
 
r = en.run_command("hostname", roles=frontend, raw=True)
 
print(f"We've succesfully reached {r[0].stdout}")
```
 
%% Cell type:code id:5794c7a6-2b8e-4dd2-bd6f-2e6b08b0ba14 tags:
 
``` python
# This also must work
!ssh grenoble.iot-lab.info hostname
```
 
%% Cell type:code id:e8dd01c1-586b-47a6-96b5-c488a01b4696 tags:
 
``` python
fit_grenoble = en.Host("grenoble.iot-lab.info", user=FIT_USER)
 
r = en.run_command("hostname", roles=fit_grenoble, raw=True)
 
print(f"We've succesfully reached {r[0].stdout}")
```
 
%% Cell type:code id:f4ff0662-03b0-407f-95a4-66f453b11905 tags:
 
``` python
# you're ready !
```
 
%% Cell type:code id:2908964f-933d-4a0f-b82c-9d2385e920c0 tags:
%% Cell type:markdown id:5e3e183e-4043-4569-b960-039b5977ed45 tags:
## Check
%% Cell type:code id:725cf9e2-971a-4ec8-aa69-72e0a6242281 tags:
``` python
en.check()
```
%% Cell type:code id:3baa0a7b-6319-414d-8f5c-8c40922d6a41 tags:
 
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment