4 from subprocess import *
5 from subprocess import STDOUT
10 parser = argparse.ArgumentParser()
13 help='Bootstrapping the system',
18 help='Trigger one single VES event from each simulator',
24 help='Trigger only a subset of the simulators (note --triggerend)',
29 help='Last instance to trigger',
34 help='URL of the VES collector',
39 help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event',
44 help='IP address range beginning',
50 help='Cleaning work-dirs',
55 help='Starting instances',
65 help='Stopping instances',
68 args = parser.parse_args()
70 if args.bootstrap and args.ipstart and args.urlves:
75 for i in range(int(args.bootstrap)):
76 print("PNF simulator instance: " + str(i) + ".")
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.
83 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
84 print("\tIP Gateway:" + str(ip_gw))
86 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
87 print("\tIp Pnf SIM:" + str(IpPnfSim))
89 IpFileServer = args.ipfileserver
92 PortSftp=start_port +1
93 PortFtps=start_port +2
95 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
96 print("\tUrl Ftps: " + str(UrlFtps))
98 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
99 print("\tUrl Sftp: " + str(UrlSftp))
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/* ' +
108 print('\tCloning folder:', completed.stdout)
110 composercmd = "./simulator.sh compose " + \
112 str(ip_subnet) + " " + \
114 str(args.urlves) + " " + \
115 str(IpPnfSim) + " " + \
116 str(IpFileServer) + " " + \
117 str(PortSftp) + " " + \
118 str(PortFtps) + " " + \
119 str(UrlFtps) + " " + \
122 completed = subprocess.run(
128 print('Cloning:', completed.stdout)
130 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
131 print("Build docker image: ", completed.stdout)
136 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
137 print('Deleting:', completed.stdout)
142 for i in range(int(args.start)):
143 foldername = "pnf-sim-lw-" + str(i)
145 completed = subprocess.run(
148 "; bash -x ./simulator.sh start",
150 print('Starting:', completed.stdout)
156 for i in range(int(args.status)):
157 foldername = "pnf-sim-lw-" + str(i)
159 completed = subprocess.run(
162 "; ./simulator.sh status",
164 print('Status:', completed.stdout)
167 for i in range(int(args.stop)):
168 foldername = "pnf-sim-lw-" + str(i)
170 completed = subprocess.run(
173 "; ./simulator.sh stop " + str(i),
175 print('Stopping:', completed.stdout)
179 print("Triggering VES sending:")
181 for i in range(int(args.trigger)):
182 foldername = "pnf-sim-lw-" + str(i)
184 completed = subprocess.run(
187 "; ./simulator.sh trigger-simulator",
189 print('Status:', completed.stdout)
191 if args.triggerstart and args.triggerend:
192 print("Triggering VES sending by a range of simulators:")
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))
198 completed = subprocess.run(
201 "; ./simulator.sh trigger-simulator",
203 print('Status:', completed.stdout)
208 print("No instruction was defined")