empty value for provider setter

asked 2014-06-02 19:14:53 -0500

nerdysu gravatar image

I implemented a pair of type and provider for a new resource. I defined a series of new parameters for a provider, and it looks like this.

newparam(:name) do
    desc "description blah"

newproperty(:foo) do
    desc "foo property. This should be able to take empty value"

and in the provider, I wrote getter and setter for property foo

def foo

def foo=(value)
    # call cmd binary to set property

This resource works well when it the foo has a value, but if the value is not set, it triggers an error message.

# puppet resource my_property foo="bar"     // works well
# puppet resource my_property foo=""        // error
Error: Could not run: Invalid parameter setting foo=

foo="" is meant to be "property reset", and I wonder there is any way I can allow empty string for a property. This is by design of the command binary I'm utilizing so I need to pass down empty string somehow.

In type, I tried munge to get @resource.original_parameters[:foo] value and override it, but puppet even doesn't go inside the munge do block without parameter value.

edit retag flag offensive close merge delete


Did you ever figure this out? I think I'm just going to implement a munge on that looks for a 'None' and set to empty if that's the value.

flyinbutrs gravatar imageflyinbutrs ( 2015-10-24 14:34:26 -0500 )edit