3 Puppet::Type.type(:rabbitmq_queue).provide(:rabbitmqadmin) do
5 if Puppet::PUPPETVERSION.to_f < 3
6 commands :rabbitmqctl => 'rabbitmqctl'
7 commands :rabbitmqadmin => '/usr/local/bin/rabbitmqadmin'
9 has_command(:rabbitmqctl, 'rabbitmqctl') do
10 environment :HOME => "/tmp"
12 has_command(:rabbitmqadmin, '/usr/local/bin/rabbitmqadmin') do
13 environment :HOME => "/tmp"
16 defaultfor :feature => :posix
22 @should_vhost = resource[:name].rpartition('@').last
28 rabbitmqctl('list_vhosts', '-q').split(/\n/).collect do |vhost|
34 def self.all_queues(vhost)
35 rabbitmqctl('list_queues', '-q', '-p', vhost, 'name', 'durable', 'auto_delete', 'arguments').split(/\n/)
40 all_vhosts.each do |vhost|
41 all_queues(vhost).collect do |line|
42 name, durable, auto_delete, arguments = line.split()
43 # Convert output of arguments from the rabbitmqctl command to a json string.
45 arguments = arguments.gsub(/^\[(.*)\]$/, "").gsub(/\{("(?:.|\\")*?"),/, '{\1:').gsub(/\},\{/, ",")
54 :auto_delete => auto_delete,
55 :arguments => JSON.parse(arguments),
57 :name => "%s@%s" % [name, vhost],
59 resources << new(queue) if queue[:name]
65 def self.prefetch(resources)
67 resources.keys.each do |name|
68 if provider = packages.find{ |pkg| pkg.name == name }
69 resources[name].provider = provider
75 @property_hash[:ensure] == :present
79 vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
80 name = resource[:name].rpartition('@').first
81 arguments = resource[:arguments]
85 rabbitmqadmin('declare',
88 "--user=#{resource[:user]}",
89 "--password=#{resource[:password]}",
91 '/etc/rabbitmq/rabbitmqadmin.conf',
93 "durable=#{resource[:durable]}",
94 "auto_delete=#{resource[:auto_delete]}",
95 "arguments=#{arguments.to_json}"
97 @property_hash[:ensure] = :present
101 vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
102 name = resource[:name].rpartition('@').first
103 rabbitmqadmin('delete', 'queue', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf', "name=#{name}")
104 @property_hash[:ensure] = :absent