import enoslib as en
-
SIMONIN Matthieu authoredSIMONIN Matthieu authored
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.
- Get a Grid'5000 account
- 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
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).
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")
bare_host
host_with_alias
host_with_alias_and_username
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.
localhost = en.LocalHost()
localhost
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.
docker_host = en.DockerHost("alias", "container_name", host_with_alias_and_username)
docker_host
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.
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
Network and Networks
Network
and Networks
are the same as Host
and Roles
but for networks:
Network
represent a single NetworkNetworks
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
.
from enoslib.objects import DefaultNetwork
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")
one_network
one_network_with_a_pool_of_ips
# get one free ip
ip_gen = one_network_with_a_pool_of_ips.free_ips
next(ip_gen)
IPv4Address('192.168.1.10')
# get another one
next(ip_gen)
IPv4Address('192.168.1.11')