On Fri, Jun 14, 2013 at 7:22 AM, Drew Fisher <[email protected]>wrote:
> I'm looking for some tips and understanding on how user defined attributes
> work with newproperty() calls.
>
> For example, lets say I am defining a new type and I have:
>
> Puppet::Type.newtype(:foobar) do
> ensurable
>
> newparam(:name) do
> desc "some description here"
> isnamevar
> end
>
> newproperty(:baz, :a => :b) do
> desc "some description here"
> end
> end
>
> tracing through the calls in type.rb and util/classgen.rb I see that we
> get here:
>
> if attrs = options[:attributes]
> attrs.each do |param, value|
> method = param.to_s + "="
> klass.send(method, value) if klass.respond_to? method <<------
> end
> end
>
> What do I need to define in order to get the klass.send(...) call to
> process? Everything I've tried so far fails to register a method with the
> klass so its never ever sent. I can see that the attrs hash has {:a => :b}
> so I know it's there, I just don't know how to get it added to the klass
> itself.
>
You can access the values in the resource type. As an example you can see:
https://github.com/vmware/vmware-vmware_lib/blob/master/lib/puppet/property/vmware.rb#L70-L116
The :sort and :inclusive values are used to specify whether we want to sort
the array or perform inclusive comparison (look at the
vmware_vcenter/vshield modules for examples).
newproperty(:order_matters, :array_matching => :all, :sort => :false,
:parent => Puppet::Property::VMware_Array ) do
end
newproperty(:order_doesnt_matters, :array_matching => :all, :sort => :true,
:parent => Puppet::Property::VMware_Array ) do
end
(Don't ask about the symbol :true/:false, booleans are a pain in Puppet)
Also, once I have the type able to accept user defined attributes, how do I
> access them in the provider itself?
>
This a per resource type value, so it won't be uniq per resource. It makes
more sense if you use it for validate/munge or some other function in the
resource type. I suppose if you need it in the provider use munge and store
it for access later.
newproperty(:baz, :a => :b) do
desc "some description here"
def munge value
self[:value_a] = self.class.a
value
end
end
newparam(:value_a) do
desc "not really intended for user to specify"
end
Not sure if there's a better way. IMO, if you are not using { :a => 'value'
} in the resource type, then you might as well specify it in the provider.
HTH,
Nan
--
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.
For more options, visit https://groups.google.com/groups/opt_out.