Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #216 from vuntz/tex-order-only-existing-array
Browse files Browse the repository at this point in the history
crowbar-pacemaker: Support String for ordering of order_only_existing
  • Loading branch information
vuntz committed Jan 15, 2016
2 parents 44c0cb7 + 54b85b0 commit 506de1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,33 @@ def delete_order(name)
end

action :create do
ordering = new_resource.ordering
# evil command line; there must be a better way to fetch the list of resources
# unfortunately, "crm_resource --list-raw" doesn't list groups/clones/etc.
all_resources = %x{crm --display=plain configure show | awk '/^(primitive|group|clone|ms)/ {print $2}'}.split("\n")
ordering_for_existing_resources = new_resource.ordering.select { |r| all_resources.include?(r) }
case ordering
when Array
ordering_for_existing_resources = ordering.select { |r| all_resources.include?(r) }
when String
# Try to ensure the syntax makes sense
raise "Sets in ordering cannot be nested." if ordering =~ /\([^\)]*[\(\[\]]/ || ordering =~ /\[[^\]]*[\[\(\)]/
# Only keep valid items, including what's valid in the crm syntax, which
# is:
# - foo ( bar foobar ) xyz
# - foo [ bar foobar ] xyz
# - foo [ bar foobar sequantial=true ] xyz
# - foo [ bar foobar require-all=true ] xyz
ordering_array = ordering.split(" ")
existing_ordering_array = ordering_array.select do |r|
all_resources.include?(r) || %w{( ) [ ]}.include?(r) || r =~ /sequential=/ || r =~ /require-all=/
end
# Drop empty sets; we don't want something like:
# order Mandatory: foo ( ) bar
# It should become:
# order Mandatory: foo bar
existing_ordering = existing_ordering_array.join(" ").gsub(/[\(\[](( sequential=[^ ]*)|( require-all=[^ ]*))* [\)\]]/, "")
ordering_for_existing_resources = existing_ordering.split(" ")
end

if ordering_for_existing_resources.length <= 1
delete_order(new_resource.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@
attribute :name, :kind_of => String, :name_attribute => true
attribute :score, :kind_of => String
attribute :ordering, :kind_of => Array
attribute :ordering, :kind_of => [Array, String]

0 comments on commit 506de1e

Please sign in to comment.