Tim Stoop
2010-Feb-04 15:22 UTC
[Puppet Users] Wrapping built-in types with defined types, how to do it?
Hi all, Due to some automation we want to set in place, I''d like to write my own wrapper around several built-in types. Is there an easy way to tell a defined type to allow all options that another type allows and then some? What I''m looking for, really, is some equivalent to (sorry Luke) Python''s **kw argument. Is that currently possible? If not, how would you view a feature request to that end? If I need to name all options that my new defined type allows, so it can pass them all on to the built-in type I''m writing the wrapper for, what''s the best way to define them in the definition? False or undef? So like: mypkg ($ensure = "installed", $responsefile = false) { ... do stuff, including calling package { $name: ensure => $ensure, responsefile => $responsefile } } Or: mypkg ($ensure = "installed", $responsefile = undef) { ... do stuff, including calling package { $name: ensure => $ensure, responsefile => $responsefile } } I want to recreate package{}''s behaviour as closely as possible, of course. Thanks for any sort of advice in this! -- Kind regards, Tim Stoop (tim|macbook or tim|imac on IRC) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Dan Bode
2010-Feb-07 04:57 UTC
Re: [Puppet Users] Wrapping built-in types with defined types, how to do it?
Hi Tim, This post might have been more appropriate for the dev list, but Ill take a stab at it. On Thu, Feb 4, 2010 at 7:22 AM, Tim Stoop <tim.stoop@gmail.com> wrote:> Hi all, > > Due to some automation we want to set in place, I''d like to write my > own wrapper around several built-in types. Is there an easy way to > tell a defined type to allow all options that another type allows and > then some? What I''m looking for, really, is some equivalent to (sorry > Luke) Python''s **kw argument.Is that the same as Project R''s ... ? Is that currently possible? If not, how> would you view a feature request to that end? >I think its pretty reasonable (but I''m also not on the dev team) :). I think its worth opening up a ticket for. This does not exist if you are doing the implementation in Puppet. I think you can do something similar with inheritance if you implement a type/provider in Ruby (although this is currently beyond me)> If I need to name all options that my new defined type allows, so it > can pass them all on to the built-in type I''m writing the wrapper for, > what''s the best way to define them in the definition? False or undef? > So like: > > mypkg ($ensure = "installed", $responsefile = false) { ... do stuff, > including calling package { $name: ensure => $ensure, responsefile => > $responsefile } } > > Or: > > mypkg ($ensure = "installed", $responsefile = undef) { ... do stuff, > including calling package { $name: ensure => $ensure, responsefile => > $responsefile } } >undef is actually an alias to '''' when used during variable assignment. There is no way to pass undef from a defined resource attribute to another resource (I assume this is your goal). Your request might be related to the patch for http://projects.reductivelabs.com/issues/2818, expected in Rwolf (although I haven''t read the code, and they don''t discuss the solution in the ticket). I would use undef (understanding that for now its really just '''') and then use conditionals inside of the defined resource type to make things act as expected. The best way to handle this is to figure out which attributes you care about, add them to the defined resource type and ignore the rest. Otherwise, you wind up with lots of logic like: package{ ... x => $x? {'''' => undef, default => $x} ... } which is pretty ugly.> I want to recreate package{}''s behaviour as closely as possible, of > course. > >Someone feel free to jump in if you have any better suggestions :) Thanks for any sort of advice in this!> > -- > Kind regards, > Tim Stoop (tim|macbook or tim|imac on IRC) > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.