From 9016f01585bdf6e3e6fbf21543c240681f65fcbe Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Wed, 4 Jan 2017 16:30:54 +0100 Subject: [PATCH] crowbar: Generate an event when a cluster config is changed For now, we're only interested in changes in the public/admin name of haproxy. This event will be consumed by OpenStack barclamp so they know that the endpoint is changing. We may add other relevant attributes to the event later on if required. --- .../app/models/pacemaker_service.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crowbar_framework/app/models/pacemaker_service.rb b/crowbar_framework/app/models/pacemaker_service.rb index 727b0fbf..97ef7889 100644 --- a/crowbar_framework/app/models/pacemaker_service.rb +++ b/crowbar_framework/app/models/pacemaker_service.rb @@ -15,6 +15,8 @@ # limitations under the License. # +require "set" + class PacemakerService < ServiceObject def initialize(thelogger) super(thelogger) @@ -439,6 +441,30 @@ def apply_role_post_chef_call(old_role, role, all_nodes) apply_cluster_roles_to_new_nodes_post_chef_call(role) + # let's not consider the first time the proposal is applied as worth + # sending an event + if !old_role.nil? && !role.nil? + old_attributes = old_role.default_attributes["pacemaker"] + new_attributes = role.default_attributes["pacemaker"] + + changed_attributes = Set.new + + if old_attributes["haproxy"]["public_name"] != new_attributes["haproxy"]["public_name"] + changed_attributes.add("haproxy.public_name") + end + if old_attributes["haproxy"]["admin_name"] != new_attributes["haproxy"]["admin_name"] + changed_attributes.add("haproxy.admin_name") + end + + unless changed_attributes.empty? + details = { + cluster: "#{PacemakerServiceObject.cluster_key}:#{role.inst}", + attributes: changed_attributes + } + Crowbar::EventDispatcher.trigger_hooks("cluster_changed", details) + end + end + @logger.debug("Pacemaker apply_role_post_chef_call: leaving") end