diff --git a/lib/facter/stonith_levels.rb b/lib/facter/stonith_levels.rb new file mode 100644 index 000000000..8d8089b90 --- /dev/null +++ b/lib/facter/stonith_levels.rb @@ -0,0 +1,25 @@ +# Copyright 2016 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + +Facter.add('stonith_levels') do + setcode do + + hostname = Facter::Core::Execution.execute("crm_node -n 2> /dev/null", {}) + + stonith_levels = Facter::Core::Execution.execute("pcs stonith level | sed -n \"/^Target: #{hostname}$/,/^Target:/{/^Target: #{hostname}$/b;/^Target:/b;p}\" |tail -1 | awk '{print $2}' 2> /dev/null", {}) + + stonith_levels + end +end diff --git a/manifests/fencing.pp b/manifests/fencing.pp index d64cb05cf..4888cecdd 100644 --- a/manifests/fencing.pp +++ b/manifests/fencing.pp @@ -84,7 +84,7 @@ class tripleo::fencing( $content = $config['devices'] # check if the devices: section in fence.yaml contains levels. - # if it doesn't, assume level=1 an build a hash with the content. + # if it doesn't, assume level=1 and build a hash with the content. if is_array($content) { $all_levels = {'level1' => $content} } @@ -92,6 +92,26 @@ class tripleo::fencing( $all_levels = $content } + # collect the number of stonith levels currently defined for this system + # and convert it to integer. + $local_levels = 0 + $facts['stonith_levels'] + + # if the number of levels defined on this system is greather than the number in hiera + # we need to delete the delta. + if $local_levels > $all_levels.length { + $begin = $all_levels.length + 1 + range("${begin}", "${local_levels}").each |$level|{ + pacemaker::stonith::level{ "stonith-${level}": + ensure => 'absent', + level => $level, + target => '$(/usr/sbin/crm_node -n)', + stonith_resources => [''], + tries => $tries, + try_sleep => $try_sleep, + } + } + } + $all_levels.each |$index, $levelx_devices |{ $level = regsubst($index, 'level', '', 'G')