require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl'))
-Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, parent: Puppet::Provider::Rabbitmqctl) do
+Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmqctl) do
+
if Puppet::PUPPETVERSION.to_f < 3
- commands rabbitmqctl: 'rabbitmqctl'
+ commands :rabbitmqctl => 'rabbitmqctl'
else
- has_command(:rabbitmqctl, 'rabbitmqctl') do
- environment HOME: '/tmp'
- end
+ has_command(:rabbitmqctl, 'rabbitmqctl') do
+ environment :HOME => "/tmp"
+ end
end
def self.instances
- vhost_list = run_with_retries do
+ self.run_with_retries {
rabbitmqctl('-q', 'list_vhosts')
- end
-
- vhost_list.split(%r{\n}).map do |line|
- raise Puppet::Error, "Cannot parse invalid vhost line: #{line}" unless line =~ %r{^(\S+)$}
- new(name: Regexp.last_match(1))
+ }.split(/\n/).map do |line|
+ if line =~ /^(\S+)$/
+ new(:name => $1)
+ else
+ raise Puppet::Error, "Cannot parse invalid user line: #{line}"
+ end
end
end
end
def exists?
- self.class.run_with_retries { rabbitmqctl('-q', 'list_vhosts') }.split(%r{\n}).include? resource[:name]
+ out = self.class.run_with_retries {
+ rabbitmqctl('-q', 'list_vhosts')
+ }.split(/\n/).detect do |line|
+ line.match(/^#{Regexp.escape(resource[:name])}$/)
+ end
end
+
end