diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f0730f5bd82..1c32c7e792c 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1302,23 +1302,24 @@ Configurable, StateListener { } } - protected int getUpdatedPriority(final Network network, final List routers, final DomainRouterVO exclude) + protected int getUpdatedPriority(final Network network, final List routers, final DomainRouterVO masterRouter) throws InsufficientVirtualNetworkCapacityException { int priority; if (routers.size() == 0) { priority = DEFAULT_PRIORITY; } else { int maxPriority = 0; - for (final DomainRouterVO r : routers) { - if (!r.getIsRedundantRouter()) { + + final DomainRouterVO router0 = routers.get(0); + if (router0.getId() == masterRouter.getId()) { + if (!router0.getIsRedundantRouter()) { throw new CloudRuntimeException("Redundant router is mixed with single router in one network!"); } - // FIXME Assume the maxPriority one should be running or just - // created. - if (r.getId() != exclude.getId() && _nwHelper.getRealPriority(r) > maxPriority) { - maxPriority = _nwHelper.getRealPriority(r); - } + maxPriority = _nwHelper.getRealPriority(router0); + } else { + maxPriority = DEFAULT_PRIORITY; } + if (maxPriority == 0) { return DEFAULT_PRIORITY; } @@ -1330,6 +1331,7 @@ Configurable, StateListener { throw new InsufficientVirtualNetworkCapacityException("Too many times fail-over happened! Current maximum priority is too high as " + maxPriority + "!", network.getId()); } + priority = maxPriority - DEFAULT_DELTA + 1; } return priority; @@ -1589,6 +1591,7 @@ Configurable, StateListener { final boolean isRedundant = router.getIsRedundantRouter(); if (isRedundant) { buf.append(" redundant_router=1"); + buf.append(" router_id=").append(router.getId()); final Long vpcId = router.getVpcId(); final List routers; @@ -1599,13 +1602,16 @@ Configurable, StateListener { } String redundantState = RedundantState.BACKUP.toString(); + router.setRedundantState(RedundantState.BACKUP); if (routers.size() == 0) { redundantState = RedundantState.MASTER.toString(); + router.setRedundantState(RedundantState.MASTER); } else { final DomainRouterVO router0 = routers.get(0); if (router.getId() == router0.getId()) { redundantState = RedundantState.MASTER.toString(); + router.setRedundantState(RedundantState.MASTER); } } 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 d1d899b37df..187a0cb3c41 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py @@ -129,4 +129,9 @@ class CsCmdLine(CsDataBag): def get_state(self): if "redundant_state" in self.idata(): return self.idata()['redundant_state'] - return "MASTER" \ No newline at end of file + return "MASTER" + + def get_router_id(self): + if "router_id" in self.idata(): + return self.idata()['router_id'] + return 1 \ No newline at end of file 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 267cc1c840b..9569f08d2ca 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py @@ -102,6 +102,7 @@ class CsRedundant(object): file.search(" priority ", " priority %s" % self.cl.get_priority()) file.search(" weight ", " weight %s" % 2) file.search(" state ", " state %s" % self.cl.get_state()) + file.search(" virtual_router_id ", " virtual_router_id %s" % self.cl.get_router_id()) file.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR) file.section("virtual_ipaddress {", "}", self._collect_ips()) file.commit() @@ -122,7 +123,7 @@ class CsRedundant(object): if connt.is_changed(): CsHelper.service("conntrackd", "restart") - if file.is_changed() and self.cl.get_state() == 'MASTER': + if file.is_changed(): CsHelper.service("keepalived", "restart") # FIXME diff --git a/systemvm/patches/debian/config/opt/cloud/templates/keepalived.conf.templ b/systemvm/patches/debian/config/opt/cloud/templates/keepalived.conf.templ index 9f3c24b9996..ef276177f7f 100644 --- a/systemvm/patches/debian/config/opt/cloud/templates/keepalived.conf.templ +++ b/systemvm/patches/debian/config/opt/cloud/templates/keepalived.conf.templ @@ -38,8 +38,8 @@ vrrp_instance inside_network { advert_int 1 authentication { - auth_type PASS - auth_pass WORD + auth_type AH + auth_pass k33p@live } virtual_ipaddress {