From 1a02773b556a0efa277cf18cd099fc62a4e27706 Mon Sep 17 00:00:00 2001 From: Bharat Kumar Date: Fri, 4 Sep 2015 12:44:46 +0530 Subject: [PATCH] CLOUDSTACK-8799 fixed the defalut routes CLOUDSTACK-8799 made changes to fix CsRedundant.py --- .../config/opt/cloud/bin/cs/CsAddress.py | 32 +++++++++++++------ .../config/opt/cloud/bin/cs/CsDatabag.py | 4 +++ .../config/opt/cloud/bin/cs/CsRedundant.py | 17 ++-------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py index 767e7488242..a855f8337e0 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py @@ -95,9 +95,17 @@ class CsAddress(CsDataBag): return ip return None + def check_if_link_up(self,dev): + cmd="ip link show dev %s | tr '\n' ' ' | cut -d ' ' -f 9"%dev + result=CsHelper.execute(cmd) + if(result[0].lower()=="up"): + return True + else: + return False + + def process(self): route = CsRoute() - found_defaultroute = False for dev in self.dbag: if dev == "id": @@ -105,8 +113,14 @@ class CsAddress(CsDataBag): ip = CsIP(dev, self.config) for address in self.dbag[dev]: + if(address["nw_type"]!="public"): + continue + + #check if link is up + if not self.check_if_link_up(dev): + cmd="ip link set %s up"%dev + CsHelper.execute(cmd) - gateway = str(address["gateway"]) network = str(address["network"]) ip.setAddress(address) @@ -122,16 +136,14 @@ class CsAddress(CsDataBag): "Address %s on device %s not configured", ip.ip(), dev) if CsDevice(dev, self.config).waitfordevice(): ip.configure() + route.add_route(dev, network) - if address["nw_type"] != "control": - route.add_route(dev, network) + # once we start processing public ip's we need to verify there + # is a default route and add if needed + if not route.defaultroute_exists(): + cmdline=self.config.get_cmdline_instance() + route.add_defaultroute(cmdline.get_gateway()) - # once we start processing public ip's we need to verify there - # is a default route and add if needed - if address["nw_type"] == "public" and not found_defaultroute: - if not route.defaultroute_exists(): - if route.add_defaultroute(gateway): - found_defaultroute = True class CsInterface: diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py index 2a37b0a858f..f04961b4557 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py @@ -134,3 +134,7 @@ class CsCmdLine(CsDataBag): md5 = hashlib.md5() md5.update(passwd) return md5.hexdigest() + def get_gateway(self): + if "gateway" in self.idata(): + return self.idata()['gateway'] + return False diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py index da9b8876ed2..3f1cbe03c47 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py @@ -261,20 +261,9 @@ class CsRedundant(object): self.set_lock() logging.debug("Setting router to master") - ads = [o for o in self.address.get_ips() if o.is_public()] - dev = '' - for o in ads: - if dev == o.get_device(): - continue - cmd2 = "ip link set %s up" % o.get_device() - if CsDevice(o.get_device(), self.config).waitfordevice(): - CsHelper.execute(cmd2) - dev = o.get_device() - logging.info("Bringing public interface %s up" % - o.get_device()) - else: - logging.error( - "Device %s was not ready could not bring it up" % o.get_device()) + self.address.process() + logging.info("added default rotue") + # ip route add default via $gw table Table_$dev proto static cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF) CsHelper.execute("%s -c" % cmd)