I''d like to reuse the same ruby code in a type across all the providers. For the type I''m writing, a certain portion of the "exists?" method would be repeated across all providers. From looking at the documentation, http://docs.puppetlabs.com/guides/custom_types.html, it''s not quite clear how I can accomplish this. I''ve looked at writing a function, but that seems to be for a larger scope than I''d like (only the providers in that module would need this code) and requires a restart of the puppet master. Thanks! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/Q87FSKhWhmUJ. 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.
Nan Liu
2012-Jul-17 16:49 UTC
Re: [Puppet Users] Method across providers for the same type
On Tue, Jul 17, 2012 at 8:34 AM, ZJE <countach44@gmail.com> wrote:> I''d like to reuse the same ruby code in a type across all the providers. For > the type I''m writing, a certain portion of the "exists?" method would be > repeated across all providers. From looking at the documentation, > http://docs.puppetlabs.com/guides/custom_types.html, it''s not quite clear > how I can accomplish this. I''ve looked at writing a function, but that > seems to be for a larger scope than I''d like (only the providers in that > module would need this code) and requires a restart of the puppet master.Look at puppetlabs registry provider[1] for an example where modules/registry is shared between registry_key and registry_value. Nan 1. https://github.com/puppetlabs/puppetlabs-registry/tree/master/lib/puppet -- 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.
Jeff McCune
2012-Jul-17 17:29 UTC
Re: [Puppet Users] Method across providers for the same type
On Tue, Jul 17, 2012 at 9:49 AM, Nan Liu <nan@puppetlabs.com> wrote:> On Tue, Jul 17, 2012 at 8:34 AM, ZJE <countach44@gmail.com> wrote: > > I''d like to reuse the same ruby code in a type across all the providers. > For > > the type I''m writing, a certain portion of the "exists?" method would be > > repeated across all providers. From looking at the documentation, > > http://docs.puppetlabs.com/guides/custom_types.html, it''s not quite > clear > > how I can accomplish this. I''ve looked at writing a function, but that > > seems to be for a larger scope than I''d like (only the providers in that > > module would need this code) and requires a restart of the puppet master. > > Look at puppetlabs registry provider[1] for an example where > modules/registry is shared between registry_key and registry_value.We''ve actually got this wrong in the registry module currently. Shared utility code should not go into the Puppet namespace at all. The convention we''ve "standardized" [1] on is: "Start with PuppetX, put the CamelCase of your author name (from the Modulefile), then put the actual CamelCase of your module name" So the registry module should be PuppetX::PuppetLabs::Registry living in ''<modulepath>/registry/lib/puppet_x/puppet_labs/registry.rb'' Puppet::Modules::Registry is a bad example and should not be followed. [1] http://projects.puppetlabs.com/issues/14149 -Jeff -- 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.
On Tuesday, July 17, 2012 12:29:52 PM UTC-5, Jeff McCune wrote:> > On Tue, Jul 17, 2012 at 9:49 AM, Nan Liu <> wrote: > >> On Tue, Jul 17, 2012 at 8:34 AM, ZJE <> wrote: >> > I''d like to reuse the same ruby code in a type across all the >> providers. For >> > the type I''m writing, a certain portion of the "exists?" method would be >> > repeated across all providers. From looking at the documentation, >> > http://docs.puppetlabs.com/guides/custom_types.html, it''s not quite >> clear >> > how I can accomplish this. I''ve looked at writing a function, but that >> > seems to be for a larger scope than I''d like (only the providers in that >> > module would need this code) and requires a restart of the puppet >> master. >> >> Look at puppetlabs registry provider[1] for an example where >> modules/registry is shared between registry_key and registry_value. > > > We''ve actually got this wrong in the registry module currently. Shared > utility code should not go into the Puppet namespace at all. > > The convention we''ve "standardized" [1] on is: > > "Start with PuppetX, put the CamelCase of your author name (from the > Modulefile), then put the actual CamelCase of your module name" > > So the registry module should be PuppetX::PuppetLabs::Registry living in > ''<modulepath>/registry/lib/puppet_x/puppet_labs/registry.rb'' > > Puppet::Modules::Registry is a bad example and should not be followed. > > [1] http://projects.puppetlabs.com/issues/14149 > > -Jeff >Thanks Nan and Jeff for the replies! I''m new to both puppet and ruby, so let me sketch out what I''m thinking I should do based on the replies. Let''s say I''m creating a type FOO in module MODULE. I should then create a file in $confdir/modules/MODULE/lib/puppet/shared.rb Inside this shared.rb, I would then implement my shared methods in the PuppetX::ZJE::FOO module For some additional info, I''m using puppet 3.0.0rc3 Thanks again for all the help! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ocg5H5bzU58J. 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.
On Tuesday, July 17, 2012 2:02:10 PM UTC-5, ZJE wrote:> > > On Tuesday, July 17, 2012 12:29:52 PM UTC-5, Jeff McCune wrote: >> >> On Tue, Jul 17, 2012 at 9:49 AM, Nan Liu <> wrote: >> >>> On Tue, Jul 17, 2012 at 8:34 AM, ZJE <> wrote: >>> > I''d like to reuse the same ruby code in a type across all the >>> providers. For >>> > the type I''m writing, a certain portion of the "exists?" method would >>> be >>> > repeated across all providers. From looking at the documentation, >>> > http://docs.puppetlabs.com/guides/custom_types.html, it''s not quite >>> clear >>> > how I can accomplish this. I''ve looked at writing a function, but that >>> > seems to be for a larger scope than I''d like (only the providers in >>> that >>> > module would need this code) and requires a restart of the puppet >>> master. >>> >>> Look at puppetlabs registry provider[1] for an example where >>> modules/registry is shared between registry_key and registry_value. >> >> >> We''ve actually got this wrong in the registry module currently. Shared >> utility code should not go into the Puppet namespace at all. >> >> The convention we''ve "standardized" [1] on is: >> >> "Start with PuppetX, put the CamelCase of your author name (from the >> Modulefile), then put the actual CamelCase of your module name" >> >> So the registry module should be PuppetX::PuppetLabs::Registry living in >> ''<modulepath>/registry/lib/puppet_x/puppet_labs/registry.rb'' >> >> Puppet::Modules::Registry is a bad example and should not be followed. >> >> [1] http://projects.puppetlabs.com/issues/14149 >> >> -Jeff >> > > Thanks Nan and Jeff for the replies! I''m new to both puppet and ruby, so > let me sketch out what I''m thinking I should do based on the replies. > > Let''s say I''m creating a type FOO in module MODULE. I should then create a > file in $confdir/modules/MODULE/lib/puppet/shared.rb > Inside this shared.rb, I would then implement my shared methods in the > PuppetX::ZJE::FOO module > > For some additional info, I''m using puppet 3.0.0rc3 > Thanks again for all the help! >Sorry, don''t know how I missed the path in your earlier code - so it should be: <modulepath>/MODULE/lib/puppet_x/ZJE/shared.rb? Thanks! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/c65yhTLjYYEJ. 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.
On Tuesday, July 17, 2012 2:29:55 PM UTC-5, ZJE wrote:> > > On Tuesday, July 17, 2012 2:02:10 PM UTC-5, ZJE wrote: >> >> >> On Tuesday, July 17, 2012 12:29:52 PM UTC-5, Jeff McCune wrote: >>> >>> On Tue, Jul 17, 2012 at 9:49 AM, Nan Liu <> wrote: >>> >>>> On Tue, Jul 17, 2012 at 8:34 AM, ZJE <> wrote: >>>> > I''d like to reuse the same ruby code in a type across all the >>>> providers. For >>>> > the type I''m writing, a certain portion of the "exists?" method would >>>> be >>>> > repeated across all providers. From looking at the documentation, >>>> > http://docs.puppetlabs.com/guides/custom_types.html, it''s not quite >>>> clear >>>> > how I can accomplish this. I''ve looked at writing a function, but >>>> that >>>> > seems to be for a larger scope than I''d like (only the providers in >>>> that >>>> > module would need this code) and requires a restart of the puppet >>>> master. >>>> >>>> Look at puppetlabs registry provider[1] for an example where >>>> modules/registry is shared between registry_key and registry_value. >>> >>> >>> We''ve actually got this wrong in the registry module currently. Shared >>> utility code should not go into the Puppet namespace at all. >>> >>> The convention we''ve "standardized" [1] on is: >>> >>> "Start with PuppetX, put the CamelCase of your author name (from the >>> Modulefile), then put the actual CamelCase of your module name" >>> >>> So the registry module should be PuppetX::PuppetLabs::Registry living >>> in ''<modulepath>/registry/lib/puppet_x/puppet_labs/registry.rb'' >>> >>> Puppet::Modules::Registry is a bad example and should not be followed. >>> >>> [1] http://projects.puppetlabs.com/issues/14149 >>> >>> -Jeff >>> >> >> Thanks Nan and Jeff for the replies! I''m new to both puppet and ruby, so >> let me sketch out what I''m thinking I should do based on the replies. >> >> Let''s say I''m creating a type FOO in module MODULE. I should then create >> a file in $confdir/modules/MODULE/lib/puppet/shared.rb >> Inside this shared.rb, I would then implement my shared methods in the >> PuppetX::ZJE::FOO module >> >> For some additional info, I''m using puppet 3.0.0rc3 >> Thanks again for all the help! >> > > Sorry, don''t know how I missed the path in your earlier code - so it > should be: > <modulepath>/MODULE/lib/puppet_x/ZJE/shared.rb? > > Thanks! > >I''m still a little confused - is there an example of a type/provider where this is done correctly? Thanks! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/1124IRjcXJ8J. 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.
Jeff McCune
2012-Jul-25 14:57 UTC
Re: [Puppet Users] Method across providers for the same type
On Tue, Jul 24, 2012 at 9:54 AM, ZJE <countach44@gmail.com> wrote:> I''m still a little confused - is there an example of a type/provider where > this is done correctly? > Thanks! >Not that I know of. You could be the first! =) What''s confusing you? As a basic example, here is the initial change set that migrates the registry module to the convention we recommend of PuppetX::Puppetlabs::Registry https://github.com/puppetlabs/puppetlabs-registry/pull/18/files As you can see, we also have to work around the $LOAD_PATH issue in #14073<http://projects.puppetlabs.com/issues/14073>. This won''t be the case in Puppet 3.x as we''ll have made modules work when distributed as Rubygems in #7788<http://projects.puppetlabs.com/issues/7788> . -Jeff -- 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.
On Wednesday, July 25, 2012 9:57:20 AM UTC-5, Jeff McCune wrote:> > On Tue, Jul 24, 2012 at 9:54 AM, ZJE <countach44@gmail.com>wrote: > >> I''m still a little confused - is there an example of a type/provider >> where this is done correctly? >> Thanks! >> > > Not that I know of. You could be the first! =) > > What''s confusing you? > > As a basic example, here is the initial change set that migrates the > registry module to the convention we recommend of > PuppetX::Puppetlabs::Registry > > https://github.com/puppetlabs/puppetlabs-registry/pull/18/files > > As you can see, we also have to work around the $LOAD_PATH issue in #14073<http://projects.puppetlabs.com/issues/14073>. > This won''t be the case in Puppet 3.x as we''ll have made modules work when > distributed as Rubygems in #7788<http://projects.puppetlabs.com/issues/7788> > . > > -Jeff >I was trying to figure out the right way to work around the $LOAD_PATH issues, the example helps. I was also wondering if in PuppetX, the "X" was supposed to be the version number, but it doesn''t look like it. I''ve got it working now, many thanks :-) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ltfMkA1D5k4J. 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.