bootstrap_agents.py 1.93 KB
Newer Older
1
2
3
4
5
import logging
import os
import json
import pika

Federico Sismondi's avatar
Federico Sismondi committed
6
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
7
8
9
10
11
12
13
14
15
16
queue_name = 'unittest_packet_router'

# rewrite default values with ENV variables
AMQP_SERVER = str(os.environ['AMQP_SERVER'])
AMQP_USER = str(os.environ['AMQP_USER'])
AMQP_PASS = str(os.environ['AMQP_PASS'])
AMQP_VHOST = str(os.environ['AMQP_VHOST'])
AMQP_EXCHANGE = str(os.environ['AMQP_EXCHANGE'])

print('Env vars for AMQP connection succesfully imported')
Federico Sismondi's avatar
Federico Sismondi committed
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
print(json.dumps(
        {
            'server': AMQP_SERVER,
            'session': AMQP_VHOST,
            'user': AMQP_USER,
            'pass': '#' * len(AMQP_PASS),
            'exchange': AMQP_EXCHANGE
        }
))

connection = pika.BlockingConnection(
        pika.connection.URLParameters(
                'amqp://%s:%s@%s/%s'
                %(AMQP_USER,
                  AMQP_PASS,
                  AMQP_SERVER,
                  AMQP_VHOST)
        )
)

channel = connection.channel()
channel.confirm_delivery()

d = {
    "_type": "tun.start",
    "ipv6_host": ":1",
    "ipv6_prefix": "bbbb"
}

logging.debug("Let's start the bootstrap the agents")

49
50
51
52
53
54
55
56
57
channel.basic_publish(
        exchange=AMQP_EXCHANGE,
        routing_key='control.tun.toAgent.agent1',
        mandatory=True,
        properties=pika.BasicProperties(
            content_type='application/json',
        ),
        body=json.dumps(d)
)
58
59

d["ipv6_host"] = ":2"
60
61
62
63
64
65
66
67
68
channel.basic_publish(
        exchange=AMQP_EXCHANGE,
        routing_key='control.tun.toAgent.agent2',
        mandatory=True,
        properties=pika.BasicProperties(
                content_type='application/json',
        ),
        body=json.dumps(d)
)
Federico Sismondi's avatar
Federico Sismondi committed
69
70

d["ipv6_host"] = ":3"
71
72
73
74
75
76
77
78
79
80
channel.basic_publish(
        exchange=AMQP_EXCHANGE,
        routing_key='control.tun.toAgent.agent_TT',
        mandatory=True,
        properties=pika.BasicProperties(
            content_type='application/json',
        ),
        body=json.dumps(d)
)