Syncing Hosts’ information#

Currently syncing the hosts’ information will update all of the Host datastructures with some specific data about them (e.g network IPs, processor information). This let’s the user code to take decisions based on those information.

Note

The synchronisation is based on Ansible facts gathering and it somehow makes the Ansible facts available to the experimenter’s python code. It comes at the cost of making a connection to every single host (which can be heavy when managing thousands of hosts).

Also, in the future, we expect some providers to fill an initial version of the updated attribute to avoid a full sync. For instance, on Grid’5000 many information can be retrieved from the REST API.

Examples#

 1import logging
 2from pathlib import Path
 3
 4import enoslib as en
 5
 6en.init_logging(level=logging.INFO)
 7en.check()
 8
 9job_name = Path(__file__).name
10
11conf = en.G5kConf.from_settings(job_type=[], job_name=job_name).add_machine(
12    roles=["control"], cluster="paravance", nodes=1
13)
14
15provider = en.G5k(conf)
16roles, networks = provider.init()
17
18roles_synced = en.sync_info(roles, networks)
19
20# some info has been populated
21h = roles_synced["control"][0]
22assert len(h.net_devices) > 0
23assert h.processor is not None
24
25# we can filter addresses based on a given network (one ipv4 address here)
26assert len(h.filter_addresses(networks["my_network"])) >= 1
27
28# add an ipv6 (if not already there)
29en.run_command("dhclient -6 br0", roles=roles)
30
31# resync
32roles_synced = en.sync_info(roles, networks)
33h = roles_synced["control"][0]
34
35# we now have two addresses in the network my_network (one ipv4, one ipv6)
36assert len(h.filter_addresses(networks["my_network"])) == 2