-
Notifications
You must be signed in to change notification settings - Fork 9
/
multiple_containers.py
executable file
·45 lines (39 loc) · 1.41 KB
/
multiple_containers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
import argparse
import shlex
import subprocess
import itertools
import ipaddress
from utils.OVS_Tools import start_containers, attach_container, connect_container_wIPs
NODE_0='192.1.1.2'
NODE_1='10.1.1.2'
BRIDGE='br0'
# Syntax: python connect_container.py -C <image name> -n <number of containers>
def get_names(number):
list = ['test{}'.format(i) for i in range(number)]
return list
def get_ip_range(base_ip, num):
try:
base_ip = ipaddress.ip_address(unicode(base_ip))
except:
print('Invalid ip address: {}'.format(base_ip))
sys.exit(1)
ips = [base_ip + i for i in range(num)]
return ips
def main():
parser=argparse.ArgumentParser(description='Connect container to vswitch')
parser.add_argument('--container', '-C', required=True, type=str)
# parser.add_argument('--name', '-N', required=True, type=str)
parser.add_argument('--instances', '-n', required=True, type=int)
args=parser.parse_args()
name_list = []
client_ips = []
server_ips = []
name_list = get_names(args.instances)
client_ips = get_ip_range(NODE_0, args.instances)
server_ips = get_ip_range(NODE_1, args.instances)
for i in range(0, len(name_list)):
start_containers(args.container, name_list[i])
attach_container(BRIDGE, name_list[i])
connect_container_wIPs(BRIDGE, client_ips[i], server_ips[i], name_list[i])
if __name__ == '__main__':
main()