Commit 092506b4 authored by Bill Grant's avatar Bill Grant

part 2 complete

parent 25d9a696
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,18 @@ class ConfigureLeafSpine():
self,
hosts,
groups,
baseconfig
baseconfig,
spines,
spineconfig,
):
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)
self.baseconfig = baseconfig
self.spineconfig = spineconfig
self.ENV = Environment(loader=FileSystemLoader('.'))
def generatebaseconfig(self):
......@@ -34,11 +39,27 @@ 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)
if __name__ == "__main__":
lsconfig = ConfigureLeafSpine(
'hosts.yaml',
'groups.yaml',
'baseconfig.j2'
'baseconfig.j2',
'spine.yaml',
'spine.j2'
)
lsconfig.generatebaseconfig()
lsconfig.generatespineconfig()
......@@ -4,15 +4,59 @@ 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
neighbors:
- 172.16.0.10
- 172.16.0.14
leaf-1:
managementip: 198.51.100.252/24
managementgw: 198.51.100.1
site: ny
role: leaf
leaf-2:
managementip: 198.51.100.251/24
managementgw: 198.51.100.1
site: ny
\ No newline at end of file
site: ny
role: leaf
# LeafSpineAutomation
! 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
! Base configuration
!
hostname leaf-1
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
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 198.51.100.252/24
!
ip route vrf management 0.0.0.0/0 198.51.100.1
!
end
\ No newline at end of file
! Base configuration
!
hostname leaf-2
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
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 198.51.100.251/24
!
ip route vrf management 0.0.0.0/0 198.51.100.1
!
end
\ No newline at end of file
! Base configuration
!
hostname spine-1
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
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 198.51.100.254/24
!
ip route vrf management 0.0.0.0/0 198.51.100.1
!
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
! Base configuration
!
hostname spine-2
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
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 198.51.100.253/24
!
ip route vrf management 0.0.0.0/0 198.51.100.1
!
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
#!/usr/bin/env python3
from jinja2 import Environment, FileSystemLoader
import yaml
class ConfigureLeafSpine():
"""Class to configure and maintain leaf spine switches"""
def __init__(
self,
hosts,
groups,
baseconfig,
spines,
spineconfig,
):
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)
self.baseconfig = baseconfig
self.spineconfig = spineconfig
self.ENV = Environment(loader=FileSystemLoader('.'))
def generatebaseconfig(self):
"""Generates base configuration files"""
template = self.ENV.get_template(self.baseconfig)
for key, value in self.hosts.items():
config = template.render(
defaults=self.groups['defaults'],
hostname=key,
host=value,
site=self.groups[value['site']]
)
filename = 'configs/{0}-base.config'.format(key)
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)
if __name__ == "__main__":
lsconfig = ConfigureLeafSpine(
'hosts.yaml',
'groups.yaml',
'baseconfig.j2',
'spine.yaml',
'spine.j2'
)
lsconfig.generatebaseconfig()
lsconfig.generatespineconfig()
---
defaults:
domain: example.net
ntpserver1: 0.pool.ntp.org
ntpserver2: 1.pool.ntp.org
nameserver1: 8.8.8.8
nameserver2: 8.8.4.4
domainname: example.net
username: admin
password: admin
ny:
timezone: America/New_York
arista_eos:
nos: eos
iprouting: True
lldp: True
---
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
neighbors:
- 172.16.0.10
- 172.16.0.14
leaf-1:
managementip: 198.51.100.252/24
managementgw: 198.51.100.1
site: ny
role: leaf
leaf-2:
managementip: 198.51.100.251/24
managementgw: 198.51.100.1
site: ny
role: leaf
# LeafSpineAutomation
! 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
! Base configuration
!
hostname leaf-1
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
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 198.51.100.252/24
!
ip route vrf management 0.0.0.0/0 198.51.100.1
!
end
\ No newline at end of file
! Base configuration
!
hostname leaf-2
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
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 198.51.100.251/24
!
ip route vrf management 0.0.0.0/0 198.51.100.1
!
end
\ No newline at end of file
! Base configuration
!
hostname spine-1
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
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 198.51.100.254/24
!
ip route vrf management 0.0.0.0/0 198.51.100.1
!
end
\ No newline at end of file
! Base configuration
!
hostname spine-2
ip name-server 8.8.8.8
ip name-server 8.8.4.4
ip domain-name example.net
!
ntp source Management1
ntp server 0.pool.ntp.org prefer
ntp server 1.pool.ntp.org
!
username admin role network-admin secret admin
!
clock timezone America/New_York
!
vrf definition management