I am working on updating types/providers for new functionality in Solaris. I need to take a list of properties (not their values) and modify them before any operations (checking current values, etc). Specifically, I will need to substitute '-' for '_' in the property names. What is the proper place for me to do this? In the provider or type? I am very new to Puppet, and don't want to implement a solution that isn't done the right way.
I know I'm being a bit vague, but this is in response to functional changes in Solaris, which aren't even integrated yet.
Hey Josh, thanks for the reply.
I'm still struggling with this. I have a hash of the values passed in from the manifest with the keys including '_' which need to be re-written.
properties => {'john_wayne' => '1', 'liberty_valance' => '0', ...}
this needs to become:
properties => {'john-wayne' => '1', 'liberty-valance' => '0', ...}
I believe this is where they are defined in my type:
newproperty(:properties) do
desc "A hash table of propname=propvalue entries to apply to the link"
end
So, I should write a method in the type to re-write the keys? Something like (forgive my ruby too):
def modify_keys(h)
h.keys.each do |k|
if(k.include? '_') then
h[k.gsub(/_/, '-')] = h[k]
h.delete(k)
end
end
end
Can I add a method like this to my property? How is such a method then called in the provider?
munge do |value| value.inject({}) do |xlated, kv|
k, v = kv
xlated[k.gsub(/_/, '-')] = v
end
end
Okay, I see. I can't add new keys while I am iterating, which makes sense. So, I need to create a new hash and then do a .merge when I'm done.