blob: c3a17b0b1fe614f19d84caebec82febbe0e925d7 [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
TamasBakai34a6f112019-04-15 08:38:51 +000021
22parser.add_argument(
23 '--triggerstart',
24 help='Trigger only a subset of the simulators (note --triggerend)',
25)
26
27parser.add_argument(
28 '--triggerend',
29 help='Last instance to trigger',
30)
31
TamasBakaib59bffb2019-03-22 09:52:03 +000032parser.add_argument(
TamasBakaibab325b2019-03-26 09:20:16 +000033 '--urlves',
34 help='URL of the VES collector',
TamasBakaid38feb62019-02-28 09:06:19 +000035)
36
37parser.add_argument(
TamasBakaib59bffb2019-03-22 09:52:03 +000038 '--ipfileserver',
39 help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event',
40)
41
42parser.add_argument(
RehanRaza4b50bdd2019-05-03 14:28:39 +000043 '--typefileserver',
44 help='Type of the file server (SFTP/FTPS) to be included in the VES event',
45)
46
47parser.add_argument(
TamasBakaid38feb62019-02-28 09:06:19 +000048 '--ipstart',
49 help='IP address range beginning',
50)
51
52parser.add_argument(
53 '--clean',
54 action='store_true',
55 help='Cleaning work-dirs',
56)
57
58parser.add_argument(
59 '--start',
60 help='Starting instances',
61)
62
63parser.add_argument(
64 '--status',
65 help='Status',
66)
67
68parser.add_argument(
69 '--stop',
70 help='Stopping instances',
71)
72
73args = parser.parse_args()
74
TamasBakaibab325b2019-03-26 09:20:16 +000075if args.bootstrap and args.ipstart and args.urlves:
TamasBakaid38feb62019-02-28 09:06:19 +000076 print("Bootstrap:")
77
TamasBakaib59bffb2019-03-22 09:52:03 +000078 start_port=2000
TamasBakaie781c7c2019-07-11 11:26:20 +000079 ftps_pasv_port_start=8000
80 ftps_pasv_port_num_of_ports=10
81
82 ftps_pasv_port_end=ftps_pasv_port_start + ftps_pasv_port_num_of_ports
83
TamasBakaib59bffb2019-03-22 09:52:03 +000084
TamasBakaid38feb62019-02-28 09:06:19 +000085 for i in range(int(args.bootstrap)):
86 print("PNF simulator instance: " + str(i) + ".")
87
88 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
89 print("\tIp Subnet:" + str(ip_subnet))
90 # The IP ranges are in distance of 16 compared to each other.
91 # This is matching the /28 subnet mask used in the dockerfile inside.
92
93 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
94 print("\tIP Gateway:" + str(ip_gw))
95
96 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
97 print("\tIp Pnf SIM:" + str(IpPnfSim))
98
TamasBakaib59bffb2019-03-22 09:52:03 +000099 IpFileServer = args.ipfileserver
RehanRaza4b50bdd2019-05-03 14:28:39 +0000100 TypeFileServer = args.typefileserver
TamasBakaib59bffb2019-03-22 09:52:03 +0000101
102
103 PortSftp=start_port +1
104 PortFtps=start_port +2
105 start_port +=2
TamasBakaibab325b2019-03-26 09:20:16 +0000106 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
107 print("\tUrl Ftps: " + str(UrlFtps))
TamasBakaib59bffb2019-03-22 09:52:03 +0000108
TamasBakaibab325b2019-03-26 09:20:16 +0000109 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
110 print("\tUrl Sftp: " + str(UrlSftp))
TamasBakaid38feb62019-02-28 09:06:19 +0000111
112 foldername = "pnf-sim-lw-" + str(i)
113 completed = subprocess.run('mkdir ' + foldername, shell=True)
114 print('\tCreating folder:', completed.stdout)
115 completed = subprocess.run(
116 'cp -r pnf-sim-lightweight/* ' +
117 foldername,
118 shell=True)
119 print('\tCloning folder:', completed.stdout)
120
TamasBakaibab325b2019-03-26 09:20:16 +0000121 composercmd = "./simulator.sh compose " + \
122 str(ip_gw) + " " + \
123 str(ip_subnet) + " " + \
124 str(i) + " " + \
125 str(args.urlves) + " " + \
126 str(IpPnfSim) + " " + \
127 str(IpFileServer) + " " + \
RehanRaza4b50bdd2019-05-03 14:28:39 +0000128 str(TypeFileServer) + " " + \
TamasBakaibab325b2019-03-26 09:20:16 +0000129 str(PortSftp) + " " + \
130 str(PortFtps) + " " + \
131 str(UrlFtps) + " " + \
TamasBakaie781c7c2019-07-11 11:26:20 +0000132 str(UrlSftp) + " " + \
133 str(ftps_pasv_port_start) + " " + \
134 str(ftps_pasv_port_end)
TamasBakaid38feb62019-02-28 09:06:19 +0000135
136 completed = subprocess.run(
137 'set -x; cd ' +
138 foldername +
139 '; ' +
140 composercmd,
141 shell=True)
142 print('Cloning:', completed.stdout)
TamasBakaie781c7c2019-07-11 11:26:20 +0000143
144 ftps_pasv_port_start += ftps_pasv_port_num_of_ports + 1
145 ftps_pasv_port_end += ftps_pasv_port_num_of_ports +1
TamasBakaid38feb62019-02-28 09:06:19 +0000146
TamasBakaibab325b2019-03-26 09:20:16 +0000147 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
148 print("Build docker image: ", completed.stdout)
149
TamasBakaid38feb62019-02-28 09:06:19 +0000150 sys.exit()
151
152if args.clean:
153 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
154 print('Deleting:', completed.stdout)
155 sys.exit()
156
157if args.start:
158
159 for i in range(int(args.start)):
160 foldername = "pnf-sim-lw-" + str(i)
161
162 completed = subprocess.run(
163 'set -x ; cd ' +
164 foldername +
165 "; bash -x ./simulator.sh start",
166 shell=True)
167 print('Starting:', completed.stdout)
168
169 time.sleep(5)
170
171if args.status:
172
173 for i in range(int(args.status)):
174 foldername = "pnf-sim-lw-" + str(i)
175
176 completed = subprocess.run(
177 'cd ' +
178 foldername +
179 "; ./simulator.sh status",
180 shell=True)
181 print('Status:', completed.stdout)
182
183if args.stop:
184 for i in range(int(args.stop)):
185 foldername = "pnf-sim-lw-" + str(i)
186
187 completed = subprocess.run(
188 'cd ' +
189 foldername +
RehanRaza48f92042019-03-20 08:12:55 +0000190 "; ./simulator.sh stop " + str(i),
TamasBakaid38feb62019-02-28 09:06:19 +0000191 shell=True)
192 print('Stopping:', completed.stdout)
193
TamasBakaib59bffb2019-03-22 09:52:03 +0000194
195if args.trigger:
196 print("Triggering VES sending:")
197
198 for i in range(int(args.trigger)):
199 foldername = "pnf-sim-lw-" + str(i)
200
201 completed = subprocess.run(
202 'cd ' +
203 foldername +
204 "; ./simulator.sh trigger-simulator",
205 shell=True)
206 print('Status:', completed.stdout)
TamasBakai34a6f112019-04-15 08:38:51 +0000207
208if args.triggerstart and args.triggerend:
209 print("Triggering VES sending by a range of simulators:")
210
211 for i in range(int(args.triggerstart), int(args.triggerend)+1):
212 foldername = "pnf-sim-lw-" + str(i)
213 print("Instance being processed:" + str(i))
214
215 completed = subprocess.run(
216 'cd ' +
217 foldername +
218 "; ./simulator.sh trigger-simulator",
219 shell=True)
220 print('Status:', completed.stdout)
221
222
TamasBakaib59bffb2019-03-22 09:52:03 +0000223
TamasBakaid38feb62019-02-28 09:06:19 +0000224else:
225 print("No instruction was defined")
226 sys.exit()