blob: 773b97193e5542486a0b069ff53ba8630ac880c3 [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(
TamasBakaid38feb62019-02-28 09:06:19 +000043 '--ipstart',
44 help='IP address range beginning',
45)
46
47parser.add_argument(
48 '--clean',
49 action='store_true',
50 help='Cleaning work-dirs',
51)
52
53parser.add_argument(
54 '--start',
55 help='Starting instances',
56)
57
58parser.add_argument(
59 '--status',
60 help='Status',
61)
62
63parser.add_argument(
64 '--stop',
65 help='Stopping instances',
66)
67
68args = parser.parse_args()
69
TamasBakaibab325b2019-03-26 09:20:16 +000070if args.bootstrap and args.ipstart and args.urlves:
TamasBakaid38feb62019-02-28 09:06:19 +000071 print("Bootstrap:")
72
TamasBakaib59bffb2019-03-22 09:52:03 +000073 start_port=2000
74
TamasBakaid38feb62019-02-28 09:06:19 +000075 for i in range(int(args.bootstrap)):
76 print("PNF simulator instance: " + str(i) + ".")
77
78 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
79 print("\tIp Subnet:" + str(ip_subnet))
80 # The IP ranges are in distance of 16 compared to each other.
81 # This is matching the /28 subnet mask used in the dockerfile inside.
82
83 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
84 print("\tIP Gateway:" + str(ip_gw))
85
86 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
87 print("\tIp Pnf SIM:" + str(IpPnfSim))
88
TamasBakaib59bffb2019-03-22 09:52:03 +000089 IpFileServer = args.ipfileserver
90
91
92 PortSftp=start_port +1
93 PortFtps=start_port +2
94 start_port +=2
TamasBakaibab325b2019-03-26 09:20:16 +000095 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
96 print("\tUrl Ftps: " + str(UrlFtps))
TamasBakaib59bffb2019-03-22 09:52:03 +000097
TamasBakaibab325b2019-03-26 09:20:16 +000098 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
99 print("\tUrl Sftp: " + str(UrlSftp))
TamasBakaid38feb62019-02-28 09:06:19 +0000100
101 foldername = "pnf-sim-lw-" + str(i)
102 completed = subprocess.run('mkdir ' + foldername, shell=True)
103 print('\tCreating folder:', completed.stdout)
104 completed = subprocess.run(
105 'cp -r pnf-sim-lightweight/* ' +
106 foldername,
107 shell=True)
108 print('\tCloning folder:', completed.stdout)
109
TamasBakaibab325b2019-03-26 09:20:16 +0000110 composercmd = "./simulator.sh compose " + \
111 str(ip_gw) + " " + \
112 str(ip_subnet) + " " + \
113 str(i) + " " + \
114 str(args.urlves) + " " + \
115 str(IpPnfSim) + " " + \
116 str(IpFileServer) + " " + \
117 str(PortSftp) + " " + \
118 str(PortFtps) + " " + \
119 str(UrlFtps) + " " + \
120 str(UrlSftp)
TamasBakaid38feb62019-02-28 09:06:19 +0000121
122 completed = subprocess.run(
123 'set -x; cd ' +
124 foldername +
125 '; ' +
126 composercmd,
127 shell=True)
128 print('Cloning:', completed.stdout)
129
TamasBakaibab325b2019-03-26 09:20:16 +0000130 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
131 print("Build docker image: ", completed.stdout)
132
TamasBakaid38feb62019-02-28 09:06:19 +0000133 sys.exit()
134
135if args.clean:
136 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
137 print('Deleting:', completed.stdout)
138 sys.exit()
139
140if args.start:
141
142 for i in range(int(args.start)):
143 foldername = "pnf-sim-lw-" + str(i)
144
145 completed = subprocess.run(
146 'set -x ; cd ' +
147 foldername +
148 "; bash -x ./simulator.sh start",
149 shell=True)
150 print('Starting:', completed.stdout)
151
152 time.sleep(5)
153
154if args.status:
155
156 for i in range(int(args.status)):
157 foldername = "pnf-sim-lw-" + str(i)
158
159 completed = subprocess.run(
160 'cd ' +
161 foldername +
162 "; ./simulator.sh status",
163 shell=True)
164 print('Status:', completed.stdout)
165
166if args.stop:
167 for i in range(int(args.stop)):
168 foldername = "pnf-sim-lw-" + str(i)
169
170 completed = subprocess.run(
171 'cd ' +
172 foldername +
RehanRaza48f92042019-03-20 08:12:55 +0000173 "; ./simulator.sh stop " + str(i),
TamasBakaid38feb62019-02-28 09:06:19 +0000174 shell=True)
175 print('Stopping:', completed.stdout)
176
TamasBakaib59bffb2019-03-22 09:52:03 +0000177
178if args.trigger:
179 print("Triggering VES sending:")
180
181 for i in range(int(args.trigger)):
182 foldername = "pnf-sim-lw-" + str(i)
183
184 completed = subprocess.run(
185 'cd ' +
186 foldername +
187 "; ./simulator.sh trigger-simulator",
188 shell=True)
189 print('Status:', completed.stdout)
TamasBakai34a6f112019-04-15 08:38:51 +0000190
191if args.triggerstart and args.triggerend:
192 print("Triggering VES sending by a range of simulators:")
193
194 for i in range(int(args.triggerstart), int(args.triggerend)+1):
195 foldername = "pnf-sim-lw-" + str(i)
196 print("Instance being processed:" + str(i))
197
198 completed = subprocess.run(
199 'cd ' +
200 foldername +
201 "; ./simulator.sh trigger-simulator",
202 shell=True)
203 print('Status:', completed.stdout)
204
205
TamasBakaib59bffb2019-03-22 09:52:03 +0000206
TamasBakaid38feb62019-02-28 09:06:19 +0000207else:
208 print("No instruction was defined")
209 sys.exit()