-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathac-generate.py
73 lines (55 loc) · 2.25 KB
/
ac-generate.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import time
'''
Generates folders and config files for each device in lists
Not a part of the main auto configurator, run this manually
'''
def openConfig(config_in):
with open(config_in) as ci:
config = ci.read()
ci.close()
return(config)
def main():
fleet_config = openConfig('./configs/templates/fleet')
command_config = openConfig('./configs/templates/command')
folder_all = './configs/all'
with open('./lists/master.csv', 'r') as master:
for row in master:
stripped_row = row.strip()
split_row = row.split(',')
vehicle = split_row[0]
command_ip = split_row[1]
fleet_ip = split_row[2].strip()
fleet_hostname = 'cb-{}-fleet'.format(vehicle.lower())
command_hostname = 'cb-{}-command'.format(vehicle.lower())
# Folder
folder_out = './configs/folders/{}'.format(vehicle)
# Files
fleet_file = '{}/cb-{}-fleet.txt'.format(folder_out, vehicle.lower())
command_file = '{}/cb-{}-command.txt'.format(folder_out, vehicle.lower())
fleet_all = './configs/all/cb-{}-fleet.txt'.format(vehicle.lower())
command_all = './configs/all/cb-{}-command.txt'.format(vehicle.lower())
# Generate configs
new_fleet = fleet_config.format(hostname=fleet_hostname, ip=fleet_ip)
new_command = command_config.format(hostname=command_hostname, ip=command_ip)
# Create vehicle folder
if not os.path.exists(folder_out):
os.makedirs(folder_out)
# Fleet config in folder
with open(fleet_file, 'w') as ff:
ff.write(new_fleet)
ff.close()
# Command config in folder
with open(command_file, 'w') as cf:
cf.write(new_command)
cf.close()
# Fleet in all folder
with open(fleet_all, 'w') as fa:
fa.write(new_fleet)
fa.close()
# Command in all folder
with open(command_all, 'w') as ca:
ca.write(new_command)
ca.close()
if __name__ == '__main__':
main()