On Oct 4, 9:39 am, Bruno Leon <[email protected]> wrote:
> On 11-10-04 09:11 AM, jcbollinger wrote:
>
>
>
>
>
> > On Oct 3, 5:44 pm, Bruno Leon<[email protected]>  wrote:
> >> Hi,
>
> >> is there a way to get the value of a parameter passed to a parameterized
> >> class ?
> >> I've searched quite a lot and did not came out with a solution.
> > Did you mean within your manifests?  You can do it easily as long as
> > the class in question provides for it, otherwise not at all.  For
> > example:
>
> > module1::class1($param1, $param2='foo') {
> >     $my_param1 = $param1
> >     $my_param2 = $param2
> > }
>
> > module2::class2 {
> >     notify { "module1::class1::param1":
> >        message =>  "module1::class1::param1 = $
> > {module1::class1::my_param1}"
> >     }
> >     notify { "module1::class1::param2":
> >        message =>  "module1::class1::param2 = $
> > {module1::class1::my_param2}"
> >     }
> > }
>
> > There, the class makes the parameters externally available by
> > assigning their values to class variables.  If you need parameter
> > values from a class that does not expose them that way and that you
> > cannot modify to do so, then you are out of luck.  You can get
> > something close, however: you can record the values that are
> > *supposed* to be assigned in global variables or some other class's
> > variables.  For example,
>
> > module3::class3($param1, $param2='foo') {
> > }
>
> > module4::class4 {
> >    $class3_param1 = 42
> >    $class3_param2 = 'bar'
> >    class { "module3::class3":
> >       param1 =>  $class3_param1
> >       param2 =>  $class3_param2
> >    }
> > }
>
> > module5::class5 {
> >     notify { "module3::class3::param1":
> >        message =>  "module3::class3::param1 = $
> > {module4::class4::class3_param1}"
> >     }
> >     notify { "module3::class3::param2":
> >        message =>  "module3::class3::param2 = $
> > {module4::class4::class3_param2}"
> >     }
> > }
>
> > Good luck,
>
> > John
>
> Very interesting ideas John.
>
> I did not thought about making the parameters available by assigning
> them to class variables.
> That would indeed work, but I was hoping for some kind of method that
> would allow to get the value,
>
> I also thought about passing every single parameter through hiera, so
> that they are easily available for any object,
> but that kind of end up having all variables/parameters in on place like
> it used to be in 0.25.X.
>
> I think I need to make up my mind about the best way to do this.


If you are open to a design that uses non-parameterized classes
instead of parameterized ones then I urge you to give it serious
consideration.  The main problem that parameterized classes address is
not having all your data in one place.  In fact, it's exactly the
opposite: having data in different (dynamic) scopes such that it is
unclear from which one(s) classes are obtaining it.  Although they
provide one solution to that problem, parameterized classed introduce
their own set of problems.

Providing a central, universal data access point is exactly the
purpose of hiera, and of extlookup() to a lesser extent.  They --
especially hiera -- do not in fact require the data themselves to be
collocated; instead, they allow your classes to get the needed data
from wherever they happen to be.


John



-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to