mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
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:
parent
a5d6f90f66
commit
ae53d5ede1
@ -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 {
|
throws InsufficientVirtualNetworkCapacityException {
|
||||||
int priority;
|
int priority;
|
||||||
if (routers.size() == 0) {
|
if (routers.size() == 0) {
|
||||||
priority = DEFAULT_PRIORITY;
|
priority = DEFAULT_PRIORITY;
|
||||||
} else {
|
} else {
|
||||||
int maxPriority = 0;
|
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!");
|
throw new CloudRuntimeException("Redundant router is mixed with single router in one network!");
|
||||||
}
|
}
|
||||||
// FIXME Assume the maxPriority one should be running or just
|
maxPriority = _nwHelper.getRealPriority(router0);
|
||||||
// created.
|
} else {
|
||||||
if (r.getId() != exclude.getId() && _nwHelper.getRealPriority(r) > maxPriority) {
|
maxPriority = DEFAULT_PRIORITY;
|
||||||
maxPriority = _nwHelper.getRealPriority(r);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxPriority == 0) {
|
if (maxPriority == 0) {
|
||||||
return DEFAULT_PRIORITY;
|
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 + "!",
|
throw new InsufficientVirtualNetworkCapacityException("Too many times fail-over happened! Current maximum priority is too high as " + maxPriority + "!",
|
||||||
network.getId());
|
network.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
priority = maxPriority - DEFAULT_DELTA + 1;
|
priority = maxPriority - DEFAULT_DELTA + 1;
|
||||||
}
|
}
|
||||||
return priority;
|
return priority;
|
||||||
@ -1589,6 +1591,7 @@ Configurable, StateListener<State, VirtualMachine.Event, VirtualMachine> {
|
|||||||
final boolean isRedundant = router.getIsRedundantRouter();
|
final boolean isRedundant = router.getIsRedundantRouter();
|
||||||
if (isRedundant) {
|
if (isRedundant) {
|
||||||
buf.append(" redundant_router=1");
|
buf.append(" redundant_router=1");
|
||||||
|
buf.append(" router_id=").append(router.getId());
|
||||||
|
|
||||||
final Long vpcId = router.getVpcId();
|
final Long vpcId = router.getVpcId();
|
||||||
final List<DomainRouterVO> routers;
|
final List<DomainRouterVO> routers;
|
||||||
@ -1599,13 +1602,16 @@ Configurable, StateListener<State, VirtualMachine.Event, VirtualMachine> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String redundantState = RedundantState.BACKUP.toString();
|
String redundantState = RedundantState.BACKUP.toString();
|
||||||
|
router.setRedundantState(RedundantState.BACKUP);
|
||||||
if (routers.size() == 0) {
|
if (routers.size() == 0) {
|
||||||
redundantState = RedundantState.MASTER.toString();
|
redundantState = RedundantState.MASTER.toString();
|
||||||
|
router.setRedundantState(RedundantState.MASTER);
|
||||||
} else {
|
} else {
|
||||||
final DomainRouterVO router0 = routers.get(0);
|
final DomainRouterVO router0 = routers.get(0);
|
||||||
|
|
||||||
if (router.getId() == router0.getId()) {
|
if (router.getId() == router0.getId()) {
|
||||||
redundantState = RedundantState.MASTER.toString();
|
redundantState = RedundantState.MASTER.toString();
|
||||||
|
router.setRedundantState(RedundantState.MASTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -129,4 +129,9 @@ class CsCmdLine(CsDataBag):
|
|||||||
def get_state(self):
|
def get_state(self):
|
||||||
if "redundant_state" in self.idata():
|
if "redundant_state" in self.idata():
|
||||||
return self.idata()['redundant_state']
|
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
|
||||||
@ -102,6 +102,7 @@ class CsRedundant(object):
|
|||||||
file.search(" priority ", " priority %s" % self.cl.get_priority())
|
file.search(" priority ", " priority %s" % self.cl.get_priority())
|
||||||
file.search(" weight ", " weight %s" % 2)
|
file.search(" weight ", " weight %s" % 2)
|
||||||
file.search(" state ", " state %s" % self.cl.get_state())
|
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.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR)
|
||||||
file.section("virtual_ipaddress {", "}", self._collect_ips())
|
file.section("virtual_ipaddress {", "}", self._collect_ips())
|
||||||
file.commit()
|
file.commit()
|
||||||
@ -122,7 +123,7 @@ class CsRedundant(object):
|
|||||||
if connt.is_changed():
|
if connt.is_changed():
|
||||||
CsHelper.service("conntrackd", "restart")
|
CsHelper.service("conntrackd", "restart")
|
||||||
|
|
||||||
if file.is_changed() and self.cl.get_state() == 'MASTER':
|
if file.is_changed():
|
||||||
CsHelper.service("keepalived", "restart")
|
CsHelper.service("keepalived", "restart")
|
||||||
|
|
||||||
# FIXME
|
# FIXME
|
||||||
|
|||||||
@ -38,8 +38,8 @@ vrrp_instance inside_network {
|
|||||||
|
|
||||||
advert_int 1
|
advert_int 1
|
||||||
authentication {
|
authentication {
|
||||||
auth_type PASS
|
auth_type AH
|
||||||
auth_pass WORD
|
auth_pass k33p@live
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual_ipaddress {
|
virtual_ipaddress {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user