Mentions légales du service

Skip to content
Snippets Groups Projects
Forked from discovery / enoslib
820 commits behind the upstream repository.
00_setup_and_basics.ipynb 82.26 KiB

Setup and basic objects

Get started with EnOSlib on Grid'5000.



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. 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.
  2. Make sure EnOSlib is available in your notebook environment
    • Follow the steps here. Using a virtualenv is the way to go, make sure to use one.

Testing the import

In [1]:
import enoslib as en

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).

In [14]:
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")
In [15]:
bare_host
Out [15]:
In [16]:
host_with_alias
Out [16]:
In [17]:
host_with_alias_and_username
Out [17]:

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.

In [6]:
localhost = en.LocalHost()
localhost
Out [6]:

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.

In [7]:
docker_host = en.DockerHost("alias", "container_name", host_with_alias_and_username)
docker_host
Out [7]:

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.

Roles

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.

In [22]:
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
Out [22]:

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.

In [23]:
from enoslib.objects import DefaultNetwork
In [24]:
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") 
In [25]:
one_network
Out [25]:
In [26]:
one_network_with_a_pool_of_ips
Out [26]:
In [27]:
# get one free ip
ip_gen = one_network_with_a_pool_of_ips.free_ips
next(ip_gen)
Out [27]:
IPv4Address('192.168.1.10')
In [28]:
# get another one
next(ip_gen)
Out [28]:
IPv4Address('192.168.1.11')