From ff96e5efeeafb9a4b1fd9133da3d6a8427b5c50b Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Wed, 11 Feb 2015 17:32:22 -0800 Subject: [PATCH 01/12] updateros: ignore specified BGP-announced networks in route list. --- updateros.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/updateros.py b/updateros.py index c555a24..1e5ea63 100755 --- a/updateros.py +++ b/updateros.py @@ -29,8 +29,11 @@ username = None # blacklist BGP-announced networks with direct-routing agreements -hamwan_dstaddresses = ["44.24.240.0/20", "44.103.0.0/19", "44.34.128.0/21"] -hamwan_gateways = ["198.178.136.80", "209.189.196.68"] +bgp_networks = [ + "44.24.240.0/20", # HamWAN Puget Sound + "44.34.128.0/21", # HamWAN Memphis + "44.103.0.0/19", # W8CMN Mi6WAN +] def get_encap(): @@ -38,6 +41,12 @@ def get_encap(): return ampr.encap +def filter_encap(route): + if route.network() in bgp_networks: + return False + return route + + def parse_ros_route(line): dstaddress, gateway = None, None for field in line.split(" "): @@ -92,7 +101,7 @@ def export_ros_ipip_interfaces(ssh): def main(): - encap = get_encap() + encap = filter(None, map(filter_encap, get_encap())) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) From 72a79b077f6e22e1b14c388381f1dc0996cdea04 Mon Sep 17 00:00:00 2001 From: Marc Date: Sat, 14 Feb 2015 00:16:18 +0100 Subject: [PATCH 02/12] making the distance parameter a config parameter it can be quite handy to be able to define the value for the distance parameter. --- updateros.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/updateros.py b/updateros.py index 1e5ea63..167acc8 100755 --- a/updateros.py +++ b/updateros.py @@ -27,6 +27,7 @@ edge_router_ip = sys.argv[-1] ssh_port = 22 username = None +distance = 30 # blacklist BGP-announced networks with direct-routing agreements bgp_networks = [ @@ -151,7 +152,7 @@ def main(): edge_router_ip, interface, entry['gatewayIP'], "AMPR last updated %s, added %s" % ( entry['updated'].date(), date.today()))) - commands.append("/ip route add dst-address=%s gateway=%s distance=30" % (entry.network(), interface)) + commands.append("/ip route add dst-address=%s gateway=%s distance=%s" % (entry.network(), interface, distance)) commands.append("/ip neighbor discovery set %s discover=no" % (interface)) if "-v" in sys.argv: From 8cb36b04add43058ede4071ab76dc6661f22a9b3 Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Fri, 27 Feb 2015 18:57:48 -0800 Subject: [PATCH 03/12] updateros: break on KeyboardInterrupt. --- updateros.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/updateros.py b/updateros.py index 167acc8..dd3ae7e 100755 --- a/updateros.py +++ b/updateros.py @@ -161,6 +161,8 @@ def main(): for command in commands: ssh.exec_command(command) time.sleep(0.1) + except KeyboardInterrupt: + print "KeyboardInterrupt received, closing..." except UserWarning, e: print e except socket.timeout: From 83bfe8698777a6e34d553259c8d9216f1d9ffb2a Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Fri, 13 Mar 2015 23:32:19 -0700 Subject: [PATCH 04/12] updateros: don't use [find] for remove. --- updateros.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updateros.py b/updateros.py index dd3ae7e..c938241 100755 --- a/updateros.py +++ b/updateros.py @@ -141,7 +141,7 @@ def main(): if ipips_to_remove: commands.append("# removing orphaned ipip interfaces") for interface, gateway in ipips_to_remove: - commands.append("/interface ipip remove [find name=%s]" % interface) + commands.append("/interface ipip remove %s" % interface) if routes_to_add: commands.append("# adding new and modified routes") From 887ee7fe2d56f98d1bd627c63ef75e498e8eae34 Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Fri, 13 Mar 2015 23:57:21 -0700 Subject: [PATCH 05/12] updateros: fix: an empty encap could cause all ipip interfaces to be deleted. --- updateros.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/updateros.py b/updateros.py index c938241..23d7db9 100755 --- a/updateros.py +++ b/updateros.py @@ -101,6 +101,11 @@ def export_ros_ipip_interfaces(ssh): export_ros(ssh, "/interface ipip export"))) +def filter_ipip_ampr(ipips): + return filter( + lambda (interface, gateway): interface.startswith('ampr-'), ipips) + + def main(): encap = filter(None, map(filter_encap, get_encap())) @@ -114,7 +119,7 @@ def main(): unchanged = 0 routes_to_add = set(encap) routes_to_remove = set(ros_routes) - ipips_to_remove = set(ros_ipips) + ipips_to_remove = set(filter_ipip_ampr(ros_ipips)) for entry in encap: dstaddress = entry.network() gateway = entry['gatewayIP'] From 165c864afad35945e622bffc503dea420837e785 Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Thu, 26 Mar 2015 19:42:39 -0700 Subject: [PATCH 06/12] Add instructions for installing dependencies. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6bdead7..0885b07 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ AMPR Portal API Python bindings =============================== +Install Dependencies +-------------------- + + sudo apt-get install python python-requests + Usage ----- From a5cddc845b53bb2052198c62e6f7ea71d1af3c21 Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Thu, 26 Mar 2015 20:20:33 -0700 Subject: [PATCH 07/12] Add pip instruction to README. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0885b07..68beae0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ Install Dependencies sudo apt-get install python python-requests +or + + sudo pip install requests + Usage ----- From 5e64d1ef95e439226ba9dfa1cf5bded7238fecbd Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Fri, 27 Mar 2015 00:42:57 -0700 Subject: [PATCH 08/12] Add Paramiko to install instructions. --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 68beae0..cf46108 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,7 @@ AMPR Portal API Python bindings Install Dependencies -------------------- - sudo apt-get install python python-requests - -or - - sudo pip install requests + sudo pip install paramiko requests Usage ----- From a5733f469d19388109fe1a50f7843531b3663eba Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Mon, 23 Nov 2015 22:04:11 +0200 Subject: [PATCH 09/12] Update amprapi.py Update according to the last changes in ampr portal API (1.0.7) --- amprapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amprapi.py b/amprapi.py index af005c0..c2584d8 100755 --- a/amprapi.py +++ b/amprapi.py @@ -60,7 +60,7 @@ class AMPRAPI: 'encap': EncapEntry, } _api_version = 'v1' - _api_version_minor = "1.04" + _api_version_minor = "1.07" def __init__(self, url=settings.API_URL, user=settings.API_USER, api_key=settings.API_KEY): @@ -84,7 +84,7 @@ def get(self, endpoint): r = requests.get(self.url + self._api_version + '/' + endpoint, auth=(self.user, self.api_key)) if r.status_code == 200: - return json.loads(r.json()) + return json.loads(r.text) elif r.status_code == 404: raise NotImplementedError(r.json()) else: From 6545202d8b4e58eac66556ed7bffe79cbaf4c5c8 Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Mon, 23 Nov 2015 22:29:51 +0200 Subject: [PATCH 10/12] Update amprapi.py Another small adaptation for consistency --- amprapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amprapi.py b/amprapi.py index c2584d8..6fab47d 100755 --- a/amprapi.py +++ b/amprapi.py @@ -86,7 +86,7 @@ def get(self, endpoint): if r.status_code == 200: return json.loads(r.text) elif r.status_code == 404: - raise NotImplementedError(r.json()) + raise NotImplementedError(r.text) else: raise Exception(r.text) From ec67550e2c013cd1921fc9e9f297354b3f0c28e5 Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Wed, 27 Jan 2016 12:17:20 +0200 Subject: [PATCH 11/12] Correct KeyError on netmask use on stand alone run Resolution of issue KeyError: u'netmask' using latest commit (d84daa1 on Nov 23, 2015) (#5) --- amprapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amprapi.py b/amprapi.py index 6fab47d..028d5b8 100755 --- a/amprapi.py +++ b/amprapi.py @@ -49,7 +49,7 @@ class AMPRAPI: >>> import amprapi >>> ampr = amprapi.AMPRAPI() >>> for entry in ampr.encap: - ... print "%(network)s/%(netmask)s via %(gatewayIP)s" % entry + ... print "%(network)s/%(maskLength)s via %(gatewayIP)s" % entry ... 44.151.22.22/32 via 2.10.28.74 44.182.69.0/24 via 5.15.186.251 @@ -97,4 +97,4 @@ def __getattr__(self, name): if __name__ == "__main__": ampr = AMPRAPI() for entry in ampr.encap: - print "%(network)s/%(netmask)s via %(gatewayIP)s" % entry + print "%(network)s/%(maskLength)s via %(gatewayIP)s" % entry From e09c6cef5a96a5438980dbd1b70a4f4ad841ce00 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 4 Mar 2016 13:17:38 +0100 Subject: [PATCH 12/12] allowing fast path --- updateros.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updateros.py b/updateros.py index 23d7db9..2308cc0 100755 --- a/updateros.py +++ b/updateros.py @@ -152,7 +152,7 @@ def main(): commands.append("# adding new and modified routes") for entry in routes_to_add: interface = "ampr-%s" % entry['gatewayIP'] - commands.append("/interface ipip add !keepalive clamp-tcp-mss=yes " + commands.append("/interface ipip add !keepalive clamp-tcp-mss=yes allow-fast-path=yes " "local-address=%s name=%s remote-address=%s comment=\"%s\"" % ( edge_router_ip, interface, entry['gatewayIP'], "AMPR last updated %s, added %s" % (