Skip to content

Commit b9feb39

Browse files
committed
apply static routes on change to master state
1 parent ef115ab commit b9feb39

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from cs.CsLoadBalancer import CsLoadBalancer
4343
from cs.CsConfig import CsConfig
4444
from cs.CsProcess import CsProcess
45+
from cs.CsStaticRoutes import CsStaticRoutes
4546

4647

4748
class CsPassword(CsDataBag):
@@ -74,27 +75,6 @@ def __update(self, vm_ip, password):
7475
logging.debug("Update password server result ==> %s" % result)
7576

7677

77-
class CsStaticRoutes(CsDataBag):
78-
79-
def process(self):
80-
logging.debug("Processing CsStaticRoutes file ==> %s" % self.dbag)
81-
for item in self.dbag:
82-
if item == "id":
83-
continue
84-
self.__update(self.dbag[item])
85-
86-
def __update(self, route):
87-
if route['revoke']:
88-
command = "ip route del %s via %s" % (route['network'], route['gateway'])
89-
result = CsHelper.execute(command)
90-
else:
91-
command = "ip route show | grep %s | awk '{print $1, $3}'" % route['network']
92-
result = CsHelper.execute(command)
93-
if not result:
94-
route_command = "ip route add %s via %s" % (route['network'], route['gateway'])
95-
result = CsHelper.execute(route_command)
96-
97-
9878
class CsAcl(CsDataBag):
9979
"""
10080
Deal with Network acls

systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from CsApp import CsPasswdSvc
3939
from CsAddress import CsDevice
4040
from CsRoute import CsRoute
41+
from CsStaticRoutes import CsStaticRoutes
4142
import socket
4243
from time import sleep
4344

@@ -298,9 +299,9 @@ def set_master(self):
298299
continue
299300
dev = ip.get_device()
300301
logging.info("Will proceed configuring device ==> %s" % dev)
301-
cmd2 = "ip link set %s up" % dev
302+
cmd = "ip link set %s up" % dev
302303
if CsDevice(dev, self.config).waitfordevice():
303-
CsHelper.execute(cmd2)
304+
CsHelper.execute(cmd)
304305
logging.info("Bringing public interface %s up" % dev)
305306

306307
try:
@@ -312,7 +313,10 @@ def set_master(self):
312313
else:
313314
logging.error("Device %s was not ready could not bring it up" % dev)
314315

315-
# ip route add default via $gw table Table_$dev proto static
316+
logging.debug("Configuring static routes")
317+
static_routes = CsStaticRoutes("staticroutes", self.config)
318+
static_routes.process()
319+
316320
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF)
317321
CsHelper.execute("%s -c" % cmd)
318322
CsHelper.execute("%s -f" % cmd)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/python
2+
# -- coding: utf-8 --
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
from CsDatabag import CsDataBag
21+
from CsRedundant import *
22+
23+
24+
class CsStaticRoutes(CsDataBag):
25+
26+
def process(self):
27+
logging.debug("Processing CsStaticRoutes file ==> %s" % self.dbag)
28+
for item in self.dbag:
29+
if item == "id":
30+
continue
31+
self.__update(self.dbag[item])
32+
33+
def __update(self, route):
34+
if route['revoke']:
35+
command = "ip route del %s via %s" % (route['network'], route['gateway'])
36+
CsHelper.execute(command)
37+
else:
38+
command = "ip route show | grep %s | awk '{print $1, $3}'" % route['network']
39+
result = CsHelper.execute(command)
40+
if not result:
41+
route_command = "ip route add %s via %s" % (route['network'], route['gateway'])
42+
CsHelper.execute(route_command)

0 commit comments

Comments
 (0)