diff --git a/systemvm/patches/debian/config/opt/cloud/bin/configure.py b/systemvm/patches/debian/config/opt/cloud/bin/configure.py index 29e19c4feba..ae24ac56d8a 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/configure.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/configure.py @@ -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 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 3e8fbcaeb80..a473277b75a 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py @@ -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 @@ -123,42 +120,21 @@ class CsAddress(CsDataBag): for address in self.dbag[dev]: #check if link is up 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) - 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,28 +283,43 @@ 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") '''For isolated/redundant and dhcpsrvr routers, call this method after the post_config is complete ''' 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 """ @@ -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 diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRoute.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRoute.py index fd2d98987cc..1178fb04e1f 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRoute.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRoute.py @@ -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