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',
23 help='URL of the VES collector',
28 help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event',
33 help='IP address range beginning',
39 help='Cleaning work-dirs',
44 help='Starting instances',
54 help='Stopping instances',
57 args = parser.parse_args()
59 if args.bootstrap and args.ipstart and args.urlves:
64 for i in range(int(args.bootstrap)):
65 print("PNF simulator instance: " + str(i) + ".")
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.
72 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
73 print("\tIP Gateway:" + str(ip_gw))
75 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
76 print("\tIp Pnf SIM:" + str(IpPnfSim))
78 IpFileServer = args.ipfileserver
81 PortSftp=start_port +1
82 PortFtps=start_port +2
84 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
85 print("\tUrl Ftps: " + str(UrlFtps))
87 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
88 print("\tUrl Sftp: " + str(UrlSftp))
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/* ' +
97 print('\tCloning folder:', completed.stdout)
99 composercmd = "./simulator.sh compose " + \
101 str(ip_subnet) + " " + \
103 str(args.urlves) + " " + \
104 str(IpPnfSim) + " " + \
105 str(IpFileServer) + " " + \
106 str(PortSftp) + " " + \
107 str(PortFtps) + " " + \
108 str(UrlFtps) + " " + \
111 completed = subprocess.run(
117 print('Cloning:', completed.stdout)
119 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
120 print("Build docker image: ", completed.stdout)
125 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
126 print('Deleting:', completed.stdout)
131 for i in range(int(args.start)):
132 foldername = "pnf-sim-lw-" + str(i)
134 completed = subprocess.run(
137 "; bash -x ./simulator.sh start",
139 print('Starting:', completed.stdout)
145 for i in range(int(args.status)):
146 foldername = "pnf-sim-lw-" + str(i)
148 completed = subprocess.run(
151 "; ./simulator.sh status",
153 print('Status:', completed.stdout)
156 for i in range(int(args.stop)):
157 foldername = "pnf-sim-lw-" + str(i)
159 completed = subprocess.run(
162 "; ./simulator.sh stop " + str(i),
164 print('Stopping:', completed.stdout)
168 print("Triggering VES sending:")
170 for i in range(int(args.trigger)):
171 foldername = "pnf-sim-lw-" + str(i)
173 completed = subprocess.run(
176 "; ./simulator.sh trigger-simulator",
178 print('Status:', completed.stdout)
181 print("No instruction was defined")