Len
2014-Feb-12 12:01 UTC
[Puppet Users] Puppet Custom Provider. Class level and instance level methods/variable access issues
To all,
My ruby is failing me as I try to create a custom provider. I have a custom
provider I am writing that uses the net-ldap gem that will, based on the
custom type create, destroy and modify LDAP entries. What I am struggling
with is the difference between the class level methods: self.instance and
self.prefetch and instance level methods: create, destroy, etc.
As things currently stand I have in my custom provider code
def self.ldap_connection ## Class level method
Puppet.debug("Creating new LDAP connection")
unless @ldap_connection
@ldap_conection = Net::LDAP.new(
:host => '127.0.01',
.......
@ldap_connection
end
def self.prefetch ## Class level method
ldap_connection.search(:base => Services_Base, :filter =>
searchFilter ) do |entry|
.... <code to parse output>
results << new ( .... )
results
end
def create ## Instance level method
self.class.ldap_connection.add(:dn => mydn, :attributes => myattr)
end
The above all works fine, I can create and destory LDAP entries and modify
attributes based on my custom type without a problem. But if you look at
the self.ldap_connection I hard-coded the host. What I want to do, is
create a parameter in the type, called ldapserver, which I then can use in
self.ldap_connect.
I tried
@ldap_conection = Net::LDAP.new(
:host => @resource[:ldapserver],
But when I debug @resource[:ldapserver] it is nil so I'm obviously not
access it correctly. I also tried @@resource[:ldapserver] thinking resource
is a class level variable, but still no luck.
I've also tried to make def ldap_connection, so it is an instance level
method,but the I run into issues in self.instances where I need to open a
LDAP connection to prefetch, and the method is instance level, so not
available at the class level, self.instances.
Thanks
Len
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/d2eb2130-374c-4292-9412-cd01a32355c1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.