mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-8915 - Rearrenging a bit the default route code in order to make it more clear
This commit is contained in:
parent
c17fb0ff28
commit
0c752eab60
@ -663,7 +663,7 @@ class CsForwardingRules(CsDataBag):
|
||||
elif rule["type"] == "staticnat":
|
||||
self.processStaticNatRule(rule)
|
||||
|
||||
#return the VR guest interface ipo
|
||||
#return the VR guest interface ip
|
||||
def getGuestIp(self):
|
||||
ipr = []
|
||||
ipAddr = None
|
||||
|
||||
@ -112,9 +112,6 @@ class CsAddress(CsDataBag):
|
||||
return False
|
||||
|
||||
def process(self):
|
||||
route = CsRoute()
|
||||
found_defaultroute = False
|
||||
|
||||
for dev in self.dbag:
|
||||
if dev == "id":
|
||||
continue
|
||||
@ -126,39 +123,18 @@ class CsAddress(CsDataBag):
|
||||
cmd="ip link set %s up" % dev
|
||||
CsHelper.execute(cmd)
|
||||
|
||||
gateway = str(address["gateway"])
|
||||
network = str(address["network"])
|
||||
|
||||
ip.setAddress(address)
|
||||
|
||||
if ip.configured():
|
||||
logging.info(
|
||||
"Address %s on device %s already configured", ip.ip(), dev)
|
||||
|
||||
ip.post_configure()
|
||||
|
||||
ip.post_configure(address)
|
||||
else:
|
||||
logging.info(
|
||||
"Address %s on device %s not configured", ip.ip(), dev)
|
||||
if CsDevice(dev, self.config).waitfordevice():
|
||||
ip.configure()
|
||||
|
||||
route.add_route(dev, network)
|
||||
|
||||
# The code looks redundant here, but we actually have to cater for routers and
|
||||
# VPC routers in a different manner. Please do not remove this block otherwise
|
||||
# The VPC default route will be broken.
|
||||
if address["nw_type"] == "public" and not found_defaultroute:
|
||||
if not route.defaultroute_exists():
|
||||
if route.add_defaultroute(gateway):
|
||||
found_defaultroute = True
|
||||
|
||||
# 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.cmdline()
|
||||
if(cmdline.get_gateway()):
|
||||
route.add_defaultroute(cmdline.get_gateway())
|
||||
ip.configure(address)
|
||||
|
||||
|
||||
class CsInterface:
|
||||
@ -307,22 +283,24 @@ class CsIP:
|
||||
def getAddress(self):
|
||||
return self.address
|
||||
|
||||
def configure(self):
|
||||
def configure(self, address):
|
||||
logging.info(
|
||||
"Configuring address %s on device %s", self.ip(), self.dev)
|
||||
cmd = "ip addr add dev %s %s brd +" % (self.dev, self.ip())
|
||||
subprocess.call(cmd, shell=True)
|
||||
self.post_configure()
|
||||
self.post_configure(address)
|
||||
|
||||
def post_configure(self):
|
||||
def post_configure(self, address):
|
||||
""" The steps that must be done after a device is configured """
|
||||
if not self.get_type() in ["control"]:
|
||||
route = CsRoute()
|
||||
route.add_table(self.dev)
|
||||
|
||||
CsRule(self.dev).addMark()
|
||||
self.check_is_up()
|
||||
self.set_mark()
|
||||
self.arpPing()
|
||||
|
||||
CsRpsrfs(self.dev).enable()
|
||||
self.post_config_change("add")
|
||||
|
||||
@ -330,6 +308,19 @@ class CsIP:
|
||||
if not self.config.is_vpc():
|
||||
self.setup_router_control()
|
||||
|
||||
if self.config.is_vpc():
|
||||
# The code looks redundant here, but we actually have to cater for routers and
|
||||
# VPC routers in a different manner. Please do not remove this block otherwise
|
||||
# The VPC default route will be broken.
|
||||
if self.get_type() in ["public"]:
|
||||
gateway = str(address["gateway"])
|
||||
route.add_defaultroute(gateway)
|
||||
else:
|
||||
# once we start processing public ip's we need to verify there
|
||||
# is a default route and add if needed
|
||||
if(self.cl.get_gateway()):
|
||||
route.add_defaultroute(self.cl.get_gateway())
|
||||
|
||||
def check_is_up(self):
|
||||
""" Ensure device is up """
|
||||
cmd = "ip link show %s | grep 'state DOWN'" % self.getDevice()
|
||||
@ -543,19 +534,20 @@ class CsIP:
|
||||
CsDevice(self.dev, self.config).configure_rp()
|
||||
|
||||
logging.error(
|
||||
"Not able to setup sourcenat for a regular router yet")
|
||||
"Not able to setup source-nat for a regular router yet")
|
||||
dns = CsDnsmasq(self)
|
||||
dns.add_firewall_rules()
|
||||
app = CsApache(self)
|
||||
app.setup()
|
||||
|
||||
cmdline = self.config.cmdline()
|
||||
# If redundant then this is dealt with by the master backup functions
|
||||
if self.get_type() in ["guest"] and not self.config.cl.is_redundant():
|
||||
if self.get_type() in ["guest"] and not cmdline.is_redundant():
|
||||
pwdsvc = CsPasswdSvc(self.address['public_ip']).start()
|
||||
|
||||
if self.get_type() == "public" and self.config.is_vpc():
|
||||
if self.address["source_nat"]:
|
||||
vpccidr = self.config.cmdline().get_vpccidr()
|
||||
vpccidr = cmdline.get_vpccidr()
|
||||
self.fw.append(
|
||||
["filter", "", "-A FORWARD -s %s ! -d %s -j ACCEPT" % (vpccidr, vpccidr)])
|
||||
self.fw.append(
|
||||
@ -567,7 +559,15 @@ class CsIP:
|
||||
for i in CsHelper.execute(cmd):
|
||||
vals = i.lstrip().split()
|
||||
if (vals[0] == 'inet'):
|
||||
self.iplist[vals[1]] = self.dev
|
||||
|
||||
cidr = vals[1]
|
||||
for ip, device in self.iplist.iteritems():
|
||||
logging.info(
|
||||
"Iterating over the existing IPs. CIDR to be configured ==> %s, existing IP ==> %s on device ==> %s",
|
||||
cidr, ip, device)
|
||||
|
||||
if cidr[0] != ip[0] and device != self.dev:
|
||||
self.iplist[cidr] = self.dev
|
||||
|
||||
def configured(self):
|
||||
if self.address['cidr'] in self.iplist.keys():
|
||||
@ -635,8 +635,13 @@ class CsIP:
|
||||
interface = CsInterface(bag, self.config)
|
||||
if not self.config.cl.is_redundant():
|
||||
return False
|
||||
|
||||
rip = ip.split('/')[0]
|
||||
logging.info("Checking if cidr is a gateway for rVPC. IP ==> %s / device ==> %s", ip, self.dev)
|
||||
|
||||
gw = interface.get_gateway()
|
||||
logging.info("Interface has the following gateway ==> %s", gw)
|
||||
|
||||
if bag['nw_type'] == "guest" and rip == gw:
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -71,13 +71,16 @@ class CsRoute:
|
||||
:param str gateway
|
||||
:return: bool
|
||||
"""
|
||||
if gateway is not None:
|
||||
if not gateway:
|
||||
raise Exception("Gateway cannot be None.")
|
||||
|
||||
if self.defaultroute_exists():
|
||||
return False
|
||||
else:
|
||||
cmd = "default via " + gateway
|
||||
logging.info("Adding default route")
|
||||
self.set_route(cmd)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def defaultroute_exists(self):
|
||||
""" Return True if a default route is present
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user