Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 6efdf2a3 authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

docs/jupyter: some updates

parent e4ddf439
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:racial-puppy tags:
# Setup and basic objects
Get started with EnOSlib on Grid'5000.
---
- Website: https://discovery.gitlabpages.inria.fr/enoslib/index.html
- Instant chat: https://framateam.org/enoslib
---
This is the first notebooks of a series that will let you discover the main features of EnOSlib/Grid'5000.
If you want to actually execute them you'll need to setup your environment properly.
We sum up here the different steps to achieve this process.
1. Get a Grid'5000 account
- Register using this [page](https://www.grid5000.fr/w/Grid5000:Get_an_account).
Pay attention to the fact that uploading a SSH key (public part) is mandatory to perform any EnOSlib action.
- Make sure the SSH connection is ready. You can follow this [tutorial](https://www.grid5000.fr/w/Getting_Started).
2. Make sure EnOSlib is available in your notebook environment
- Follow the steps [here](https://discovery.gitlabpages.inria.fr/enoslib/tutorials/grid5000.html#installation).
Using a virtualenv is the way to go, make sure to use one.
%% Cell type:markdown id:8b961d12-5752-4181-a672-a00013c20163 tags:
## Testing the import
%% Cell type:code id:indirect-delicious tags:
``` python
import enoslib as en
```
%% Cell type:markdown id:818254cb-c26f-4457-bf41-a2229eb8243d tags:
## Resources abstractions
In this notebook we won't execute anything remotely, instead we'll just cover some basic abstractions provided by the library.
We start with the abstractions of the resources (machines and networks that are usually given by an infrastructure)
### Host
An host is anything we can connect to and act on it. Most of the time it corresponds to a machine reachable through SSH.
The datastructure reflects this.
Usually you don't instantiate hosts manually, instead they are brought to you by EnOSlib (because they depend on a scheduler decision like OAR on Grid'5000).
%% Cell type:code id:665c334b-6c6e-4ca1-95ed-010f683d81b0 tags:
``` python
bare_host = en.Host("192.168.0.1")
host_with_alias = en.Host("192.168.0.2", alias="one_alias")
host_with_alias_and_username = en.Host("192.168.0.3", alias="one_alias", user="foo")
```
%% Cell type:code id:ae526e0b-ca1a-429b-a3a1-a7d3623c9e28 tags:
``` python
bare_host
```
%% Output
Host(address='192.168.0.1', alias='192.168.0.1', user=None, keyfile=None, port=None, extra={}, net_devices=set())
%% Cell type:code id:2fb3ec36-0b5d-4aa3-99bc-702f308e3e89 tags:
``` python
host_with_alias
```
%% Output
Host(address='192.168.0.2', alias='one_alias', user=None, keyfile=None, port=None, extra={}, net_devices=set())
%% Cell type:code id:10e17d3b-9888-486a-bb58-642151b9d42e tags:
``` python
host_with_alias_and_username
```
%% Output
Host(address='192.168.0.3', alias='one_alias', user='foo', keyfile=None, port=None, extra={}, net_devices=set())
%% Cell type:markdown id:2436ad88-9b65-4c17-9c43-6ca33db0b5b7 tags:
The local machine can be represented by an instance of the `LocalHost` object. This is a specialization of an `Host`, the connection to this host will be made using sub-processes (instead of SSH). We can see it in the `extra` attribute of the `LocalHost` object. This `extra` attribute is actually interpreted when a "remote" action is triggered on our hosts.
%% Cell type:code id:1d7daa8d-605b-4940-bf9b-37e7d814b92f tags:
``` python
localhost = en.LocalHost()
localhost
```
%% Output
LocalHost(address='localhost', alias='localhost', user=None, keyfile=None, port=None, extra={'ansible_connection': 'local'}, net_devices=set())
%% Cell type:markdown id:a5a50353-9275-4a0e-bf0e-49fd1cd01ec4 tags:
Other types of Hosts are possible. The library has a `DockerHost` which represents a docker container we want to reach using the docker TCP protocol. One needs to specify where this container is running by passing an host instance.
%% Cell type:code id:06e734e9-4276-46a3-851e-04257ea22b68 tags:
``` python
docker_host = en.DockerHost("alias", "container_name", host_with_alias_and_username)
docker_host
```
%% Output
DockerHost(address='container_name', alias='alias', user='foo', keyfile=None, port=None, extra={'ansible_connection': 'docker', 'ansible_docker_extra_args': '-H ssh://foo@192.168.0.3', 'mitogen_via': 'foo@192.168.0.3'}, net_devices=set())
%% Cell type:markdown id:71371096-d367-463d-a82b-f1a861c4703b tags:
The above `extra` field suggest that the connection to this docker container will be made through an ssh jump to the remote host hosting the container.
This will be done transparently by the library anyway.
---
A common pratice when experimenting, especially with distributed applications, is to form logical group of machines.
%% Cell type:markdown id:d62c0172-bea2-4d17-b414-6aa24dd7f070 tags:
### Roles
%% Cell type:markdown id:7cad7f3c-49ee-4a08-964f-4367b16d88a8 tags:
During an experiment your hosts will serve different purposes: some will host the system you are studying while other will install third party tools to inject some load, observe ...
A natural way of configuring differently several sets of hosts is to tag them and group them according to their tags.
The `Roles` datastructure serves this purpose: it lets you group your hosts based on tags. It follow a `dict-like` interface.
%% Cell type:code id:f0e99de3-5565-4203-b1e1-c767f850192b tags:
``` python
h1 = en.Host("10.0.0.1")
h2 = en.Host("10.0.0.2")
h3 = en.Host("10.0.0.3")
roles = en.Roles()
roles["tag1"] = [h1, h2]
roles["tag2"] = [h3]
roles["tag3"] = [h2, h3]
roles
```
%% Output
{'tag1': [Host(address='10.0.0.1', alias='10.0.0.1', user=None, keyfile=None, port=None, extra={}, net_devices=set()), Host(address='10.0.0.2', alias='10.0.0.2', user=None, keyfile=None, port=None, extra={}, net_devices=set())], 'tag2': [Host(address='10.0.0.3', alias='10.0.0.3', user=None, keyfile=None, port=None, extra={}, net_devices=set())], 'tag3': [Host(address='10.0.0.2', alias='10.0.0.2', user=None, keyfile=None, port=None, extra={}, net_devices=set()), Host(address='10.0.0.3', alias='10.0.0.3', user=None, keyfile=None, port=None, extra={}, net_devices=set())]}
%% Cell type:markdown id:8549ef96-1e0c-4d9e-ab58-abb119355177 tags:
### Network and Networks
`Network` and `Networks` are the same as `Host` and `Roles` but for networks:
- `Network` represent a single Network
- `Networks` represent a "Roles" of Network: networks indexed by their tags
.
Networks are usually given by an infrastructure and thus you won't really instantiate `Network` nor `Networks` by yourself.
More precisely there exists a specific subclass of `Network` per infrastructure which will be returned automatically by EnOSlib when needed.
Moreover `Network` datastructure isn't exposed in EnOSlib at the top level, let's see however how a `DefaultNetwork` can look like. A `DefaultNetwork` is a very common abstraction of a network that allows to represent a basic network with optionnally a pool of free ips/macs address. For instance a subnet or a vlan on Grid5000 are represented by a specific `DefaultNetwork`.
%% Cell type:code id:dbbd79c8-4440-44d4-a264-1aa71115cd1a tags:
``` python
from enoslib.objects import DefaultNetwork
```
%% Cell type:code id:d7788d7c-245c-4069-ab06-bb66d022c5dd tags:
``` python
one_network = DefaultNetwork("192.168.1.0/24")
one_network_with_a_pool_of_ips = DefaultNetwork("192.168.1.0/24", ip_start="192.168.1.10", ip_end="192.168.1.100")
```
%% Cell type:code id:e7952082-7aab-4a3d-8ff7-1a6f6a102dc6 tags:
``` python
one_network
```
%% Output
<enoslib.objects.DefaultNetwork at 0x7f39d8067390>
%% Cell type:code id:a4aa289d-357f-4003-9a77-4cfa6284df72 tags:
``` python
one_network_with_a_pool_of_ips
```
%% Output
<enoslib.objects.DefaultNetwork at 0x7f39d80b1410>
%% Cell type:code id:337d3e84-c08a-4846-8b64-93f70d491e51 tags:
``` python
# get one free ip
ip_gen = one_network_with_a_pool_of_ips.free_ips
next(ip_gen)
```
%% Output
IPv4Address('192.168.1.10')
%% Cell type:code id:467c109c-c402-4ff7-a375-4330541f3452 tags:
``` python
# get another one
next(ip_gen)
```
%% Output
IPv4Address('192.168.1.11')
%% Cell type:markdown id:07f16097-4f2a-44ff-b057-a860a8759380 tags:
## About
%% Cell type:markdown id:cd2ed1aa-1260-4f83-bf84-a2890dd785bb tags:
This notebook is brought
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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