Hi all,

I am trying to understand how self.instances is supposed to work.

I have implemented it as below (which I tried to construct based on examples
I found in puppet's source) :

  def self.instances
    rabbitmqctl('list_users').split(/\n/)[1..-2].collect do |line|
      if line =~ /^(\S+)\s+(\S+)$/
        new(:name => $1, :admin => $2)
      else
        raise Puppet::Error, "Cannot parse invalid user line: #{line}"
      end
    end
  end

By making a single call, I can retrieve all namevars and their properties
(which I return as an array of Provider instances)

When running:

puppet resource rabbitmq_user

I get the following error:

/vagrant/modules/rabbitmq/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb:41:in
`admin': undefined method `[]' for nil:NilClass (NoMethodError)
    from
/vagrant/modules/rabbitmq/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb:40:in
`each'
    from
/vagrant/modules/rabbitmq/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb:40:in
`admin'
    from /vagrant/puppet/lib/puppet/property.rb:246:in `send'
    from /vagrant/puppet/lib/puppet/property.rb:246:in `retrieve'
    from /vagrant/puppet/lib/puppet/type.rb:710:in `retrieve'
    from /vagrant/puppet/lib/puppet/type.rb:704:in `each'
    from /vagrant/puppet/lib/puppet/type.rb:704:in `retrieve'
    from /vagrant/puppet/lib/puppet/type.rb:718:in `retrieve_resource'
    from /vagrant/puppet/lib/puppet/type.rb:1893:in `to_trans'
    from /vagrant/puppet/lib/puppet/type.rb:1918:in `to_resource'
    from /vagrant/puppet/lib/puppet/indirector/resource/ral.rb:16:in
`search'
    from /vagrant/puppet/lib/puppet/indirector/resource/ral.rb:14:in `map'
    from /vagrant/puppet/lib/puppet/indirector/resource/ral.rb:14:in
`search'
    from /vagrant/puppet/lib/puppet/indirector/indirection.rb:248:in
`search'
    from /vagrant/puppet/lib/puppet/application/resource.rb:186:in `main'
    from /vagrant/puppet/lib/puppet/application.rb:315:in `run_command'
    from /vagrant/puppet/lib/puppet/application.rb:307:in `run'
    from /vagrant/puppet/lib/puppet/application.rb:411:in `hook'
    from /vagrant/puppet/lib/puppet/application.rb:307:in `run'
    from /vagrant/puppet/lib/puppet/application.rb:402:in `exit_on_fail'
    from /vagrant/puppet/lib/puppet/application.rb:307:in `run'
    from /vagrant/puppet/lib/puppet/util/command_line.rb:62:in `execute'
    from /vagrant/puppet/bin/puppet:4

The error is because retrieve is being called on the type (which causes
retrieve to be called for the admin property)

This causes the following code to be invoked:

  def admin
    #puts resource.inspect
    rabbitmqctl('list_users').split(/\n/)[1..-2].each do |line|
      return line.match(/^#{resource[:name]}\s+(\S+)$/)[1].to_sym
    end
    raise 'Admin field is only supported on version 2.4.1'
  end

which fails b/c resource is not set

my questions follow:

1. Am I doing something blatantly wrong?
2. Is self.instances just supposed to set parameters and then rely on
calling type.retrieve to fill in its properties?
       if this is the case, how am I supposed to set the :name param (or any
other params it may need)

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to