blob: a02e3fdd255d28c3c467eafa5118bf460bf2d5a6 [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
79
TamasBakaid38feb62019-02-28 09:06:19 +000080 for i in range(int(args.bootstrap)):
81 print("PNF simulator instance: " + str(i) + ".")
82
83 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
84 print("\tIp Subnet:" + str(ip_subnet))
85 # The IP ranges are in distance of 16 compared to each other.
86 # This is matching the /28 subnet mask used in the dockerfile inside.
87
88 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
89 print("\tIP Gateway:" + str(ip_gw))
90
91 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
92 print("\tIp Pnf SIM:" + str(IpPnfSim))
93
TamasBakaib59bffb2019-03-22 09:52:03 +000094 IpFileServer = args.ipfileserver
RehanRaza4b50bdd2019-05-03 14:28:39 +000095 TypeFileServer = args.typefileserver
TamasBakaib59bffb2019-03-22 09:52:03 +000096
97
98 PortSftp=start_port +1
99 PortFtps=start_port +2
100 start_port +=2
TamasBakaibab325b2019-03-26 09:20:16 +0000101 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
102 print("\tUrl Ftps: " + str(UrlFtps))
TamasBakaib59bffb2019-03-22 09:52:03 +0000103
TamasBakaibab325b2019-03-26 09:20:16 +0000104 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
105 print("\tUrl Sftp: " + str(UrlSftp))
TamasBakaid38feb62019-02-28 09:06:19 +0000106
107 foldername = "pnf-sim-lw-" + str(i)
108 completed = subprocess.run('mkdir ' + foldername, shell=True)
109 print('\tCreating folder:', completed.stdout)
110 completed = subprocess.run(
111 'cp -r pnf-sim-lightweight/* ' +
112 foldername,
113 shell=True)
114 print('\tCloning folder:', completed.stdout)
115
TamasBakaibab325b2019-03-26 09:20:16 +0000116 composercmd = "./simulator.sh compose " + \
117 str(ip_gw) + " " + \
118 str(ip_subnet) + " " + \
119 str(i) + " " + \
120 str(args.urlves) + " " + \
121 str(IpPnfSim) + " " + \
122 str(IpFileServer) + " " + \
RehanRaza4b50bdd2019-05-03 14:28:39 +0000123 str(TypeFileServer) + " " + \
TamasBakaibab325b2019-03-26 09:20:16 +0000124 str(PortSftp) + " " + \
125 str(PortFtps) + " " + \
126 str(UrlFtps) + " " + \
127 str(UrlSftp)
TamasBakaid38feb62019-02-28 09:06:19 +0000128
129 completed = subprocess.run(
130 'set -x; cd ' +
131 foldername +
132 '; ' +
133 composercmd,
134 shell=True)
135 print('Cloning:', completed.stdout)
136
TamasBakaibab325b2019-03-26 09:20:16 +0000137 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
138 print("Build docker image: ", completed.stdout)
139
TamasBakaid38feb62019-02-28 09:06:19 +0000140 sys.exit()
141
142if args.clean:
143 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
144 print('Deleting:', completed.stdout)
145 sys.exit()
146
147if args.start:
148
149 for i in range(int(args.start)):
150 foldername = "pnf-sim-lw-" + str(i)
151
152 completed = subprocess.run(
153 'set -x ; cd ' +
154 foldername +
155 "; bash -x ./simulator.sh start",
156 shell=True)
157 print('Starting:', completed.stdout)
158
159 time.sleep(5)
160
161if args.status:
162
163 for i in range(int(args.status)):
164 foldername = "pnf-sim-lw-" + str(i)
165
166 completed = subprocess.run(
167 'cd ' +
168 foldername +
169 "; ./simulator.sh status",
170 shell=True)
171 print('Status:', completed.stdout)
172
173if args.stop:
174 for i in range(int(args.stop)):
175 foldername = "pnf-sim-lw-" + str(i)
176
177 completed = subprocess.run(
178 'cd ' +
179 foldername +
RehanRaza48f92042019-03-20 08:12:55 +0000180 "; ./simulator.sh stop " + str(i),
TamasBakaid38feb62019-02-28 09:06:19 +0000181 shell=True)
182 print('Stopping:', completed.stdout)
183
TamasBakaib59bffb2019-03-22 09:52:03 +0000184
185if args.trigger:
186 print("Triggering VES sending:")
187
188 for i in range(int(args.trigger)):
189 foldername = "pnf-sim-lw-" + str(i)
190
191 completed = subprocess.run(
192 'cd ' +
193 foldername +
194 "; ./simulator.sh trigger-simulator",
195 shell=True)
196 print('Status:', completed.stdout)
TamasBakai34a6f112019-04-15 08:38:51 +0000197
198if args.triggerstart and args.triggerend:
199 print("Triggering VES sending by a range of simulators:")
200
201 for i in range(int(args.triggerstart), int(args.triggerend)+1):
202 foldername = "pnf-sim-lw-" + str(i)
203 print("Instance being processed:" + str(i))
204
205 completed = subprocess.run(
206 'cd ' +
207 foldername +
208 "; ./simulator.sh trigger-simulator",
209 shell=True)
210 print('Status:', completed.stdout)
211
212
TamasBakaib59bffb2019-03-22 09:52:03 +0000213
TamasBakaid38feb62019-02-28 09:06:19 +0000214else:
215 print("No instruction was defined")
216 sys.exit()