Skip to content

Commit

Permalink
Support setting pacemaker resource defaults
Browse files Browse the repository at this point in the history
This patch adds initial support for pacemaker resource
defaults. Similarly as other pacemaker resource types in this module, it
doesn't yet prefetch already created resources.

The resource default can either be created directly via
pcmk_resource_default type, or in bulk via pacemaker::resource_defaults
class.
  • Loading branch information
jistr committed Sep 1, 2015
1 parent 1fa8e55 commit a2c8705
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/puppet/provider/pcmk_resource_default/pcs.rb
@@ -0,0 +1,54 @@
# Currently the implementation is somewhat naive (will not work great
# with ensure => absent, unless the correct current value is also
# specified). For more proper handling, prefetching should be
# implemented and `value` should be switched from a param to a
# property. This should be possible to do without breaking the
# interface of the resource type.
Puppet::Type.type(:pcmk_resource_default).provide(:pcs) do
desc 'Manages default values for pacemaker resource options via pcs'

def create
name = @resource[:name]
value = @resource[:value]

cmd = "resource defaults #{name}='#{value}'"

pcs(cmd)
end

def destroy
name = @resource[:name]

cmd = 'resource defaults #{name}='
pcs(cmd)
end

def exists?
name = @resource[:name]
value = @resource[:value]

cmd = 'resource defaults'
status, _ = pcs(cmd,
:grep => "^#{name}: #{value}$",
:allow_failure => true)
status == 0
end

def pcs(cmd, options={})
full_cmd = "pcs #{cmd}"

if options[:grep]
full_cmd += " | grep '#{options[:grep]}'"
end

Puppet.debug("Running #{full_cmd}")
output = `#{full_cmd}`
status = $?.exitstatus

if status != 0 && !options[:allow_failure]
raise Puppet::Error("#{full_cmd} returned #{status}, output: #{output}")
end

[status, output]
end
end
16 changes: 16 additions & 0 deletions lib/puppet/type/pcmk_resource_default.rb
@@ -0,0 +1,16 @@
require 'puppet/parameter/boolean'

Puppet::Type.newtype(:pcmk_resource_default) do
@doc = "A default value for pacemaker resource options"

ensurable

newparam(:name) do
desc "A unique name of the option"
end

newparam(:value) do
desc "A default value for the option"
end

end
12 changes: 12 additions & 0 deletions manifests/resource_defaults.pp
@@ -0,0 +1,12 @@
class pacemaker::resource_defaults(
$defaults,
$ensure = 'present',
) {
create_resources(
"pcmk_resource_default",
$defaults,
{
ensure => $ensure,
}
)
}

0 comments on commit a2c8705

Please sign in to comment.