From 08b4a74c90f812b393a514a1f09a58ef690c8b6e Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 27 May 2013 12:12:49 +0900 Subject: [PATCH] add property lwrp --- attributes/default.rb | 2 ++ providers/property.rb | 44 +++++++++++++++++++++++++++++++++++++++++++ recipes/config.rb | 7 +++++++ resources/property.rb | 25 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 providers/property.rb create mode 100644 resources/property.rb diff --git a/attributes/default.rb b/attributes/default.rb index bcfe8dc..1f8a6a7 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -77,3 +77,5 @@ default['pacemaker']['colocation']['c-cinder-volume']['active'] = "#{pacemaker[' default['pacemaker']['order']['o-lvm']['priority'] = "inf" default['pacemaker']['order']['o-lvm']['resources'] = ['drbd-cluster', 'clvm-clone', 'vip', 'cinder-volume'] default['pacemaker']['order']['o-lvm']['active'] = "#{pacemaker['nodes']}" + +default['pacemaker']['property']['no-quorum-policy'] = "ignore" diff --git a/providers/property.rb b/providers/property.rb new file mode 100644 index 0000000..f07552a --- /dev/null +++ b/providers/property.rb @@ -0,0 +1,44 @@ +# Author:: Robert Choi +# Cookbook Name:: pacemaker +# Provider:: property +# +# Copyright:: 2013, Robert Choi +# +# 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. +# + +require ::File.join(::File.dirname(__FILE__), 'helper') + +action :create do + name = new_resource.name + val = new_resource.value + + unless resource_exists?(name) + cmd = "crm configure property #{name}=#{val}" + + cmd_ = Mixlib::ShellOut.new(cmd) + cmd_.environment['HOME'] = ENV.fetch('HOME', '/root') + cmd_.run_command + begin + cmd_.error! + if resource_exists?(name) + new_resource.updated_by_last_action(true) + Chef::Log.info "Successfully configured property '#{name}'." + else + Chef::Log.error "Failed to configure property #{name}." + end + rescue + Chef::Log.error "Failed to configure property #{name}." + end + end +end diff --git a/recipes/config.rb b/recipes/config.rb index cfba86e..6a203aa 100644 --- a/recipes/config.rb +++ b/recipes/config.rb @@ -106,3 +106,10 @@ node['pacemaker']['order'].each do |name, attr| only_if { attr['active'].include?(node.name.partition(".")[0]) } end end + +node['pacemaker']['property'].each do |name, val| + pacemaker_property name do + value val + action :create + end +end diff --git a/resources/property.rb b/resources/property.rb new file mode 100644 index 0000000..3f6c66b --- /dev/null +++ b/resources/property.rb @@ -0,0 +1,25 @@ +# Author:: Robert Choi +# Cookbook Name:: pacemaker +# Resource:: property +# +# Copyright:: 2013, Robert Choi +# +# 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. +# + +actions :create + +default_action :create + +attribute :name, :kind_of => String, :name_attribute => true +attribute :value, :kind_of => String