Yanis Guenane
2012-Jun-26 11:07 UTC
[Puppet Users] Is it possible to access type params in another type?
Hey guys, I was wondering if it was possible to access type params within another type. Here is an example of what I would like to do. Puppet::Type.newtype(:a) do>newparam(:name) do> isnamevar > end >newparam(:path) do> end > end >Puppet::Type.newtype(:b) do>newparam(:name) do> isnamevar > end >newparam(:needs) do> > /* I want to access path param from ''a'' type heresomething like resource[:needs].path */>> end > end >And the manifest calling that would be a {''test-a'' :> path => ''/usr'', > } > > b {''test-b'' : > needs => a > } > >Is it possible ? -- 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/-/71LHFiGNs2YJ. 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.
jcbollinger
2012-Jun-26 19:40 UTC
[Puppet Users] Re: Is it possible to access type params in another type?
On Tuesday, June 26, 2012 6:07:41 AM UTC-5, Yanis Guenane wrote:> > Hey guys, > > I was wondering if it was possible to access type params within another > type. > > Here is an example of what I would like to do. > > Puppet::Type.newtype(:a) do >> > newparam(:name) do >> isnamevar >> end >> > newparam(:path) do >> end >> end >> > > Puppet::Type.newtype(:b) do >> > newparam(:name) do >> isnamevar >> end >> > newparam(:needs) do >> >> /* I want to access path param from ''a'' type here > > something like resource[:needs].path */ >> > >> end >> end >> > > And the manifest calling that would be > > a {''test-a'' : >> path => ''/usr'', >> } >> >> b {''test-b'' : >> needs => a >> } >> >> > > > Is it possible ? >What is the example supposed to mean? It doesn''t make sense. As a best guess, what you actually want to do is access the parameter values of a resource *instance*, not (as you wrote) the parameter[ definition]s of a resource *type*. It might be possible to do that (involving somewhat different manifest syntax), but it would be decidedly non-idiomatic. Why do you want this? Your example is too abstract to tell me much. John -- 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/-/cgDhAqNhrOgJ. 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.
Yanis Guenane
2012-Jun-27 05:27 UTC
[Puppet Users] Re: Is it possible to access type params in another type?
What I actually would like it to create a kind of dependency. I would like that a parameter X of any instance of type ''b'' *depends* on the path param of the ''a'' resource instance namely passed as a parameter. file {''test'' :> ensure => present, > name => ''test.txt'', > *within* => dir, > } > > file {''dir'' : > ensure => directory, > name => ''dir'', > path => ''/tmp'' > } >This is not the best example since file does not work this way but its the closest one to what I would like. Imagine file was a custom type, so I know in the *within *param I am expecting a File[] resource insance. I''d like to know if there is any way I can get the parameters of this resource instance (dir)? (Something like extrapolating it, or accessing it through catalog) In the previous case File[''test''] will end up being located at ''/tmp/text.txt'', appending dir.path + test.name, without specifying the path in File[''test''] but just the directory it depends on. I hope I could explain myself a bit better, On Tuesday, June 26, 2012 9:40:32 PM UTC+2, jcbollinger wrote:> > > > On Tuesday, June 26, 2012 6:07:41 AM UTC-5, Yanis Guenane wrote: >> >> Hey guys, >> >> I was wondering if it was possible to access type params within another >> type. >> >> Here is an example of what I would like to do. >> >> Puppet::Type.newtype(:a) do >>> >> newparam(:name) do >>> isnamevar >>> end >>> >> newparam(:path) do >>> end >>> end >>> >> >> Puppet::Type.newtype(:b) do >>> >> newparam(:name) do >>> isnamevar >>> end >>> >> newparam(:needs) do >>> >>> /* I want to access path param from ''a'' type here >> >> something like resource[:needs].path */ >>> >> >>> end >>> end >>> >> >> And the manifest calling that would be >> >> a {''test-a'' : >>> path => ''/usr'', >>> } >>> >>> b {''test-b'' : >>> needs => a >>> } >>> >>> >> >> >> Is it possible ? >> > > > What is the example supposed to mean? It doesn''t make sense. As a best > guess, what you actually want to do is access the parameter values of a > resource *instance*, not (as you wrote) the parameter[ definition]s of a > resource *type*. It might be possible to do that (involving somewhat > different manifest syntax), but it would be decidedly non-idiomatic. > > Why do you want this? Your example is too abstract to tell me much. > > > John > >-- 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/-/D25xHdkiLnMJ. 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.
jcbollinger
2012-Jun-27 14:39 UTC
[Puppet Users] Re: Is it possible to access type params in another type?
On Wednesday, June 27, 2012 12:27:17 AM UTC-5, Yanis Guenane wrote:> > What I actually would like it to create a kind of dependency. > > I would like that a parameter X of any instance of type ''b'' *depends* on > the path param of the ''a'' resource instance namely passed as a parameter. > > file {''test'' : >> ensure => present, >> name => ''test.txt'', >> *within* => dir, >> } >> >> file {''dir'' : >> ensure => directory, >> name => ''dir'', >> path => ''/tmp'' >> } >> > > This is not the best example since file does not work this way but its the > closest one to what I would like. > > Imagine file was a custom type, so I know in the *within *param I am > expecting a File[] resource insance. I''d like to know if there is any way I > can get the parameters of this resource instance (dir)? (Something like > extrapolating it, or accessing it through catalog) > > In the previous case File[''test''] will end up being located at > ''/tmp/text.txt'', appending dir.path + test.name, without specifying the > path in File[''test''] but just the directory it depends on. > > I hope I could explain myself a bit better,Yes, you did, and that''s pretty much what I had supposed you were after. Chances are good that you could force this to work, but I cannot advise you about details, and I recommend you do not follow this path. Nothing else in Puppet works the way you describe. More generally, despite appearances, implementation language, and some of the terminology used in the Puppet community, Puppet DSL is not an object-oriented language in any conventional sense, but that''s how you want to make it behave (albeit only within the confines of your custom type). The fact that you are trying to do something so non-idiomatic should give you pause. The usual ways to approach this sort of problem all involve making multiple classes and / or resources pull data from the same source, typically one of global or class variables, defined type parameters, an external data repository, or class parameters. For example, if the two associated resources are going to be declared together, then you could do this: define my_module::file_and_directory($filename, $dir) { file {$dir : ensure => directory, } file {"${dir}/${filename}": ensure => present, } } my_module::file_and_directory { "foo": filename => ''file'', dir => ''/tmp'' } John -- 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/-/GMMVj0r6oiQJ. 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.
Yanis Guenane
2012-Jun-28 10:19 UTC
[Puppet Users] Re: Is it possible to access type params in another type?
John, thanks a lot for your answers. I was doing it this way at first, but I thought that providing native type would be much simpler for end users. The same way puppet is providing native types for Nagios I wanted to create native type for the application I need. Anyway I''ll get back to defined type and class ;) Thanks again, On Tuesday, June 26, 2012 1:07:41 PM UTC+2, Yanis Guenane wrote:> > Hey guys, > > I was wondering if it was possible to access type params within another > type. > > Here is an example of what I would like to do. > > Puppet::Type.newtype(:a) do >> > newparam(:name) do >> isnamevar >> end >> > newparam(:path) do >> end >> end >> > > Puppet::Type.newtype(:b) do >> > newparam(:name) do >> isnamevar >> end >> > newparam(:needs) do >> >> /* I want to access path param from ''a'' type here > > something like resource[:needs].path */ >> > >> end >> end >> > > And the manifest calling that would be > > a {''test-a'' : >> path => ''/usr'', >> } >> >> b {''test-b'' : >> needs => a >> } >> >> > > > Is it possible ? >-- 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/-/ouzxtGDl8EkJ. 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.
Steve Traylen
2012-Jun-28 18:52 UTC
[Puppet Users] Re: Is it possible to access type params in another type?
On Tuesday, 26 June 2012 13:07:41 UTC+2, Yanis Guenane wrote:> > Hey guys, > > I was wondering if it was possible to access type params within another > type. > > Here is an example of what I would like to do. > > Puppet::Type.newtype(:a) do >> > newparam(:name) do >> isnamevar >> end >> > newparam(:path) do >> end >> end >> > > Puppet::Type.newtype(:b) do >> > newparam(:name) do >> isnamevar >> end >> > newparam(:needs) do >> >> /* I want to access path param from ''a'' type here > > something like resource[:needs].path */ >> > >> end >> end >> > > And the manifest calling that would be > > a {''test-a'' : >> path => ''/usr'', >> } >> >> b {''test-b'' : >> needs => a >> } >> >> > > > Is it possible ? >Hi Yanis, http://projects.puppetlabs.com/issues/10166 describes a unproven technique for catalog lookup from a provider to access another type. Steve, -- 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/-/lc41eCS9zdkJ. 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.