forked from cnp3/CampusNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_puppet.py
53 lines (47 loc) · 1.42 KB
/
update_puppet.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
bgp = ['Pythagore', 'Halles']
nodes = ['Carnoy', 'SH1C', 'Stevin', 'Michotte']
monitors = ['MO1', 'MO2']
ns = ['NS1', 'NS2']
pp = 'ucl_group9/%s/puppet/site.pp'
yaml = 'ucl_group9/%s/puppet/data/node.yaml'
data_bgp = """# SNMP specific infos
snmp::sysLocation: %s building
snmp::sysContact: Group 9 <[email protected]>
snmp::trap_functions:
- bgp
- ospf
snmp::is_monitor: false"""
data_node = """# SNMP specific infos
snmp::sysLocation: %s building
snmp::sysContact: Group 9 <[email protected]>
snmp::trap_functions:
- ospf
snmp::is_monitor: false"""
data_monitor = """---
name: %s
# SNMP specific infos
snmp::sysLocation: %s building
snmp::sysContact: Group 9 <[email protected]>
snmp::trap_functions:
- dns
snmp::is_monitor: true"""
data_ns = """---
name: %s
# SNMP specific infos
snmp::sysLocation: %s building
snmp::sysContact: Group 9 <[email protected]>
snmp::trap_functions: []
snmp::is_monitor: false"""
pp_text = """$default_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Exec { path => $default_path }
include snmp
"""
def write_data(filename, data):
with open(filename, 'a') as f:
f.write(data)
for node in monitors:
write_data(pp % node, pp_text)
write_data(yaml % node, data_monitor % (node, node))
for node in ns:
write_data(pp % node, pp_text)
write_data(yaml % node, data_ns % (node, node))