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":
|
elif rule["type"] == "staticnat":
|
||||||
self.processStaticNatRule(rule)
|
self.processStaticNatRule(rule)
|
||||||
|
|
||||||
#return the VR guest interface ipo
|
#return the VR guest interface ip
|
||||||
def getGuestIp(self):
|
def getGuestIp(self):
|
||||||
ipr = []
|
ipr = []
|
||||||
ipAddr = None
|
ipAddr = None
|
||||||
|
|||||||
@ -112,9 +112,6 @@ class CsAddress(CsDataBag):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
route = CsRoute()
|
|
||||||
found_defaultroute = False
|
|
||||||
|
|
||||||
for dev in self.dbag:
|
for dev in self.dbag:
|
||||||
if dev == "id":
|
if dev == "id":
|
||||||
continue
|
continue
|
||||||
@ -123,42 +120,21 @@ class CsAddress(CsDataBag):
|
|||||||
for address in self.dbag[dev]:
|
for address in self.dbag[dev]:
|
||||||
#check if link is up
|
#check if link is up
|
||||||
if not self.check_if_link_up(dev):
|
if not self.check_if_link_up(dev):
|
||||||
cmd="ip link set %s up"%dev
|
cmd="ip link set %s up" % dev
|
||||||
CsHelper.execute(cmd)
|
CsHelper.execute(cmd)
|
||||||
|
|
||||||
gateway = str(address["gateway"])
|
|
||||||
network = str(address["network"])
|
|
||||||
|
|
||||||
ip.setAddress(address)
|
ip.setAddress(address)
|
||||||
|
|
||||||
if ip.configured():
|
if ip.configured():
|
||||||
logging.info(
|
logging.info(
|
||||||
"Address %s on device %s already configured", ip.ip(), dev)
|
"Address %s on device %s already configured", ip.ip(), dev)
|
||||||
|
|
||||||
ip.post_configure()
|
ip.post_configure(address)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.info(
|
logging.info(
|
||||||
"Address %s on device %s not configured", ip.ip(), dev)
|
"Address %s on device %s not configured", ip.ip(), dev)
|
||||||
if CsDevice(dev, self.config).waitfordevice():
|
if CsDevice(dev, self.config).waitfordevice():
|
||||||
ip.configure()
|
ip.configure(address)
|
||||||
|
|
||||||
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())
|
|
||||||
|
|
||||||
|
|
||||||
class CsInterface:
|
class CsInterface:
|
||||||
@ -307,22 +283,24 @@ class CsIP:
|
|||||||
def getAddress(self):
|
def getAddress(self):
|
||||||
return self.address
|
return self.address
|
||||||
|
|
||||||
def configure(self):
|
def configure(self, address):
|
||||||
logging.info(
|
logging.info(
|
||||||
"Configuring address %s on device %s", self.ip(), self.dev)
|
"Configuring address %s on device %s", self.ip(), self.dev)
|
||||||
cmd = "ip addr add dev %s %s brd +" % (self.dev, self.ip())
|
cmd = "ip addr add dev %s %s brd +" % (self.dev, self.ip())
|
||||||
subprocess.call(cmd, shell=True)
|
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 """
|
""" The steps that must be done after a device is configured """
|
||||||
if not self.get_type() in ["control"]:
|
if not self.get_type() in ["control"]:
|
||||||
route = CsRoute()
|
route = CsRoute()
|
||||||
route.add_table(self.dev)
|
route.add_table(self.dev)
|
||||||
|
|
||||||
CsRule(self.dev).addMark()
|
CsRule(self.dev).addMark()
|
||||||
self.check_is_up()
|
self.check_is_up()
|
||||||
self.set_mark()
|
self.set_mark()
|
||||||
self.arpPing()
|
self.arpPing()
|
||||||
|
|
||||||
CsRpsrfs(self.dev).enable()
|
CsRpsrfs(self.dev).enable()
|
||||||
self.post_config_change("add")
|
self.post_config_change("add")
|
||||||
|
|
||||||
@ -330,6 +308,19 @@ class CsIP:
|
|||||||
if not self.config.is_vpc():
|
if not self.config.is_vpc():
|
||||||
self.setup_router_control()
|
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):
|
def check_is_up(self):
|
||||||
""" Ensure device is up """
|
""" Ensure device is up """
|
||||||
cmd = "ip link show %s | grep 'state DOWN'" % self.getDevice()
|
cmd = "ip link show %s | grep 'state DOWN'" % self.getDevice()
|
||||||
@ -543,19 +534,20 @@ class CsIP:
|
|||||||
CsDevice(self.dev, self.config).configure_rp()
|
CsDevice(self.dev, self.config).configure_rp()
|
||||||
|
|
||||||
logging.error(
|
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 = CsDnsmasq(self)
|
||||||
dns.add_firewall_rules()
|
dns.add_firewall_rules()
|
||||||
app = CsApache(self)
|
app = CsApache(self)
|
||||||
app.setup()
|
app.setup()
|
||||||
|
|
||||||
|
cmdline = self.config.cmdline()
|
||||||
# If redundant then this is dealt with by the master backup functions
|
# 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()
|
pwdsvc = CsPasswdSvc(self.address['public_ip']).start()
|
||||||
|
|
||||||
if self.get_type() == "public" and self.config.is_vpc():
|
if self.get_type() == "public" and self.config.is_vpc():
|
||||||
if self.address["source_nat"]:
|
if self.address["source_nat"]:
|
||||||
vpccidr = self.config.cmdline().get_vpccidr()
|
vpccidr = cmdline.get_vpccidr()
|
||||||
self.fw.append(
|
self.fw.append(
|
||||||
["filter", "", "-A FORWARD -s %s ! -d %s -j ACCEPT" % (vpccidr, vpccidr)])
|
["filter", "", "-A FORWARD -s %s ! -d %s -j ACCEPT" % (vpccidr, vpccidr)])
|
||||||
self.fw.append(
|
self.fw.append(
|
||||||
@ -567,7 +559,15 @@ class CsIP:
|
|||||||
for i in CsHelper.execute(cmd):
|
for i in CsHelper.execute(cmd):
|
||||||
vals = i.lstrip().split()
|
vals = i.lstrip().split()
|
||||||
if (vals[0] == 'inet'):
|
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):
|
def configured(self):
|
||||||
if self.address['cidr'] in self.iplist.keys():
|
if self.address['cidr'] in self.iplist.keys():
|
||||||
@ -635,8 +635,13 @@ class CsIP:
|
|||||||
interface = CsInterface(bag, self.config)
|
interface = CsInterface(bag, self.config)
|
||||||
if not self.config.cl.is_redundant():
|
if not self.config.cl.is_redundant():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
rip = ip.split('/')[0]
|
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()
|
gw = interface.get_gateway()
|
||||||
|
logging.info("Interface has the following gateway ==> %s", gw)
|
||||||
|
|
||||||
if bag['nw_type'] == "guest" and rip == gw:
|
if bag['nw_type'] == "guest" and rip == gw:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -71,13 +71,16 @@ class CsRoute:
|
|||||||
:param str gateway
|
:param str gateway
|
||||||
:return: bool
|
: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
|
cmd = "default via " + gateway
|
||||||
logging.info("Adding default route")
|
logging.info("Adding default route")
|
||||||
self.set_route(cmd)
|
self.set_route(cmd)
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def defaultroute_exists(self):
|
def defaultroute_exists(self):
|
||||||
""" Return True if a default route is present
|
""" Return True if a default route is present
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user