mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-8799 fixed the defalut routes
CLOUDSTACK-8799 made changes to fix CsRedundant.py
This commit is contained in:
parent
a04b8f6e82
commit
1a02773b55
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user