chef/cookbooks/watcher/recipes/common.rb
#
# Cookbook Name:: watcher
# Recipe:: common
#
# Copyright 2019, SUSE LINUX GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
node[:watcher][:platform][:packages].each do |p|
package p
end
ha_enabled = node[:watcher][:ha][:enabled]
db_settings = fetch_database_settings
include_recipe "database::client"
include_recipe "#{db_settings[:backend_name]}::client"
include_recipe "#{db_settings[:backend_name]}::python-client"
crowbar_pacemaker_sync_mark "wait-watcher_database" if ha_enabled
# Create the Watcher Database
database "create #{node[:watcher][:db][:database]} database" do
connection db_settings[:connection]
database_name node[:watcher][:db][:database]
provider db_settings[:provider]
action :create
only_if { !ha_enabled || CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
database_user "create watcher database user" do
host "%"
connection db_settings[:connection]
username node[:watcher][:db][:user]
password node[:watcher][:db][:password]
provider db_settings[:user_provider]
action :create
only_if { !ha_enabled || CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
database_user "grant database access for watcher database user" do
connection db_settings[:connection]
username node[:watcher][:db][:user]
password node[:watcher][:db][:password]
database_name node[:watcher][:db][:database]
host "%"
privileges db_settings[:privs]
provider db_settings[:user_provider]
require_ssl db_settings[:connection][:ssl][:enabled]
action :grant
only_if { !ha_enabled || CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
crowbar_pacemaker_sync_mark "create-watcher_database" if ha_enabled
sql_connection = fetch_database_connection_string(node[:watcher][:db])
if node[:watcher][:sql_connection] != sql_connection
node.set[:watcher][:sql_connection] = sql_connection
node.save
end
# Register watcher service user
keystone_settings = KeystoneHelper.keystone_settings(node, @cookbook_name)
crowbar_pacemaker_sync_mark "wait-watcher_register_user" if ha_enabled
register_auth_hash = { user: keystone_settings["admin_user"],
password: keystone_settings["admin_password"],
project: keystone_settings["admin_project"] }
keystone_register "watcher wakeup keystone" do
protocol keystone_settings["protocol"]
insecure keystone_settings["insecure"]
host keystone_settings["internal_url_host"]
port keystone_settings["admin_port"]
auth register_auth_hash
action :wakeup
only_if { !ha_enabled || CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
keystone_register "register watcher user" do
protocol keystone_settings["protocol"]
insecure keystone_settings["insecure"]
host keystone_settings["internal_url_host"]
port keystone_settings["admin_port"]
auth register_auth_hash
user_name keystone_settings["service_user"]
user_password keystone_settings["service_password"]
project_name keystone_settings["service_tenant"]
action :add_user
only_if { !ha_enabled || CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
keystone_register "give watcher user access" do
protocol keystone_settings["protocol"]
insecure keystone_settings["insecure"]
host keystone_settings["internal_url_host"]
port keystone_settings["admin_port"]
auth register_auth_hash
user_name keystone_settings["service_user"]
project_name keystone_settings["service_tenant"]
role_name "admin"
action :add_access
only_if { !ha_enabled || CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
crowbar_pacemaker_sync_mark "create-watcher_register_user" if ha_enabled