X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Frabbitmq%2Flib%2Fpuppet%2Fprovider%2Frabbitmq_vhost%2Frabbitmqctl.rb;fp=3rdparty%2Fmodules%2Frabbitmq%2Flib%2Fpuppet%2Fprovider%2Frabbitmq_vhost%2Frabbitmqctl.rb;h=fbd389d87ddde86c1edb15524750f29421bf1310;hb=24caa46729f80fbba4be8b9b26ebcb3acc4cb0fb;hp=c2703611f4806104ffeb96d6e6ca91be80e7e526;hpb=c7e7bcc28cc5dc48a7e284a3c82f33df27d1f57d;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/rabbitmq/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb b/3rdparty/modules/rabbitmq/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb index c2703611f..fbd389d87 100644 --- a/3rdparty/modules/rabbitmq/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb +++ b/3rdparty/modules/rabbitmq/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb @@ -1,21 +1,23 @@ 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 @@ -28,6 +30,11 @@ Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, parent: Puppet::Provide 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