Parcourir la source

peers: Clean old or dead peers

Sebastien Badia il y a 7 ans
Parent
commit
b716672d0f
4 fichiers modifiés avec 82 ajouts et 24 suppressions
  1. 81 0
      generate_config_bird.py
  2. 0 2
      peers/amsix.yml
  3. 0 22
      peers/sfinx.yml
  4. 1 0
      todo

+ 81 - 0
generate_config_bird.py

@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import ipaddr
+import yaml
+import sys
+import os
+import glob
+from jinja2 import Environment, FileSystemLoader
+from termcolor import colored
+
+def parse_peers(peer_file):
+    """parse_peers: Just a simple function for peers parsing
+    :peer_file: The YAML peer file to parse
+    :returns: Just a return code if the file is correctly parsed or not
+
+    """
+
+    peering_flat = open(peer_file).read()
+    ixp = os.path.splitext(os.path.basename(peer_file))[0]
+
+    try:
+        peerings = yaml.safe_load(peering_flat)
+    except:
+        print colored('ERROR', 'red') + ": the peers.yaml file could not be parsed.. please check \
+    your syntax"
+        sys.exit(2)
+
+    for asn in peerings:
+        for keyword in ['export', 'import', 'description']:
+            if keyword not in peerings[asn]:
+                print colored('ERROR', 'red') + ": missing %s statement in stanza %s" % (keyword, asn)
+                sys.exit(2)
+
+        acceptable_exports = ['AS-GITOYEN', 'NOT ANY', 'ANY']
+        if not peerings[asn]['export'] in acceptable_exports:
+            print colored('ERROR', 'red') + ": export must be one of the following: %s" \
+                % " ".join(acceptable_exports)
+            sys.exit(2)
+
+        for peer in peerings[asn]['peerings']:
+            try:
+                peer_ip = ipaddr.IPAddress(peer)
+                if type(ipaddr.IPAddress(peer_ip)) is ipaddr.IPv4Address:
+                    neighbor_ipv4 = peer_ip
+                    if ixp == 'sfinx':
+                        ix4_group = 'SFINX'
+                    else:
+                        ix4_group = 'AMS-IX-PEERS'
+                elif type(ipaddr.IPAddress(peer_ip)) is ipaddr.IPv6Address:
+                    neighbor_ipv6 = peer_ip
+                    if ixp == 'sfinx':
+                        ix6_group = 'SFINXV6'
+                    else:
+                        ix6_group = 'AMS-IX6-PEERS'
+            except ValueError:
+                print colored('ERROR', 'red') + ": %s in %s is not a valid IP" % (peer, asn)
+                sys.exit(2)
+
+        try:
+            limit_ipv4 = peerings[asn]['limit_ipv4']
+        except:
+            limit_ipv4 = False
+
+        try:
+            limit_ipv6 = peerings[asn]['limit_ipv6']
+        except:
+            limit_ipv6 = False
+
+        env = Environment(loader=FileSystemLoader('./'))
+        tpl = env.get_template('templates/bird_v4.j2')
+
+        print tpl.render(neighbor_as = asn, description =
+                peerings[asn]['description'], export_as = peerings[asn]['export'],
+                import_as = peerings[asn]['import'], neighbor_ipv4 =
+                neighbor_ipv4, neighbor_ipv6 = neighbor_ipv6, ix4_name =
+                ix4_group, ix6_name = ix6_group, limit_ipv4 = limit_ipv4,
+                limit_ipv6 = limit_ipv6)
+
+for peer_files in ('peers/franceix.yml', 'peers/amsix.yml'):
+    parse_peers(peer_files)

+ 0 - 2
peers/amsix.yml

@@ -64,10 +64,8 @@
   peerings:
     - 80.249.208.168
     - 80.249.209.208
-    - 80.249.211.233
     - 2001:7f8:1::a502:940:1
     - 2001:7f8:1::a502:940:2
-    - 2001:7f8:1::a502:940:3
 
 16298:
   description: Interbox

+ 0 - 22
peers/sfinx.yml

@@ -13,14 +13,6 @@
   peerings:
     - 194.68.129.111
 
-35189:
-  description: Association Kazar
-  import: AS-KAZAAR
-  export: AS-GITOYEN
-  peerings:
-    - 194.68.129.120
-    - 2001:7f8:4e:2::120
-
 29608:
   description: Absolight
   import: AS-ABSOLIGHT
@@ -51,13 +43,6 @@
   peerings:
     - 194.68.129.148
 
-42937:
-  description: 720degres
-  import: AS42937
-  export: AS-GITOYEN
-  peerings:
-    - 194.68.129.166
-
 50620:
   description: Bluenetwork
   import: AS50620
@@ -101,10 +86,3 @@
   peerings:
     - 194.68.129.238
     - 2001:7f8:4e:2::238
-
-9003:
-  description: Altitude Telecom
-  import: AS9003
-  export: AS-GITOYEN
-  peerings:
-    - 194.68.129.246

+ 1 - 0
todo

@@ -0,0 +1 @@
+git remote set-url --add origin git+ssh://gogs@code.ffdn.org:55555/gitoyen/peering.git