-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_core_conf.py
More file actions
39 lines (29 loc) · 978 Bytes
/
generate_core_conf.py
File metadata and controls
39 lines (29 loc) · 978 Bytes
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
from ditto import readConfig, getFilename
from jinja2 import Template
def generateCoreConfig(ports, hostname, ip, subnet, gateway, template):
temp = Template(open(template, 'r').read())
print(temp.render(
tableports = ports,
hostname = hostname,
ip = ip,
subnet = subnet,
gateway = gateway
))
def generatePort(name, switch, dhcpserver):
port = """
interface GigabitEthernet0/%s
description %s
no switchport
ip address %s %s
ip helper-address %s
!
""" % (switch['port'], name, switch['gateway'], switch['netmask'], dhcpserver)
return port
def main():
fn = getFilename()
conf = readConfig(fn)
ports = ""
for switch in conf["switch"]:
ports += generatePort(switch, conf["switch"][switch], conf['general']['dhcp'])
generateCoreConfig(ports, 'core', conf['general']['core'], '255.255.255.128', conf['general']['gateway'], 'template/c3560g.txt')
main()