-
Notifications
You must be signed in to change notification settings - Fork 4
/
csv-to-instack.py
51 lines (44 loc) · 1.33 KB
/
csv-to-instack.py
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
46
47
48
49
50
51
import csv
import json
import sys
import getopt
from collections import defaultdict
def main(argv):
inputfile = None
try:
opts, args = getopt.getopt(argv,"c",["csv="])
except :
print >> sys.stderr, "csv-to-instack.py --csv=<inputfile>"
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print >> sys.stderr ,'csv-to-instack.py --csv=<inputfile>'
sys.exit()
elif opt in ("-c", "--csv"):
inputfile = arg
if inputfile == None :
print >> sys.stderr, "Error : No input file passed"
print >> sys.stderr, "Usage:"
print >> sys.stderr, "csv-to-instack.py --csv=<inputfile>"
sys.exit(2)
print >> sys.stderr, "Opening %s" % inputfile
csvFile = open(inputfile)
data = list(csv.reader(csvFile))
firstrow = True
jdata = defaultdict(list)
for value in data:
if firstrow :
firstrow = False
continue
jdata['nodes'].append({'pm_password' : value[3],
'pm_type' : value[4],
'mac' : [value[0]],
'cpu' : "2",
'memory' : "1024",
'disk' : "20",
'arch' : "x86_64",
'pm_user' : value[2],
'pm_addr' : value[1]})
print json.dumps(jdata,indent=4, sort_keys=True)
if __name__ == "__main__":
main(sys.argv[1:])