blob: 8a4f390aa911f1ebdc870898936ab911e62834ca [file] [log] [blame]
TamasBakaid38feb62019-02-28 09:06:19 +00001#!/usr/bin/env python3
2import argparse
3import sys
4from subprocess import *
5from subprocess import STDOUT
6import subprocess
7import ipaddress
8import time
9
10parser = argparse.ArgumentParser()
11parser.add_argument(
12 '--bootstrap',
13 help='Bootstrapping the system',
14)
15
16parser.add_argument(
TamasBakaib59bffb2019-03-22 09:52:03 +000017 '--trigger',
18 help='Trigger one single VES event from each simulator',
19)
20
21parser.add_argument(
TamasBakaibab325b2019-03-26 09:20:16 +000022 '--urlves',
23 help='URL of the VES collector',
TamasBakaid38feb62019-02-28 09:06:19 +000024)
25
26parser.add_argument(
TamasBakaib59bffb2019-03-22 09:52:03 +000027 '--ipfileserver',
28 help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event',
29)
30
31parser.add_argument(
TamasBakaid38feb62019-02-28 09:06:19 +000032 '--ipstart',
33 help='IP address range beginning',
34)
35
36parser.add_argument(
37 '--clean',
38 action='store_true',
39 help='Cleaning work-dirs',
40)
41
42parser.add_argument(
43 '--start',
44 help='Starting instances',
45)
46
47parser.add_argument(
48 '--status',
49 help='Status',
50)
51
52parser.add_argument(
53 '--stop',
54 help='Stopping instances',
55)
56
57args = parser.parse_args()
58
TamasBakaibab325b2019-03-26 09:20:16 +000059if args.bootstrap and args.ipstart and args.urlves:
TamasBakaid38feb62019-02-28 09:06:19 +000060 print("Bootstrap:")
61
TamasBakaib59bffb2019-03-22 09:52:03 +000062 start_port=2000
63
TamasBakaid38feb62019-02-28 09:06:19 +000064 for i in range(int(args.bootstrap)):
65 print("PNF simulator instance: " + str(i) + ".")
66
67 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
68 print("\tIp Subnet:" + str(ip_subnet))
69 # The IP ranges are in distance of 16 compared to each other.
70 # This is matching the /28 subnet mask used in the dockerfile inside.
71
72 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
73 print("\tIP Gateway:" + str(ip_gw))
74
75 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
76 print("\tIp Pnf SIM:" + str(IpPnfSim))
77
TamasBakaib59bffb2019-03-22 09:52:03 +000078 IpFileServer = args.ipfileserver
79
80
81 PortSftp=start_port +1
82 PortFtps=start_port +2
83 start_port +=2
TamasBakaibab325b2019-03-26 09:20:16 +000084 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
85 print("\tUrl Ftps: " + str(UrlFtps))
TamasBakaib59bffb2019-03-22 09:52:03 +000086
TamasBakaibab325b2019-03-26 09:20:16 +000087 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
88 print("\tUrl Sftp: " + str(UrlSftp))
TamasBakaid38feb62019-02-28 09:06:19 +000089
90 foldername = "pnf-sim-lw-" + str(i)
91 completed = subprocess.run('mkdir ' + foldername, shell=True)
92 print('\tCreating folder:', completed.stdout)
93 completed = subprocess.run(
94 'cp -r pnf-sim-lightweight/* ' +
95 foldername,
96 shell=True)
97 print('\tCloning folder:', completed.stdout)
98
TamasBakaibab325b2019-03-26 09:20:16 +000099 composercmd = "./simulator.sh compose " + \
100 str(ip_gw) + " " + \
101 str(ip_subnet) + " " + \
102 str(i) + " " + \
103 str(args.urlves) + " " + \
104 str(IpPnfSim) + " " + \
105 str(IpFileServer) + " " + \
106 str(PortSftp) + " " + \
107 str(PortFtps) + " " + \
108 str(UrlFtps) + " " + \
109 str(UrlSftp)
TamasBakaid38feb62019-02-28 09:06:19 +0000110
111 completed = subprocess.run(
112 'set -x; cd ' +
113 foldername +
114 '; ' +
115 composercmd,
116 shell=True)
117 print('Cloning:', completed.stdout)
118
TamasBakaibab325b2019-03-26 09:20:16 +0000119 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
120 print("Build docker image: ", completed.stdout)
121
TamasBakaid38feb62019-02-28 09:06:19 +0000122 sys.exit()
123
124if args.clean:
125 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
126 print('Deleting:', completed.stdout)
127 sys.exit()
128
129if args.start:
130
131 for i in range(int(args.start)):
132 foldername = "pnf-sim-lw-" + str(i)
133
134 completed = subprocess.run(
135 'set -x ; cd ' +
136 foldername +
137 "; bash -x ./simulator.sh start",
138 shell=True)
139 print('Starting:', completed.stdout)
140
141 time.sleep(5)
142
143if args.status:
144
145 for i in range(int(args.status)):
146 foldername = "pnf-sim-lw-" + str(i)
147
148 completed = subprocess.run(
149 'cd ' +
150 foldername +
151 "; ./simulator.sh status",
152 shell=True)
153 print('Status:', completed.stdout)
154
155if args.stop:
156 for i in range(int(args.stop)):
157 foldername = "pnf-sim-lw-" + str(i)
158
159 completed = subprocess.run(
160 'cd ' +
161 foldername +
RehanRaza48f92042019-03-20 08:12:55 +0000162 "; ./simulator.sh stop " + str(i),
TamasBakaid38feb62019-02-28 09:06:19 +0000163 shell=True)
164 print('Stopping:', completed.stdout)
165
TamasBakaib59bffb2019-03-22 09:52:03 +0000166
167if args.trigger:
168 print("Triggering VES sending:")
169
170 for i in range(int(args.trigger)):
171 foldername = "pnf-sim-lw-" + str(i)
172
173 completed = subprocess.run(
174 'cd ' +
175 foldername +
176 "; ./simulator.sh trigger-simulator",
177 shell=True)
178 print('Status:', completed.stdout)
179
TamasBakaid38feb62019-02-28 09:06:19 +0000180else:
181 print("No instruction was defined")
182 sys.exit()