Multi-providers tutorials#

This tutorial illustrates the use of EnOSlib to interact with several providers in a synchronized way.

 1# Edge to Cloud example with Iot-Lab and Grid'5000
 2# This example is inspired from:
 3# https://www.chameleoncloud.org/experiment/share/37991779-fd7b-4ab0-8d6f-e726a9204946
 4
 5import logging
 6import os
 7from ipaddress import IPv6Interface
 8
 9import enoslib as en
10
11en.init_logging(level=logging.INFO)
12en.check()
13
14prefix = os.getlogin()
15_walltime = "02:00:00"
16
17JOB_NAME = f"{prefix}-enoslib-g5kcloud-lease3"
18
19# Leasing resources on G5K
20g5k_conf = {
21    "walltime": _walltime,
22    "job_type": [],
23    "job_name": JOB_NAME,
24    "resources": {
25        "machines": [
26            {
27                "roles": ["server"],
28                "cluster": "paravance",
29                "nodes": 1,
30                "primary_network": "n1",
31                "secondary_networks": [],
32            },
33        ],
34        "networks": [
35            {"id": "n1", "type": "prod", "roles": ["my_network"], "site": "rennes"}
36        ],
37    },
38}
39g5k_conf = en.G5kConf.from_dictionary(g5k_conf)
40g5k = en.G5k(g5k_conf)
41
42# Leasing resources on FIT IoT LAB
43iotlab_conf = {
44    "walltime": _walltime,
45    "job_name": JOB_NAME,
46    "resources": {
47        "machines": [
48            {
49                "roles": ["client"],
50                "archi": "rpi3:at86rf233",
51                "site": "grenoble",
52                "number": 3,
53            }
54        ]
55    },
56}
57iotlab_conf = en.IotlabConf.from_dictionary(iotlab_conf)
58iotlab = en.Iotlab(iotlab_conf)
59
60providers = en.Providers([g5k, iotlab])
61roles, networks = providers.init()
62
63# Firewall rules
64with g5k.firewall(hosts=roles["server"], port=[1883], src_addr=None, proto="tcp+udp"):
65    en.run("dhclient -6 br0", roles=roles["server"])
66    roles = en.sync_info(roles, networks)
67
68    cloud_server = roles["server"][0]
69    addresses = cloud_server.filter_addresses(networks=networks["my_network"])
70    # get only the ipv6 address
71    floating_ip = [str(a.ip.ip) for a in addresses if isinstance(a.ip, IPv6Interface)][
72        0
73    ]
74
75    logging.info(f"Cloud server IP: {floating_ip}")  # 2001:660:4406:700:1::28
76
77    # Experimentation logic starts here
78    # G5K Cloud
79    dest_dir = "/tmp"
80    with en.play_on(roles=roles["server"]) as p:
81        p.copy(src="./artifacts_cloud/", dest=dest_dir)
82        p.shell(f"cd {dest_dir} && bash {dest_dir}/cloud_worker.sh > {dest_dir}/tests")
83    # FIT IoT LAB
84    with en.play_on(roles=roles["client"]) as p:
85        p.copy(src="./artifacts_edge", dest=dest_dir)
86        p.shell(
87            f"bash {dest_dir}/artifacts_edge/edge_worker.sh edge_data 100 {floating_ip}"
88        )
89
90    # How to check execution?  firewall rule:
91    # https://api.grid5000.fr/stable/sites/rennes/firewall/1909896 ssh to the
92    # Cloud server: ssh root@paravance-40.rennes.grid5000.fr
93    # root@paravance-40:~# tail -f /tmp/predict.log you may also check mosquitto
94    # topic (mosquitto_sub_img.py downloads images received in running dir):
95
96    # $ python mosquitto_sub_img.py --topic edge_data --mqtt_broker <IPv6>
97    # $ python mosquitto_sub_img.py --topic edge_data --mqtt_broker <IPv6>