Fix router priuority using the same logic as the one for the state

Fix the router state. do not show UNKNOW, but MASTER or BACKUP depending on the type of router
Implement the virtual_router_id to be passed as a boot parameter to the router
  - it is needed for the keepalived configuration
This commit is contained in:
wilderrodrigues 2015-01-27 14:05:38 +01:00
parent a5d6f90f66
commit ae53d5ede1
4 changed files with 24 additions and 12 deletions

View File

@ -1302,23 +1302,24 @@ Configurable, StateListener<State, VirtualMachine.Event, VirtualMachine> {
}
}
protected int getUpdatedPriority(final Network network, final List<DomainRouterVO> routers, final DomainRouterVO exclude)
protected int getUpdatedPriority(final Network network, final List<DomainRouterVO> 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<State, VirtualMachine.Event, VirtualMachine> {
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<State, VirtualMachine.Event, VirtualMachine> {
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<DomainRouterVO> routers;
@ -1599,13 +1602,16 @@ Configurable, StateListener<State, VirtualMachine.Event, VirtualMachine> {
}
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);
}
}

View File

@ -129,4 +129,9 @@ class CsCmdLine(CsDataBag):
def get_state(self):
if "redundant_state" in self.idata():
return self.idata()['redundant_state']
return "MASTER"
return "MASTER"
def get_router_id(self):
if "router_id" in self.idata():
return self.idata()['router_id']
return 1

View File

@ -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

View File

@ -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 {