fuel-plugin-calico/deployment_scripts/calico-fuel-monitor

67 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python
import pyinotify
import subprocess
import yaml
from pluginutils import NODES_CONFIG
SCRIPTS_LOCATION="##REPLACE_ON_INSTALL##/"
RECONFIGURE_ROUTE_REFLECTOR = SCRIPTS_LOCATION + "calico_route_reflector.sh"
UPDATE_ETCD_CLUSTER = SCRIPTS_LOCATION + "update_etcd_cluster.sh"
def _get_configured_nodes(roles):
with open(NODES_CONFIG, "r") as f:
config = yaml.safe_load(f)
return [node for node in config["nodes"] if node["role"] in roles]
def _get_compute_nodes():
return _get_configured_nodes(["compute"])
def _get_control_nodes():
nodes = _get_configured_nodes(["controller", "primary-controller"])
for node in nodes:
# Note this does not change the node role in the Fuel deployment, just
# in the list of nodes internal to this script (where we are only
# concerned with the distinction between compute/control nodes, not
# whether a given control node is primary or not).
if node["role"] == "primary-controller":
node["role"] = "controller"
return nodes
class DeploymentChangeHandler(pyinotify.ProcessEvent):
def __init__(self):
super(DeploymentChangeHandler, self).__init__()
self.compute_nodes = _get_compute_nodes()
self.control_nodes = _get_control_nodes()
def process_IN_MODIFY(self, event):
current_compute_nodes = _get_compute_nodes()
current_control_nodes = _get_control_nodes()
if current_control_nodes != self.control_nodes:
subprocess.call(RECONFIGURE_ROUTE_REFLECTOR)
subprocess.call(UPDATE_ETCD_CLUSTER)
elif current_compute_nodes != self.compute_nodes:
subprocess.call(RECONFIGURE_ROUTE_REFLECTOR)
self.compute_nodes = current_compute_nodes
self.control_nodes = current_control_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()