From a8c9679919264efa9ae333736c07207f2f48fbf6 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 6 Feb 2014 13:24:37 +0000 Subject: [PATCH] rename Chef::Mixin::PacemakerCommon to Chef::Mixin::Pacemaker::StandardCIBObject --- libraries/chef/mixin/pacemaker.rb | 1 + .../mixin/pacemaker/standard_cib_object.rb | 55 +++++++++++++++++++ providers/colocation.rb | 7 ++- providers/common.rb | 54 ------------------ providers/primitive.rb | 7 ++- 5 files changed, 64 insertions(+), 60 deletions(-) create mode 100644 libraries/chef/mixin/pacemaker.rb create mode 100644 libraries/chef/mixin/pacemaker/standard_cib_object.rb delete mode 100644 providers/common.rb diff --git a/libraries/chef/mixin/pacemaker.rb b/libraries/chef/mixin/pacemaker.rb new file mode 100644 index 0000000..e78a4cf --- /dev/null +++ b/libraries/chef/mixin/pacemaker.rb @@ -0,0 +1 @@ +require File.expand_path('pacemaker/standard_cib_object.rb', File.dirname(__FILE__)) diff --git a/libraries/chef/mixin/pacemaker/standard_cib_object.rb b/libraries/chef/mixin/pacemaker/standard_cib_object.rb new file mode 100644 index 0000000..873851f --- /dev/null +++ b/libraries/chef/mixin/pacemaker/standard_cib_object.rb @@ -0,0 +1,55 @@ +require 'chef/application' +require ::File.expand_path('../../../pacemaker', ::File.dirname(__FILE__)) + +class Chef + module Mixin::Pacemaker + module StandardCIBObject + # Instantiate @current_resource and read details about the existing + # primitive (if any) via "crm configure show" into it, so that we + # can compare it against the resource requested by the recipe, and + # create / delete / modify as necessary. + # + # http://docs.opscode.com/lwrp_custom_provider_ruby.html#load-current-resource + def standard_load_current_resource + name = @new_resource.name + + cib_object = Pacemaker::CIBObject.from_name(name) + unless cib_object + ::Chef::Log.debug "CIB object definition nil or empty" + return + end + + unless cib_object.is_a? cib_object_class + expected_type = cib_object_class.description + ::Chef::Log.warn "CIB object '#{name}' was a #{cib_object.type} not a #{expected_type}" + return + end + + ::Chef::Log.debug "CIB object definition #{cib_object.definition}" + @current_resource_definition = cib_object.definition + cib_object.parse_definition + + @current_cib_object = cib_object + init_current_resource + end + + def standard_create_resource + cib_object = cib_object_class.from_chef_resource(new_resource) + cmd = cib_object.crm_configure_command + + ::Chef::Log.info "Creating new #{cib_object}" + + execute cmd do + action :nothing + end.run_action(:run) + + if cib_object.exists? + new_resource.updated_by_last_action(true) + ::Chef::Log.info "Successfully configured #{cib_object}" + else + ::Chef::Log.error "Failed to configure #{cib_object}" + end + end + end + end +end diff --git a/providers/colocation.rb b/providers/colocation.rb index 9c627c8..748cb1b 100644 --- a/providers/colocation.rb +++ b/providers/colocation.rb @@ -18,9 +18,10 @@ # require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) -require ::File.expand_path('common', ::File.dirname(__FILE__)) +require ::File.expand_path('../libraries/chef/mixin/pacemaker', + ::File.dirname(__FILE__)) -include Chef::Mixin::PacemakerCommon +include Chef::Mixin::Pacemaker::StandardCIBObject action :create do name = new_resource.name @@ -44,7 +45,7 @@ action :delete do end def cib_object_class - Pacemaker::Constraint::Colocation + ::Pacemaker::Constraint::Colocation end def load_current_resource diff --git a/providers/common.rb b/providers/common.rb deleted file mode 100644 index 2421c71..0000000 --- a/providers/common.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'chef/application' -require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) - -class Chef - module Mixin::PacemakerCommon - # Instantiate @current_resource and read details about the existing - # primitive (if any) via "crm configure show" into it, so that we - # can compare it against the resource requested by the recipe, and - # create / delete / modify as necessary. - # - # http://docs.opscode.com/lwrp_custom_provider_ruby.html#load-current-resource - def standard_load_current_resource - name = @new_resource.name - - cib_object = Pacemaker::CIBObject.from_name(name) - unless cib_object - ::Chef::Log.debug "CIB object definition nil or empty" - return - end - - unless cib_object.is_a? cib_object_class - expected_type = cib_object_class.description - ::Chef::Log.warn "CIB object '#{name}' was a #{cib_object.type} not a #{expected_type}" - return - end - - ::Chef::Log.debug "CIB object definition #{cib_object.definition}" - @current_resource_definition = cib_object.definition - cib_object.parse_definition - - @current_cib_object = cib_object - init_current_resource - end - - def standard_create_resource - cib_object = cib_object_class.from_chef_resource(new_resource) - cmd = cib_object.crm_configure_command - - ::Chef::Log.info "Creating new #{cib_object}" - - execute cmd do - action :nothing - end.run_action(:run) - - if cib_object.exists? - new_resource.updated_by_last_action(true) - ::Chef::Log.info "Successfully configured #{cib_object}" - else - ::Chef::Log.error "Failed to configure #{cib_object}" - end - end - - end -end diff --git a/providers/primitive.rb b/providers/primitive.rb index e712db8..7c36eff 100644 --- a/providers/primitive.rb +++ b/providers/primitive.rb @@ -18,9 +18,10 @@ # require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) -require ::File.expand_path('common', ::File.dirname(__FILE__)) +require ::File.expand_path('../libraries/chef/mixin/pacemaker', + ::File.dirname(__FILE__)) -include Chef::Mixin::PacemakerCommon +include Chef::Mixin::Pacemaker::StandardCIBObject action :create do name = new_resource.name @@ -81,7 +82,7 @@ action :stop do end def cib_object_class - Pacemaker::Resource::Primitive + ::Pacemaker::Resource::Primitive end def load_current_resource