Update route reflector configuration when compute nodes are added to/removed from the deployment

Change-Id: I5443489a0921594381832a0ee2fedb384e85e4a9
This commit is contained in:
Emma Gordon 2015-07-14 17:35:05 +01:00
parent 85ddb63714
commit 8cd61d75c1
4 changed files with 89 additions and 4 deletions

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
import pyinotify
import subprocess
import yaml
from pluginutils import NODES_CONFIG
RECONFIGURE_ROUTE_REFLECTOR = "##REPLACE_ON_INSTALL##/calico_route_reflector.sh"
def _get_configured_compute_nodes():
with open(NODES_CONFIG, "r") as f:
config = yaml.safe_load(f)
compute_nodes = [node for node in config["nodes"]
if node["role"] == "compute"]
return compute_nodes
class DeploymentChangeHandler(pyinotify.ProcessEvent):
def __init__(self):
super(DeploymentChangeHandler, self).__init__()
self.compute_nodes = _get_configured_compute_nodes()
def process_IN_MODIFY(self, event):
current_compute_nodes = _get_configured_compute_nodes()
if current_compute_nodes != self.compute_nodes:
subprocess.call(RECONFIGURE_ROUTE_REFLECTOR)
self.compute_nodes = current_compute_nodes
if __name__ == "__main__":
handler = DeploymentChangeHandler()
watch_manager = pyinotify.WatchManager()
notifier = pyinotify.Notifier(watch_manager, handler)
watch_manager.add_watch(NODES_CONFIG, pyinotify.IN_MODIFY)
notifier.loop()

View File

@ -181,4 +181,41 @@ iptables -I INPUT 1 -p tcp --dport 179 -j ACCEPT
# controller is rebooted.
iptables-save > /etc/iptables/rules.v4
# Set up a service, calico-fuel-monitor, that will detect changes to the
# deployment and reconfigure the calico components on the controller as
# needed. For example, updating the route reflector configuration after
# compute nodes are added/removed from the deployment.
SERVICE_NAME=calico-fuel-monitor
# Install the service's dependencies.
apt-get -y install python-pip
pip install pyinotify pyaml
# During node deployment, the plugin deployment scripts are copied into
# /etc/fuel/plugins/<plugin_name>-<plugin_version> on the node, and this
# script is run from that directory.
SERVICE_DIR=$(pwd)
sed -i "s@##REPLACE_ON_INSTALL##@${SERVICE_DIR}@" $SERVICE_NAME
chmod +x $SERVICE_NAME
cat << SERVICE_CFG >> /etc/init/calico-fuel-monitor.conf
# calico-fuel-monitor - daemon to monitor for fuel deployment changes and
# reconfigure the calico components accordingly
description "Calico daemon to monitor fuel deployment changes"
author "Emma Gordon <emma@projectcalico.org>"
start on runlevel [2345]
stop on runlevel [016]
respawn
script
cd ${SERVICE_DIR}
exec ./${SERVICE_NAME}
end script
SERVICE_CFG
service $SERVICE_NAME start
exit 0

View File

@ -2,12 +2,11 @@
# Copyright 2015 Metaswitch Networks
import yaml
from pluginutils import get_config_file_for_node_type
from pluginutils import NODES_CONFIG
def main():
config_file = get_config_file_for_node_type()
with open(config_file, "r") as f:
with open(NODES_CONFIG, "r") as f:
config = yaml.safe_load(f)
# The route reflector should only peer with compute nodes.

View File

@ -3,6 +3,15 @@
import os
# This config file is updated with the latest node details as the deployment
# evolves. It only contains node details, not other config settings.
NODES_CONFIG = "/etc/hiera/nodes.yaml"
# These config files contain details of the nodes at initial deployment, but
# they are not subsequently updated with node changes. However, they contain
# a greater range of information, including settings and network config. They
# are also created on the system earlier in the deployment process, so are
# good sources of initial node information during Calico setup.
PRIMARY_CONTROLLER_CFG = "/etc/primary-controller.yaml"
CONTROLLER_CFG = "/etc/controller.yaml"
COMPUTE_CFG = "/etc/compute.yaml"