]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/rabbitmq/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb
move to puppetlabs rabbitmq module
[dsa-puppet.git] / 3rdparty / modules / rabbitmq / lib / puppet / provider / rabbitmq_plugin / rabbitmqplugins.rb
1 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl'))
2 Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, :parent => Puppet::Provider::Rabbitmqctl) do
3
4   if Puppet::PUPPETVERSION.to_f < 3
5     if Facter.value(:osfamily) == 'RedHat'
6       commands :rabbitmqplugins => '/usr/lib/rabbitmq/bin/rabbitmq-plugins'
7     else
8       commands :rabbitmqplugins => 'rabbitmq-plugins'
9     end
10   else
11     if Facter.value(:osfamily) == 'RedHat'
12       has_command(:rabbitmqplugins, '/usr/lib/rabbitmq/bin/rabbitmq-plugins') do
13         environment :HOME => "/tmp"
14       end
15     else
16       has_command(:rabbitmqplugins, 'rabbitmq-plugins') do
17         environment :HOME => "/tmp"
18       end
19     end
20   end
21
22   defaultfor :feature => :posix
23
24   def self.instances
25     self.run_with_retries {
26       rabbitmqplugins('list', '-E', '-m')
27     }.split(/\n/).map do |line|
28       if line =~ /^(\S+)$/
29         new(:name => $1)
30       else
31         raise Puppet::Error, "Cannot parse invalid plugins line: #{line}"
32       end
33     end
34   end
35
36   def create
37     rabbitmqplugins('enable', resource[:name])
38   end
39
40   def destroy
41     rabbitmqplugins('disable', resource[:name])
42   end
43
44   def exists?
45     self.class.run_with_retries {
46       rabbitmqplugins('list', '-E', '-m')
47     }.split(/\n/).detect do |line|
48       line.match(/^#{resource[:name]}$/)
49     end
50   end
51
52 end