On Apr 29, 2013, at 2:39 PM, Stefan Schulte
<[email protected]> wrote:
> 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
I don't remember specifically why this is here. I assume it's related
to the below, which is that if we dupe this, then the system loses
track of the two fields being equal. Or something. See below.
> 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 *think* I did this because there's a bunch of magic around
title/name, and if we end up with both, that magic doesn't work.
This was so long ago that that's about the best I can do, and I'm
pretty sure I wrote this, so I'm not sure if the info is retained
anywhere...
> 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.
>
>
--
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.