On May 4, 2012, at 11:08 AM, Philip Brown wrote:
....
I dont see how to send some kind of message to the logs, "hey, something changed, but I'm fixing it".
In all cases I can think of, Puppet will do the appropriate logging, so you only need to worry about extra information like debugging.E.g., if you are using 'ensure' present, then when the transaction successfully calls 'ensure' on the provider, it will create an Event that has the property set to 'ensure', the previous_value set to 'absent', and the current_value set to 'present' (or something like that). Then this Event calls the 'notice' log method with the appropriate log message.So, your provider should focus 100% on function, and throwing errors where it can't do what it is supposed to, and the transaction should handle all logging and error management.In case it's not clear, you should very rarely have a conditional like you do with the 'exists?' method above - return true if it's there, false if it's not, but don't return a string. The system will treat the string as true, but that's probably not what you want.
Puppet::Type.type(:sysprop).provide(:solaris) dodesc "Provider for Solaris system properties"defaultfor :operatingsystem => :solarisdef createPuppet.debug "sysprop.create called"enddef destroyPuppet.debug "sysprop.destroy called"enddef exists?Puppet.debug "sysprop.exists? has not been written yet"return falseendend
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-dev/-/hIaCGhTtRO4J.--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppe...@googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
Hmm, i guess I slightly misunderstood: my ensure routine should return false or true, i guess.But I'm still missing info :(In my trivial example below, the "ensure" routine gets called and prints out its debug line. But the other routines do not.Instead, I seedebug: /Stage[main]//Sysprop[system/sac]: The container Class[Main] will propagate my refresh eventdebug: Class[Main]: The container Stage[main] will propagate my refresh event
but nothing else relevant happens :(Puppet::Type.type(:sysprop).provide(:solaris) dodesc "Provider for Solaris system properties"defaultfor :operatingsystem => :solarisdef createPuppet.debug "sysprop.create called"enddef destroyPuppet.debug "sysprop.destroy called"enddef exists?Puppet.debug "sysprop.exists? has not been written yet"return falseendend
--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-dev/-/qW6qeTMEq1QJ.
..
The main thing that Puppet really 'logs' is state transitions. (it also logs command on debug, but the thing it is really designe to do is describe system state transitions)- it a resource exists and is ensurable,- then resource can use the ensure property to describe if the thing should exist- exists will be used to query if the thing currently exists- true means it currently exists on the system- false indicates it does not- if the resource was specified as being in the ensure state present, then if the thing does not exist, then create will be called to ensure that it is in the state of presentIf this process occurs, the Puppet should log the state transition
*Almost* done with this beastie! Now I just have to force it to return "true" when things already look good!ruby is wierd. sigh. I have@resource[:value] claiming its value is "true"and the output of a command, in variable 'output', claming its value is "true".BUT...if output == @resource[:value]Puppet.debug "svcprop value is desired value. sysprop return true"return trueendis NOT returning true. "exists?" falling through and returning false. sighh...
On Saturday, May 5, 2012 6:42:31 AM UTC-7, Philip Brown wrote:
...
Now the only major ugliness left, is that on successful trigger, the --verbose output is:notice: /Stage[main]//Sysprop[network/smtp:sendmail]/ensure: createdI'd rather it said something different from "ensure: created" . A custom message would be nice.But I suppose I dont have any control over that.
You can set a custom message with the change_to_s method; see exec.rb for an example.
judging by all the xxx_to_s methods in the type directory though, there's some interesting functionality here, that *really* needs to be documented :(
On Saturday, May 5, 2012 3:35:10 PM UTC-7, Philip Brown wrote:judging by all the xxx_to_s methods in the type directory though, there's some interesting functionality here, that *really* needs to be documented :(wow. yes, it reaaaaly does.I ran across it in maillist.rb, asdef change_to_s(current_value, newvalue)return "Purged #{resource}" if newvalue == :purgedsuperendBut that really didnt tell me much of what the heck it is. and it still wasnt getting triggered for my prog! :(It took me digging around in the actual puppet core to realize that that routine would really be better named aschange_to_state(oldstate,newstate)!!
PS: oops, you didnt say which "exec.rb". provider/exec.rb does not have, but type/exec.rb does.I tried moving it into my type file, but it still does not seem to get called.
Sorry - I meant it needs to be in the definition of the relevant property, which in this case is 'ensure' (but in exec is 'returns').