Module: Pacemaker::PcsCommon
- Included in:
- Puppet::Provider::PacemakerPCS
- Defined in:
- lib/pacemaker/pcs/common.rb
Overview
this submodule contains “pcs” based common functions
Instance Method Summary collapse
-
#debug_mode_enabled? ⇒ TrueClass, FalseClass
check if debug is enabled either in the pacemaker options or the resource has the ‘debug’ parameter and it’s enabled.
-
#pcs_list_to_hash(list) ⇒ Hash
parse a list of “key: value” data to a hash.
-
#pcs_safe(*args) ⇒ String, NilClass
safe pcs command.
Instance Method Details
#debug_mode_enabled? ⇒ TrueClass, FalseClass
check if debug is enabled either in the pacemaker options or the resource has the ‘debug’ parameter and it’s enabled
7 8 9 10 11 |
# File 'lib/pacemaker/pcs/common.rb', line 7 def debug_mode_enabled? return true if [:debug_enabled] return true if @resource && @resource.parameters.keys.include?(:debug) && @resource[:debug] false end |
#pcs_list_to_hash(list) ⇒ Hash
parse a list of “key: value” data to a hash
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pacemaker/pcs/common.rb', line 33 def pcs_list_to_hash(list) hash = {} list.split("\n").each do |line| line_arr = line.split ':' next unless line_arr.length == 2 name = line_arr[0].chomp.strip value = line_arr[1].chomp.strip next if name.empty? || value.empty? value = false if value == 'false' value = true if value == 'true' hash.store name, value end hash end |
#pcs_safe(*args) ⇒ String, NilClass
safe pcs command
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pacemaker/pcs/common.rb', line 16 def pcs_safe(*args) command_line = (['pcs'] + args).join ' ' if debug_mode_enabled? debug "Exec: #{command_line}" return end begin pcs *args rescue StandardError => exception debug "Command execution have failed: #{command_line}" raise exception end end |