-
Notifications
You must be signed in to change notification settings - Fork 2
/
dup
executable file
·45 lines (40 loc) · 1.5 KB
/
dup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
import argparse
import time
from util import *
parser = argparse.ArgumentParser(description='create duplicate resources')
parser.add_argument('file', metavar='file', type=str, nargs=1,
help='template file for creating duplicates')
parser.add_argument('--replicas', metavar='replicas', type=int, nargs=1,
help='number of duplicates')
parser.add_argument('--interval', metavar='interval', type=int, default=0, nargs=1,
help='creation interval')
parser.add_argument("--teardown", dest='teardown', action='store_true',
help='clean up duplicate objects')
args = parser.parse_args()
filename = args.file[0]
f = open(filename, "r")
template = f.read()
f.close()
for i in range(args.replicas[0]):
opStr = "Creating"
if args.teardown:
opStr = "Deleting"
print("==============%s %d" % (opStr, i))
# if args.interval[0] > 0:
# time.sleep(float(args.interval[0]))
tmpfile = filename + ".tmp"
f = open(tmpfile, "w")
f.write(template.replace("{$}", str(i)))
f.close()
output = ""
try:
if args.teardown:
output = subprocess.check_output(KUBECTL_DELETE + tmpfile, stderr=subprocess.STDOUT, shell=True)
else:
output = subprocess.check_output(KUBECTL_APPLY + tmpfile, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as err:
print("Failed" + err.output)
finally:
print(output)
os.remove(tmpfile)