move providers/helper.rb to libraries/cib_objects.rb and extend
This commit is contained in:
parent
7e1fa9f68d
commit
984a284514
62
libraries/cib_objects.rb
Normal file
62
libraries/cib_objects.rb
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
require 'shellwords'
|
||||||
|
|
||||||
|
module Chef::Libraries
|
||||||
|
module Pacemaker
|
||||||
|
module CIBObjects
|
||||||
|
include Chef::Mixin::ShellOut
|
||||||
|
|
||||||
|
def get_cib_object_definition(name)
|
||||||
|
cmd = Mixlib::ShellOut.new("crm configure show #{name}")
|
||||||
|
cmd.environment['HOME'] = ENV.fetch('HOME', '/root')
|
||||||
|
cmd.run_command
|
||||||
|
begin
|
||||||
|
cmd.error!
|
||||||
|
cmd.stdout
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def cib_object_exists?(name)
|
||||||
|
! get_cib_object_definition(name).nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def cib_object_type(obj_definition)
|
||||||
|
unless obj_definition =~ /\A(\w+)\s/
|
||||||
|
raise "Couldn't extract CIB object type from '#{obj_definition}'"
|
||||||
|
end
|
||||||
|
return $1
|
||||||
|
end
|
||||||
|
|
||||||
|
def pacemaker_resource_running?(name)
|
||||||
|
cmd = shell_out! "crm", "resource", "status", name
|
||||||
|
Chef::Log.info cmd.stdout
|
||||||
|
cmd.stdout.include? "resource #{name} is running"
|
||||||
|
end
|
||||||
|
|
||||||
|
# CIB object definitions look something like:
|
||||||
|
#
|
||||||
|
# primitive keystone ocf:openstack:keystone \
|
||||||
|
# params os_username="crowbar" os_password="crowbar" os_tenant_name="openstack" \
|
||||||
|
# meta target-role="Started" is-managed="true" \
|
||||||
|
# op monitor interval="10s"
|
||||||
|
#
|
||||||
|
# This method extracts a Hash from one of the params / meta / op lines.
|
||||||
|
def extract_hash(name, obj_definition, data_type)
|
||||||
|
unless obj_definition =~ /^\s+#{data_type} (.+?)(\s*\\)?$/
|
||||||
|
raise "Couldn't retrieve #{data_type} for '#{name}' CIB object from [#{obj_definition}]"
|
||||||
|
end
|
||||||
|
|
||||||
|
h = {}
|
||||||
|
Shellwords.split($1).each do |kvpair|
|
||||||
|
unless kvpair =~ /^(.+?)=(.+)$/
|
||||||
|
raise "Couldn't understand '#{kvpair}' for #{data_type} section of '#{name}' primitive"
|
||||||
|
end
|
||||||
|
h[$1] = $2
|
||||||
|
end
|
||||||
|
h
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -17,7 +17,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.join(::File.dirname(__FILE__), 'helper')
|
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries cib_objects))
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.join(::File.dirname(__FILE__), 'helper')
|
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries cib_objects))
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
include Chef::Mixin::ShellOut
|
|
||||||
|
|
||||||
def resource_exists?(name)
|
|
||||||
cmd = Mixlib::ShellOut.new("crm configure show | grep #{name}")
|
|
||||||
cmd.environment['HOME'] = ENV.fetch('HOME', '/root')
|
|
||||||
cmd.run_command
|
|
||||||
begin
|
|
||||||
cmd.error!
|
|
||||||
true
|
|
||||||
rescue
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def resource_running?(name)
|
|
||||||
cmd = shell_out! "crm", "resource", "status", name
|
|
||||||
Chef::Log.info cmd.stdout
|
|
||||||
cmd.stdout.include? "resource #{name} is running"
|
|
||||||
end
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.join(::File.dirname(__FILE__), 'helper')
|
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries cib_objects))
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.join(::File.dirname(__FILE__), 'helper')
|
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries cib_objects))
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.join(::File.dirname(__FILE__), 'helper')
|
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries cib_objects))
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.join(::File.dirname(__FILE__), 'helper')
|
|
||||||
|
|
||||||
# For vagrant env, switch to the following 'require' command.
|
# For vagrant env, switch to the following 'require' command.
|
||||||
#require "/srv/chef/file_store/cookbooks/pacemaker/providers/helper"
|
#require "/srv/chef/file_store/cookbooks/pacemaker/providers/helper"
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
require ::File.join(::File.dirname(__FILE__), 'helper')
|
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries cib_objects))
|
||||||
|
|
||||||
action :create do
|
action :create do
|
||||||
name = new_resource.name
|
name = new_resource.name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user