On Oct 7, 2008, at 8:18 AM, Sven Mueller wrote: > > I tried writing a type to handle a cobbler repository (because it is > the > first thing cobbler wants to see if you start to define a system). > However, I have two problems: > > 1) (this is a theoretical question for now) > > If I understand types (for now without providers) correctly, if I > have a > property ensure, it needs a "def retrieve" which returns the current > state of the resource. These returned states should match the > "newvalue" > definitions I provide in the source.
Essentially, yes. I recommend splitting it into type and provider, though, in which case your provider needs 'ensure' and 'ensure=' methods, and your type doesn't need any additional code beyond the newvalue statements. > So if I have > > newvalue :present > newvalue :absent > newvalue :insync > > with accompanying code, the following should work for retrieve: > > def retrieve > ret=`cobbler repo list | \ > grep -qE '(^|[[:space:]])#{resource[:name]}([[:space:]]|$)';\ > echo $?` > if ( not ret == 0) > :absent > else > if insync? > :insync > else > :present > end > end > end You don't call 'insync?' yourself -- Puppet calls it for you. 'retrieve' should just return the current value, which Puppet uses to determine if your resource is in sync. This is where the providers are really useful -- you can say 'commands :cobbler', and the providers will 1) provide a 'cobbler' method, so you can do: ret = cobbler "repo", "list", ... and 2) automatically indicate when a provider is non-functional because the 'cobbler' command is missing. It's a much better way to separate concerns. > > (As long as I have a working insync? definition) > Is this correct so far? If I defined insync? inside the same > newproperty > (:ensure in this case), should I access it as done above, or should I > use "self.insync?" or something else? > > 2) > I defined retrieve as listed above (full source of the cobbler_repo.rb > is at http://mail.incase.de/cobbler_repo.rb, it surely isn't the best > code I ever wrote, but I can't see why it shouldn't work) and I get: > > Tue Oct 07 15:14:02 +0200 2008 > //Node[testinst01]/cobbler/Cobbler_repo[CentOS5_i386] (err): Failed to > retrieve current state of resource: wrong number of arguments (1 for > 0) > > > Any hint what I did wrong? What passes one argument to which > function/method and what do I have to do to resolve this. I'm really > at > a loss here. The above should answer it for you, but in general, using --trace is a good way to get a stack trace, and asking dev questions on puppet-dev is likely to get faster dev help. -- Seize opportunity by the beard, for it is bald behind. -- Bulgarian Proverb --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---