I'm currently trying to resolve issues around composite namevars but
there is one thing I do not understand:
1) It is common practice to ommit the namevar when declaring a resource
in a puppet manifest, because it is implicitly set by the title so in a
lot of cases resource[:title] equals resource[:name] (and
resource[:name] internally resolves
to resource[:whatever_the_namevar_is])
2) We also have to be able to generate a title from the namevar, so if
we do not have a title we just set resource[:title] = resource[:name].
E.g. if I run "puppet resource service" puppet will parse /etc/init.d
to get a list of service names and will automatically create titles for
these resources.
These two points are pretty clear to and I know how to get the same
behaviour with multiple namevars. But what I do not understand is that
there are actual code paths that try to remove the namevar when it is
equal to the title, e.g.
lib/puppet/resource.rb:
def to_pson_data_hash
[...]
params = self.to_hash.inject({}) do |hash, ary|
param, value = ary
# Don't duplicate the title as the namevar
next hash if param == namevar and value == title
hash[param] = Puppet::Resource.value_to_pson_data(value)
hash
end
[...]
end
or
lib/puppet/type.rb:
def to_resource
[...]
@parameters.each do |name, param|
# Avoid adding each instance name twice
next if param.class.isnamevar? and param.value == self.title
[...]
resource[name] = param.value
end
resource
end
I do not quite understand why this is done (besides saving a few bytes)
and it will get a lot harder if I have to preserve this behaviour with
multiple namevars (I'd have to check if the title, after parsing it
with title_patterns, results in the same values for the namevars. And
in case of the first example I first have to check
resource_type.key_attributes to actually find out what the namevars are.
So can anyone give me some background info about the current behaviour?
-Stefan
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.