3 Puppet::Type.type(:rabbitmq_queue).provide(:rabbitmqadmin) do
4 if Puppet::PUPPETVERSION.to_f < 3
5 commands rabbitmqctl: 'rabbitmqctl'
6 commands rabbitmqadmin: '/usr/local/bin/rabbitmqadmin'
8 has_command(:rabbitmqctl, 'rabbitmqctl') do
9 environment HOME: '/tmp'
11 has_command(:rabbitmqadmin, '/usr/local/bin/rabbitmqadmin') do
12 environment HOME: '/tmp'
15 confine feature: :posix
21 @should_vhost = resource[:name].rpartition('@').last
26 rabbitmqctl('list_vhosts', '-q').split(%r{\n})
29 def self.all_queues(vhost)
30 rabbitmqctl('list_queues', '-q', '-p', vhost, 'name', 'durable', 'auto_delete', 'arguments').split(%r{\n})
35 all_vhosts.each do |vhost|
36 all_queues(vhost).map do |line|
37 next if line =~ %r{^federation:}
38 name, durable, auto_delete, arguments = line.split("\t")
39 # Convert output of arguments from the rabbitmqctl command to a json string.
41 arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',')
42 arguments = '{}' if arguments == ''
48 auto_delete: auto_delete,
49 arguments: JSON.parse(arguments),
51 name: format('%s@%s', name, vhost)
53 resources << new(queue) if queue[:name]
59 def self.prefetch(resources)
61 resources.keys.each do |name|
62 if (provider = packages.find { |pkg| pkg.name == name })
63 resources[name].provider = provider
69 @property_hash[:ensure] == :present
73 vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
74 name = resource[:name].rpartition('@').first
75 arguments = resource[:arguments]
76 arguments = {} if arguments.nil?
77 rabbitmqadmin('declare',
80 "--user=#{resource[:user]}",
81 "--password=#{resource[:password]}",
83 '/etc/rabbitmq/rabbitmqadmin.conf',
85 "durable=#{resource[:durable]}",
86 "auto_delete=#{resource[:auto_delete]}",
87 "arguments=#{arguments.to_json}")
88 @property_hash[:ensure] = :present
92 vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
93 name = resource[:name].rpartition('@').first
94 rabbitmqadmin('delete', 'queue', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf', "name=#{name}")
95 @property_hash[:ensure] = :absent