Fixed CsAddress destroying the VIP address on a redundant router

Taken quite a bit of code out of CsRedundant
Fixed public IP in keepalived when there is no guest network
This commit is contained in:
Ian Southam 2015-01-28 15:20:45 +01:00 committed by wilderrodrigues
parent 6d34f1f797
commit bf6e3fa8b2
3 changed files with 37 additions and 32 deletions

View File

@ -28,6 +28,7 @@ from CsRule import CsRule
VRRP_TYPES = ['guest'] VRRP_TYPES = ['guest']
class CsAddress(CsDataBag): class CsAddress(CsDataBag):
def compare(self): def compare(self):

View File

@ -38,6 +38,7 @@ import logging
import CsHelper import CsHelper
from CsFile import CsFile from CsFile import CsFile
from CsConfig import CsConfig from CsConfig import CsConfig
from CsProcess import CsProcess
class CsRedundant(object): class CsRedundant(object):
@ -63,8 +64,7 @@ class CsRedundant(object):
def set(self): def set(self):
logging.debug("Router redundancy status is %s", self.cl.is_redundant()) logging.debug("Router redundancy status is %s", self.cl.is_redundant())
guest = self.address.get_guest_if() if self.cl.is_redundant():
if self.cl.is_redundant() and guest:
self._redundant_on() self._redundant_on()
else: else:
self._redundant_off() self._redundant_off()
@ -99,19 +99,24 @@ class CsRedundant(object):
# keepalived configuration # keepalived configuration
file = CsFile(self.KEEPALIVED_CONF) file = CsFile(self.KEEPALIVED_CONF)
file.search(" router_id ", " router_id %s" % self.cl.get_name()) file.search(" router_id ", " router_id %s" % self.cl.get_name())
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.search(" state ", " state %s" % "EQUAL")
# 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)
# If there is no guest network still bring up the public interface
# Maybe necessary for things like VPNs and private gateways
if self.address.get_guest_if():
file.section("virtual_ipaddress {", "}", self._collect_ips()) file.section("virtual_ipaddress {", "}", self._collect_ips())
if self.cl.get_state() == 'MASTER': # if self.cl.get_state() == 'MASTER':
file.search(" priority ", " priority %s" % 120) # file.search(" priority ", " priority %s" % 100)
file.commit() file.commit()
# conntrackd configuration # conntrackd configuration
guest = self.address.get_guest_if() guest = self.address.get_guest_if()
connt = CsFile(self.CONNTRACKD_CONF) connt = CsFile(self.CONNTRACKD_CONF)
if guest is not None:
connt.section("Multicast {", "}", [ connt.section("Multicast {", "}", [
"IPv4_address 225.0.0.50\n", "IPv4_address 225.0.0.50\n",
"Group 3780\n", "Group 3780\n",
@ -122,6 +127,7 @@ class CsRedundant(object):
"Checksum on\n"]) "Checksum on\n"])
connt.section("Address Ignore {", "}", self._collect_ignore_ips()) connt.section("Address Ignore {", "}", self._collect_ignore_ips())
connt.commit() connt.commit()
if connt.is_changed(): if connt.is_changed():
CsHelper.service("conntrackd", "restart") CsHelper.service("conntrackd", "restart")
@ -138,6 +144,10 @@ class CsRedundant(object):
cron.add("*/1 * * * * root $SHELL %s/check_heartbeat.sh 2>&1 > /dev/null" % self.CS_ROUTER_DIR, -1) cron.add("*/1 * * * * root $SHELL %s/check_heartbeat.sh 2>&1 > /dev/null" % self.CS_ROUTER_DIR, -1)
cron.commit() cron.commit()
proc = CsProcess(['/usr/sbin/keepalived', '--vrrp'])
if not proc.find():
CsHelper.service("keepalived", "restart")
def set_fault(self): def set_fault(self):
""" Set fault mode on this router """ """ Set fault mode on this router """
if not self.cl.is_redundant(): if not self.cl.is_redundant():
@ -177,9 +187,9 @@ class CsRedundant(object):
CsHelper.service("xl2tpd", "stop") CsHelper.service("xl2tpd", "stop")
CsHelper.service("cloud-passwd-srvr", "stop") CsHelper.service("cloud-passwd-srvr", "stop")
CsHelper.service("dnsmasq", "stop") CsHelper.service("dnsmasq", "stop")
self._set_priority(self.CS_PRIO_DOWN) # self._set_priority(self.CS_PRIO_DOWN)
self.cl.dbag['config']['redundant_master'] = "false" self.cl.dbag['config']['redundant_master'] = "false"
#CsHelper.service("keepalived", "restart") # CsHelper.service("keepalived", "restart")
self.cl.save() self.cl.save()
logging.info("Router switched to backup mode") logging.info("Router switched to backup mode")
@ -212,15 +222,9 @@ class CsRedundant(object):
CsHelper.service("dnsmasq", "restart") CsHelper.service("dnsmasq", "restart")
self.cl.dbag['config']['redundant_master'] = "true" self.cl.dbag['config']['redundant_master'] = "true"
self.cl.save() self.cl.save()
#CsHelper.service("keepalived", "restart") # CsHelper.service("keepalived", "restart")
logging.info("Router switched to master mode") logging.info("Router switched to master mode")
def _set_priority(self, dir):
self.cl.set_priority(int(self.cl.get_priority()) + dir)
file = CsFile(self.KEEPALIVED_CONF)
file.search(" priority ", " priority %s" % self.cl.get_priority())
file.commit()
def _collect_ignore_ips(self): def _collect_ignore_ips(self):
""" """
This returns a list of ip objects that should be ignored This returns a list of ip objects that should be ignored