Commit 4f5f6c91 authored by Bill Grant's avatar Bill Grant

part3 complete

parent 092506b4
ip routing
!
lldp run
!
vlan 100
name Servers1
!
vlan 200
name Servers2
!
interface Ethernet1
description P2P Link to Spine-1
logging event link-status
no switchport
ip address 172.16.0.2/30
arp timeout 900
mtu 9214
no shutdown
!
interface Ethernet2
description P2P Link to Spine-2
logging event link-status
no switchport
ip address 172.16.0.10/30
arp timeout 900
mtu 9214
no shutdown
!
interface loopback0
ip address 192.168.0.3/32
!
interface Vlan100
description Servers1
mtu 9214
ip address 10.1.100.1/24
arp timeout 900
no shutdown
!
route-map ROUTE-MAP-OUT permit 10
match ip address prefix-list PREFIX-LIST-OUT
!
ip prefix-list PREFIX-LIST-OUT seq 10 permit 192.168.0.3/32
ip prefix-list PREFIX-LIST-OUT seq 20 permit 172.16.0.0/16
ip prefix-list PREFIX-LIST-OUT seq 30 permit 10.1.100.0/24
!
router bgp 65100
bgp log-neighbor-changes
distance bgp 20 200 200
maximum-paths 4 ecmp 4
neighbor EBGP-TO-SPINE peer-group
neighbor EBGP-TO-SPINE remote-as 65000
neighbor EBGP-TO-SPINE maximum-routes 12000
neighbor EBGP-TO-SPINE allowas-in 1
neighbor 172.16.0.1 peer-group EBGP-TO-SPINE
neighbor 172.16.0.9 peer-group EBGP-TO-SPINE
network 192.168.0.3/32
redistribute connected
!
end
\ No newline at end of file
ip routing
!
lldp run
!
vlan 100
name Servers1
!
vlan 200
name Servers2
!
interface Ethernet1
description P2P Link to Spine-1
logging event link-status
no switchport
ip address 172.16.0.6/30
arp timeout 900
mtu 9214
no shutdown
!
interface Ethernet2
description P2P Link to Spine-2
logging event link-status
no switchport
ip address 172.16.0.14/30
arp timeout 900
mtu 9214
no shutdown
!
interface loopback0
ip address 192.168.0.4/32
!
interface Vlan100
description Servers1
mtu 9214
ip address 10.2.100.1/24
arp timeout 900
no shutdown
!
route-map ROUTE-MAP-OUT permit 10
match ip address prefix-list PREFIX-LIST-OUT
!
ip prefix-list PREFIX-LIST-OUT seq 10 permit 192.168.0.4/32
ip prefix-list PREFIX-LIST-OUT seq 20 permit 172.16.0.0/16
ip prefix-list PREFIX-LIST-OUT seq 30 permit
!
router bgp 65100
bgp log-neighbor-changes
distance bgp 20 200 200
maximum-paths 4 ecmp 4
neighbor EBGP-TO-SPINE peer-group
neighbor EBGP-TO-SPINE remote-as 65000
neighbor EBGP-TO-SPINE maximum-routes 12000
neighbor EBGP-TO-SPINE allowas-in 1
neighbor 172.16.0.5 peer-group EBGP-TO-SPINE
neighbor 172.16.0.13 peer-group EBGP-TO-SPINE
network 192.168.0.4/32
redistribute connected
!
end
\ No newline at end of file
......@@ -14,6 +14,8 @@ class ConfigureLeafSpine():
baseconfig,
spines,
spineconfig,
leafs,
leafconfig
):
with open(hosts) as file1:
self.hosts = yaml.load(file1)
......@@ -21,8 +23,11 @@ class ConfigureLeafSpine():
self.groups = yaml.load(file2)
with open(spines) as file3:
self.spines = yaml.load(file3)
with open(leafs) as file4:
self.leafs = yaml.load(file4)
self.baseconfig = baseconfig
self.spineconfig = spineconfig
self.leafconfig = leafconfig
self.ENV = Environment(loader=FileSystemLoader('.'))
def generatebaseconfig(self):
......@@ -52,6 +57,21 @@ class ConfigureLeafSpine():
with open(filename, 'w') as file:
file.writelines(config)
def generateleafconfig(self):
"""Generates the leaf configuration"""
template = self.ENV.get_template(self.leafconfig)
for key, value in self.hosts.items():
if value['role'] == 'leaf':
config = template.render(
host=value,
vlans=self.leafs['vlans'],
routemaps=self.leafs['routemaps'],
bgp=self.leafs['bgp']
)
filename = 'configs/{0}.config'.format(key)
with open(filename, 'w') as file:
file.writelines(config)
if __name__ == "__main__":
lsconfig = ConfigureLeafSpine(
......@@ -59,7 +79,10 @@ if __name__ == "__main__":
'groups.yaml',
'baseconfig.j2',
'spine.yaml',
'spine.j2'
'spine.j2',
'leaf.yaml',
'leaf.j2'
)
lsconfig.generatebaseconfig()
lsconfig.generatespineconfig()
lsconfig.generateleafconfig()
......@@ -55,8 +55,94 @@ leaf-1:
managementgw: 198.51.100.1
site: ny
role: leaf
interfaces:
- number: 1
ip: 172.16.0.2/30
description: P2P Link to Spine-1
- number: 2
ip: 172.16.0.10/30
description: P2P Link to Spine-2
loopbacks:
- number: 0
ip: 192.168.0.3/32
routerid: 192.168.0.3
bgpnetworks:
- 192.168.0.3/32
peergroups:
- name: EBGP-TO-SPINE
maxroutes: 12000
remoteas: 65000
neighbors:
- 172.16.0.1
- 172.16.0.9
allowasin: 1
routemaps:
- name: ROUTE-MAP-OUT
direction: out
prefixlists:
- name: PREFIX-LIST-OUT
action: permit
sequence: 10
ip: 192.168.0.3/32
- name: PREFIX-LIST-OUT
action: permit
sequence: 20
ip: 172.16.0.0/16
- name: PREFIX-LIST-OUT
action: permit
sequence: 30
ip: 10.1.100.0/24
vlaninterfaces:
- number: 100
description: Servers1
mtu: 9214
ip: 10.1.100.1/24
arptimeout: 900
leaf-2:
managementip: 198.51.100.251/24
managementgw: 198.51.100.1
site: ny
role: leaf
interfaces:
- number: 1
ip: 172.16.0.6/30
description: P2P Link to Spine-1
- number: 2
ip: 172.16.0.14/30
description: P2P Link to Spine-2
loopbacks:
- number: 0
ip: 192.168.0.4/32
routerid: 192.168.0.6
bgpnetworks:
- 192.168.0.4/32
peergroups:
- name: EBGP-TO-SPINE
maxroutes: 12000
remoteas: 65000
neighbors:
- 172.16.0.5
- 172.16.0.13
allowasin: 1
routemaps:
- name: ROUTE-MAP-OUT
direction: out
prefixlists:
- name: PREFIX-LIST-OUT
action: permit
sequence: 10
ip: 192.168.0.4/32
- name: PREFIX-LIST-OUT
action: permit
sequence: 20
ip: 172.16.0.0/16
- name: PREFIX-LIST-OUT
action: permit
sequence: 30
vlaninterfaces:
- number: 100
description: Servers1
mtu: 9214
ip: 10.2.100.1/24
arptimeout: 900
ip routing
!
lldp run
!
{% for vlan in vlans -%}
vlan {{ vlan.number }}
name {{ vlan.description }}
!
{% endfor -%}
{% for interface in host.interfaces -%}
interface Ethernet{{ interface.number }}
description {{ interface.description }}
logging event link-status
no switchport
ip address {{ interface.ip }}
arp timeout 900
mtu 9214
no shutdown
!
{% endfor -%}
{% for loopback in host.loopbacks -%}
interface loopback{{ loopback.number }}
ip address {{ loopback.ip }}
!
{% endfor -%}
{% for vlaninterface in host.vlaninterfaces -%}
interface Vlan{{ vlaninterface.number }}
description {{ vlaninterface.description }}
{% if vlaninterface.mtu -%}
mtu {{ vlaninterface.mtu }}
{% endif -%}
ip address {{ vlaninterface.ip }}
arp timeout 900
no shutdown
!
{% endfor -%}
{% for routemap in routemaps -%}
route-map {{ routemap.name }} {{ routemap.filter }} 10
{% if routemap.action == 'matchip' -%}
match ip address {{ routemap.type }} {{ routemap.actionname }}
{% endif -%}
!
{% endfor -%}
{% for prefixlist in host.prefixlists -%}
ip prefix-list {{ prefixlist.name }} seq {{ prefixlist.sequence }} {{ prefixlist.action }} {{ prefixlist.ip }}
{% endfor -%}
!
router bgp {{ bgp.as }}
bgp log-neighbor-changes
distance bgp {{ bgp.distance }}
maximum-paths {{ bgp.maxpaths }} ecmp {{ bgp.maxroutes }}
{% for peergroup in host.peergroups -%}
neighbor {{ peergroup.name}} peer-group
neighbor {{ peergroup.name }} remote-as {{ peergroup.remoteas }}
neighbor {{ peergroup.name }} maximum-routes {{ peergroup.maxroutes }}
neighbor {{ peergroup.name }} allowas-in {{ peergroup.allowasin }}
{% for routemap in peergroup.routemap -%}
neighbor {{ peergroup.name }} route-map {{ routemap.name }} {{ routemap.direction }}
{% endfor -%}
{% for neighbor in peergroup.neighbors -%}
neighbor {{ neighbor }} peer-group {{ peergroup.name }}
{% endfor -%}
{% endfor -%}
{% for network in host.bgpnetworks -%}
network {{ network }}
{% endfor -%}
redistribute {{ bgp.redistribute }}
!
end
\ No newline at end of file
---
vlans:
- number: 100
description: Servers1
- number: 200
description: Servers2
routemaps:
- name: ROUTE-MAP-OUT
filter: permit
sequence: 10
action: matchip
type: prefix-list
actionname: PREFIX-LIST-OUT
bgp:
as: 65100
distance: 20 200 200
maxpaths: 4
maxroutes: 4
redistribute: connected
\ No newline at end of file
---
spine-1:
managementip: 198.51.100.254/24
managementgw: 198.51.100.1
site: ny
spine-2:
managementip: 198.51.100.253/24
managementgw: 198.51.100.1
site: ny
leaf-1:
managementip: 198.51.100.252/24
managementgw: 198.51.100.1
site: ny
leaf-2:
managementip: 198.51.100.251/24
managementgw: 198.51.100.1
site: ny
\ No newline at end of file
! Base configuration
!
hostname {{ hostname }}
ip name-server {{ defaults.nameserver1 }}
ip name-server {{ defaults.nameserver2 }}
ip domain-name {{ defaults.domainname }}
!
ntp source Management1
ntp server {{ defaults.ntpserver1 }} prefer
ntp server {{ defaults.ntpserver2 }}
!
username admin role network-admin secret {{ defaults.password }}
!
clock timezone {{ site.timezone }}
!
vrf definition management
!
! Use https in production
!
management api http-commands
protocol http
no shutdown
!
vrf management
no shutdown
!
interface Management1
vrf forwarding management
ip address {{ host.managementip }}
!
ip route vrf management 0.0.0.0/0 {{ host.managementgw }}
!
end
\ No newline at end of file
ip routing
!
lldp run
!
vlan 100
name Servers1
!
vlan 200
name Servers2
!
interface Ethernet1
description P2P Link to Spine-1
logging event link-status
no switchport
ip address 172.16.0.2/30
arp timeout 900
mtu 9214
no shutdown
!
interface Ethernet2
description P2P Link to Spine-2
logging event link-status
no switchport
ip address 172.16.0.10/30
arp timeout 900
mtu 9214
no shutdown
!
interface loopback0
ip address 192.168.0.3/32
!
interface Vlan100
description Servers1
mtu 9214
ip address 10.1.100.1/24
arp timeout 900
no shutdown
!
route-map ROUTE-MAP-OUT permit 10
match ip address prefix-list PREFIX-LIST-OUT
!
ip prefix-list PREFIX-LIST-OUT seq 10 permit 192.168.0.3/32
ip prefix-list PREFIX-LIST-OUT seq 20 permit 172.16.0.0/16
ip prefix-list PREFIX-LIST-OUT seq 30 permit 10.1.100.0/24
!
router bgp 65100
bgp log-neighbor-changes
distance bgp 20 200 200
maximum-paths 4 ecmp 4
neighbor EBGP-TO-SPINE peer-group
neighbor EBGP-TO-SPINE remote-as 65000
neighbor EBGP-TO-SPINE maximum-routes 12000
neighbor EBGP-TO-SPINE allowas-in 1
neighbor 172.16.0.1 peer-group EBGP-TO-SPINE
neighbor 172.16.0.9 peer-group EBGP-TO-SPINE
network 192.168.0.3/32
redistribute connected
!
end
\ No newline at end of file
ip routing
!
lldp run
!
vlan 100
name Servers1
!
vlan 200
name Servers2
!
interface Ethernet1
description P2P Link to Spine-1
logging event link-status
no switchport
ip address 172.16.0.6/30
arp timeout 900
mtu 9214
no shutdown
!
interface Ethernet2
description P2P Link to Spine-2
logging event link-status
no switchport
ip address 172.16.0.14/30
arp timeout 900
mtu 9214
no shutdown
!
interface loopback0
ip address 192.168.0.4/32
!
interface Vlan100
description Servers1
mtu 9214
ip address 10.2.100.1/24
arp timeout 900
no shutdown
!
route-map ROUTE-MAP-OUT permit 10
match ip address prefix-list PREFIX-LIST-OUT
!
ip prefix-list PREFIX-LIST-OUT seq 10 permit 192.168.0.4/32
ip prefix-list PREFIX-LIST-OUT seq 20 permit 172.16.0.0/16
ip prefix-list PREFIX-LIST-OUT seq 30 permit
!
router bgp 65100
bgp log-neighbor-changes
distance bgp 20 200 200
maximum-paths 4 ecmp 4
neighbor EBGP-TO-SPINE peer-group
neighbor EBGP-TO-SPINE remote-as 65000
neighbor EBGP-TO-SPINE maximum-routes 12000
neighbor EBGP-TO-SPINE allowas-in 1
neighbor 172.16.0.5 peer-group EBGP-TO-SPINE
neighbor 172.16.0.13 peer-group EBGP-TO-SPINE
network 192.168.0.4/32
redistribute connected
!
end
\ No newline at end of file
ip routing
!
lldp run
!
interface Ethernet1
description P2P Link to Leaf-1
logging event link-status
no switchport
ip address 172.16.0.1/30
arp timeout 900
no shutdown
!
interface Ethernet2
description P2P Link to Leaf-2
logging event link-status
no switchport
ip address 172.16.0.5/30
arp timeout 900
no shutdown
!
interface loopback0
ip address 192.168.0.1/32
!
router bgp 65000
bgp log-neighbor-changes
distance bgp 20 200 200
maximum-paths 4 ecmp 64
neighbor EBGP-TO-LEAF peer-group
neighbor EBGP-TO-LEAF remote-as 65100
neighbor EBGP-TO-LEAF maximum-routes 12000
neighbor 172.16.0.2 peer-group EBGP-TO-LEAF
neighbor 172.16.0.6 peer-group EBGP-TO-LEAF
network 192.168.0.1/32
!
end
\ No newline at end of file
ip routing
!
lldp run
!
interface Ethernet1
description P2P Link to Leaf-1
logging event link-status
no switchport
ip address 172.16.0.9/30
arp timeout 900
no shutdown
!
interface Ethernet2
description P2P Link to Leaf-2
logging event link-status
no switchport
ip address 172.16.0.13/30
arp timeout 900
no shutdown
!
interface loopback0
ip address 192.168.0.2/32
!
router bgp 65000
bgp log-neighbor-changes
distance bgp 20 200 200
maximum-paths 4 ecmp 64
neighbor EBGP-TO-LEAF peer-group
neighbor EBGP-TO-LEAF remote-as 65100
neighbor EBGP-TO-LEAF maximum-routes 12000
neighbor 172.16.0.10 peer-group EBGP-TO-LEAF
neighbor 172.16.0.14 peer-group EBGP-TO-LEAF
network 192.168.0.2/32
!
end
\ No newline at end of file
......@@ -11,13 +11,23 @@ class ConfigureLeafSpine():
self,
hosts,
groups,
baseconfig
baseconfig,
spines,
spineconfig,
leafs,
leafconfig
):
with open(hosts) as file1:
self.hosts = yaml.load(file1)
with open(groups) as file2:
self.groups = yaml.load(file2)
with open(spines) as file3:
self.spines = yaml.load(file3)
with open(leafs) as file4:
self.leafs = yaml.load(file4)
self.baseconfig = baseconfig
self.spineconfig = spineconfig
self.leafconfig = leafconfig
self.ENV = Environment(loader=FileSystemLoader('.'))
def generatebaseconfig(self):
......@@ -34,11 +44,45 @@ class ConfigureLeafSpine():
with open(filename, 'w') as file:
file.writelines(config)
def generatespineconfig(self):
"""Generates the spine configuration"""
template = self.ENV.get_template(self.spineconfig)
for key, value in self.hosts.items():
if value['role'] == 'spine':
config = template.render(
host=value,
bgp=self.spines['bgp']
)
filename = 'configs/{0}.config'.format(key)
with open(filename, 'w') as file:
file.writelines(config)
def generateleafconfig(self):
"""Generates the leaf configuration"""
template = self.ENV.get_template(self.leafconfig)
for key, value in self.hosts.items():
if value['role'] == 'leaf':
config = template.render(
host=value,
vlans=self.leafs['vlans'],
routemaps=self.leafs['routemaps'],
bgp=self.leafs['bgp']
)
filename = 'configs/{0}.config'.format(key)
with open(filename, 'w') as file:
file.writelines(config)
if __name__ == "__main__":
lsconfig = ConfigureLeafSpine(
'hosts.yaml',
'groups.yaml',
'baseconfig.j2'
'baseconfig.j2',
'spine.yaml',
'spine.j2',
'leaf.yaml',
'leaf.j2'
)
lsconfig.generatebaseconfig()
lsconfig.generatespineconfig()
lsconfig.generateleafconfig()
---
spine-1:
managementip: 198.51.100.254/24
managementgw: 198.51.100.1
site: ny
role: spine
interfaces:
- number: 1
ip: 172.16.0.1/30
description: P2P Link to Leaf-1
- number: 2
ip: 172.16.0.5/30
description: P2P Link to Leaf-2
loopbacks:
- number: 0
ip: 192.168.0.1/32
routerid: 192.168.0.1
bgpnetworks:
- 192.168.0.1/32
peergroups:
- name: EBGP-TO-LEAF
maxroutes: 12000
remoteas: 65100
neighbors:
- 172.16.0.2
- 172.16.0.6
spine-2:
managementip: 198.51.100.253/24
managementgw: 198.51.100.1
site: ny
role: spine
interfaces:
- number: 1
ip: 172.16.0.9/30
description: P2P Link to Leaf-1
- number: 2
ip: 172.16.0.13/30
description: P2P Link to Leaf-2
loopbacks:
- number: 0
ip: 192.168.0.2/32
routerid: 192.168.0.2
bgpnetworks:
- 192.168.0.2/32
peergroups:
- name: EBGP-TO-LEAF
maxroutes: 12000
remoteas: 65100