sync external routes
diff --git a/planetstack/openstack/driver.py b/planetstack/openstack/driver.py
index b9faa97..14eea41 100644
--- a/planetstack/openstack/driver.py
+++ b/planetstack/openstack/driver.py
@@ -239,7 +239,15 @@
self.delete_external_route(subnet)
return 1
- def add_external_route(self, subnet):
+ def get_external_routes(self):
+ status, output = commands.getstatusoutput('route')
+ routes = output.split('\n')[3:]
+ return routes
+
+ def add_external_route(self, subnet, routes=[]):
+ if not routes:
+ routes = self.get_external_routes()
+
ports = self.shell.quantum.list_ports()['ports']
gw_ip = subnet['gateway_ip']
@@ -262,8 +270,15 @@
ip_address = port['fixed_ips'][0]['ip_address']
if ip_address:
- cmd = "route add -net %s dev br-ex gw %s" % (subnet['cidr'], ip_address)
- commands.getstatusoutput(cmd)
+ # check if external route already exists
+ route_exists = False
+ if routes:
+ for route in routes:
+ if subnet['cidr'] in route and ip_address in route:
+ route_exists = True
+ if not route_exists:
+ cmd = "route add -net %s dev br-ex gw %s" % (subnet['cidr'], ip_address)
+ commands.getstatusoutput(cmd)
return 1
diff --git a/planetstack/openstack/observer.py b/planetstack/openstack/observer.py
index 6fcb3b4..8da0999 100644
--- a/planetstack/openstack/observer.py
+++ b/planetstack/openstack/observer.py
@@ -1,5 +1,6 @@
import time
import traceback
+import commands
from datetime import datetime
from collections import defaultdict
from core.models import *
@@ -263,7 +264,7 @@
for sliver in slivers:
# update connection
self.manager.init_admin(tenant=sliver.slice.name)
- servers = self.manager.client.nova.servers.findall(id=sliver.instance_id)
+ servers = self.manager.driver.shell.nova.servers.findall(id=sliver.instance_id)
if not servers:
continue
server = servers[0]
@@ -273,3 +274,10 @@
sliver.ip = ips[0]['addr']
sliver.save()
logger.info("saved sliver ip: %s %s" % (sliver, ips[0]))
+
+ def sync_external_routes(self):
+ routes = self.manager.driver.get_external_routes()
+ subnets = self.manager.driver.shell.quantum.list_subnets()
+ for subnet in subnets:
+ self.manager.driver.add_external_route(subnet, routes)
+