Hello In is possible inherits from parametrized class?? For example i have base php52 class like this: class linux::php52($pools, $extensions='''') inherits linux { ...... } and whants to inherit it like this: class linux::php52::cluster inherits linux::php52 for cluster configuration (cluster stuff -f for example prevent php from automatic startup), and class linux::php52::standalone inherits linux::php52 for standalone configuration(one host) I wants use this derrived classes like this: node "...." { ........ class { "linux::php52::standalone": pools => [ { "name" => "default", "addr" => "10.54.178.200:1982", "request_terminate_timeout" => 10, "request_slowlog_timeout" => 5, "workers" => 32 } ], extensions => ["apc", "json", "thrift-protocol", "simplexml", "curl", "hash"]; } ...... } But when i just write this class linux::php52::cluster inherits linux::php52 i got error: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter extensions How can i implement behavior that i want???? PS: puppet 2.7.10 -- 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.
You can only inherit from a parameterised class if you provide defaults for all of the parameters (and then of course those are the values that are used). What you could do is just have a single class with something like a type parameter. Then your class would have something like: if $type == "local" with the configuration that is specific to this type. On Feb 14, 3:49 pm, ruslan usifov <ruslan.usi...@gmail.com> wrote:> Hello > > In is possible inherits from parametrized class?? > > For example i have base php52 class like this: > > class linux::php52($pools, $extensions='''') inherits linux > { > ...... > > } > > and whants to inherit it like this: > > class linux::php52::cluster inherits linux::php52 > > for cluster configuration (cluster stuff -f for example prevent php from > automatic startup), and > > class linux::php52::standalone inherits linux::php52 > > for standalone configuration(one host) > > I wants use this derrived classes like this: > > node "...." > { > ........ > > class > { > > "linux::php52::standalone": > pools => [ > { > "name" => "default", > "addr" => "10.54.178.200:1982", > "request_terminate_timeout" => 10, > "request_slowlog_timeout" => 5, > "workers" => 32 > } > ], > > extensions => ["apc", "json", "thrift-protocol", > "simplexml", "curl", "hash"]; > } > > ...... > > } > > But when i just write this class linux::php52::cluster inherits linux::php52 > > i got error: > > err: Could not retrieve catalog from remote server: Error 400 on SERVER: > Invalid parameter extensions > > How can i implement behavior that i want???? > > PS: puppet 2.7.10-- 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 Tue, Feb 14, 2012 at 6:49 AM, ruslan usifov <ruslan.usifov@gmail.com> wrote:> Hello > > In is possible inherits from parametrized class??It''s not currently possible, and I don''t know if it''s 100% clear when you inherit and add parameters do you intend inherit the parent''s default, override the parent''s default, or to pass new parameters. http://projects.puppetlabs.com/issues/6539> For example i have base php52 class like this: > > class linux::php52($pools, $extensions='''') inherits linux > { > ...... > } > > > and whants to inherit it like this: > > class linux::php52::cluster inherits linux::php52For now you are probably best doing something like: class linux::php52::cluster ( $someparam ){ class { ''linux::php52'': param => $someparam, } ... other resources ... } You will need to expose any attribute you plan override as a parameter in linux::php52. Thanks, Nan -- 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 Feb 14, 10:41 am, Nan Liu <n...@puppetlabs.com> wrote:> On Tue, Feb 14, 2012 at 6:49 AM, ruslan usifov <ruslan.usi...@gmail.com> wrote: > > Hello > > > In is possible inherits from parametrized class??Is class inheritance really would you should be using? If your intention is for the child class to override properties of resources declared by the parent class, then yes; otherwise no. From your example it appears no resource overriding is intended, so probably "no". It looks like what you''re really looking for is class composition, and that''s exactly the solution that Nan proposed to you. Do not use inheritance to achieve composition.> It''s not currently possible, and I don''t know if it''s 100% clear when > you inherit and add parameters do you intend inherit the parent''s > default, override the parent''s default, or to pass new parameters.And this is one of the lesser reasons to avoid parameterizing your classes. John -- 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.
ruslan usifov
2012-Feb-17 09:48 UTC
Re: [Puppet Users] Re: inherits from parametrized class
2012/2/15 jcbollinger <John.Bollinger@stjude.org>> > > On Feb 14, 10:41 am, Nan Liu <n...@puppetlabs.com> wrote: > > On Tue, Feb 14, 2012 at 6:49 AM, ruslan usifov <ruslan.usi...@gmail.com> > wrote: > > > Hello > > > > > In is possible inherits from parametrized class?? > > > Is class inheritance really would you should be using? If your > intention is for the child class to override properties of resources > declared by the parent class, then yes; otherwise no. From your > example it appears no resource overriding is intended, so probably"no".> >I think yes, for example i use in linux::php52, follow service definition service { "php-fpm": require => [ File["/usr/local/etc/php-fpm.conf"], Package["php52"], File["/var/log/php-fpm/"], File["/etc/init.d/php-fpm"] ]; } and in derived class i want for standalone(linux::php52::standalone) configuration restart service when config files changed like this: Service["php-fpm"] { ensure => true, enable => true, hasrestart => true, subscribe => [ File["/usr/local/etc/php-fpm.conf"], File["/usr/local/etc/php.ini"], File["/etc/init.d/php-fpm"], Package["php52"] ]; } and in cluster class do nothing(restart of php will be made by cluster stack) like this: Service["php-fpm"] { enable => false } How cant accomplish this be composition? I would be very grateful> It looks like what you''re really looking for is class composition, and > that''s exactly the solution that Nan proposed to you. Do not use > inheritance to achieve composition. > > > > It''s not currently possible, and I don''t know if it''s 100% clear when > > you inherit and add parameters do you intend inherit the parent''s > > default, override the parent''s default, or to pass new parameters. > > > And this is one of the lesser reasons to avoid parameterizing your > classes. > > > John > > -- > 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. > >-- 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 Feb 17, 3:48 am, ruslan usifov <ruslan.usi...@gmail.com> wrote:> 2012/2/15 jcbollinger <John.Bollin...@stjude.org> > > > > > On Feb 14, 10:41 am, Nan Liu <n...@puppetlabs.com> wrote: > > > On Tue, Feb 14, 2012 at 6:49 AM, ruslan usifov <ruslan.usi...@gmail.com> > > wrote: > > > > Hello > > > > > In is possible inherits from parametrized class?? > > > Is class inheritance really would you should be using? If your > > intention is for the child class to override properties of resources > > declared by the parent class, then yes; otherwise no. From your > > example it appears no resource overriding is intended, so probably > > "no". > > I think yes, for example i use in linux::php52, follow service definition > > service > { > "php-fpm": > require => [ File["/usr/local/etc/php-fpm.conf"], Package["php52"], > File["/var/log/php-fpm/"], File["/etc/init.d/php-fpm"] ]; > > } > > and in derived class i want for standalone(linux::php52::standalone) > configuration restart service when config files changed like this: > > Service["php-fpm"] > { > ensure => true, > enable => true, > hasrestart => true, > subscribe => [ File["/usr/local/etc/php-fpm.conf"], > File["/usr/local/etc/php.ini"], File["/etc/init.d/php-fpm"], > Package["php52"] ]; > > } > > and in cluster class do nothing(restart of php will be made by cluster > stack) like this: > > Service["php-fpm"] > { > enable => false > > } > > How cant accomplish this be composition? I would be very gratefulIf no node uses linux::php52 directly (every node uses either linux::php52::standalone or linux::php52::cluster) then just remove the service declaration from linux::php52 and put separate ones in linux::php52::standalone and linux::php52::cluster. That makes especial sense in this example because the two erstwhile subclasses don''t need any Service["php-fpm"] property values in common: the "require" property they both inherit is redundant with the "subscribe" property that the standalone class provides. Class inheritance is a convenience in certain special circumstances, but only a complication in most. You don''t ever need it in any absolute sense. John -- 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.
Hi all, On 02/17/2012 09:44 PM, jcbollinger wrote:>> ... >> >> service >> { >> "php-fpm": >> require => [ File["/usr/local/etc/php-fpm.conf"], Package["php52"], >> File["/var/log/php-fpm/"], File["/etc/init.d/php-fpm"] ]; >> >> } >> >> and in derived class i want for standalone(linux::php52::standalone) >> configuration restart service when config files changed like this: >> >> Service["php-fpm"] >> { >> ensure => true, >> enable => true, >> hasrestart => true, >> subscribe => [ File["/usr/local/etc/php-fpm.conf"], >> File["/usr/local/etc/php.ini"], File["/etc/init.d/php-fpm"], >> Package["php52"] ]; >> >> } >> >> and in cluster class do nothing(restart of php will be made by cluster >> stack) like this: >> >> Service["php-fpm"] >> { >> enable => false >> >> } >> >> How cant accomplish this be composition? I would be very grateful > > > If no node uses linux::php52 directly (every node uses either > linux::php52::standalone or linux::php52::cluster) then just remove > the service declaration from linux::php52 and put separate ones in > linux::php52::standalone and linux::php52::cluster. > > That makes especial sense in this example because the two erstwhile > subclasses don''t need any Service["php-fpm"] property values in > common: the "require" property they both inherit is redundant with the > "subscribe" property that the standalone class provides. > > Class inheritance is a convenience in certain special circumstances, > but only a complication in most. You don''t ever need it in any > absolute sense.not commenting on what would be "best approach" here, I believe everyone has let themselves get distracted from the problem at hand. What should work is this structure: Given class mod::class($param1, $param2) { ... } class mod::class::sub1 inherits mod::class { ... } class mod::class::sub2 inherits mod::class { ... } You will then use these as class { "mod::class": param1 => ..., param2 => ... } include mod::class::sub1 # <- this does the overriding # or #include mod::class::sub2 # ...or even both (not in the presented use case, though) This is a bit confusing, but mixing includes of base classes and subclasses is quite common when using the inheritance paradigm, and this is just an irky notation of the same, seeing as the base class is parameterized. HTH, Felix -- 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.
I didn''t realise that would work. Here''s a trivial tested example derived from Felix''s comment: class mod::class($param1, $param2) { file {"$param1/$param2": content => "Bla\n"} } class mod::class::sub1 inherits mod::class { File["$param1/$param2"] {content => "Sub1\n"} } And then in the node: class {"mod::class": param1 => "/tmp", param2 => "testfile" } include mod::class::sub1 And the result is that /tmp/testfile has "Sub1" Actually it doesn''t seem that confusing. On Feb 22, 2:21 pm, Felix Frank <felix.fr...@alumni.tu-berlin.de> wrote:> Hi all, > > On 02/17/2012 09:44 PM, jcbollinger wrote: > > > > > > > > > > >> ... > > >> service > >> { > >> "php-fpm": > >> require => [ File["/usr/local/etc/php-fpm.conf"], Package["php52"], > >> File["/var/log/php-fpm/"], File["/etc/init.d/php-fpm"] ]; > > >> } > > >> and in derived class i want for standalone(linux::php52::standalone) > >> configuration restart service when config files changed like this: > > >> Service["php-fpm"] > >> { > >> ensure => true, > >> enable => true, > >> hasrestart => true, > >> subscribe => [ File["/usr/local/etc/php-fpm.conf"], > >> File["/usr/local/etc/php.ini"], File["/etc/init.d/php-fpm"], > >> Package["php52"] ]; > > >> } > > >> and in cluster class do nothing(restart of php will be made by cluster > >> stack) like this: > > >> Service["php-fpm"] > >> { > >> enable => false > > >> } > > >> How cant accomplish this be composition? I would be very grateful > > > If no node uses linux::php52 directly (every node uses either > > linux::php52::standalone or linux::php52::cluster) then just remove > > the service declaration from linux::php52 and put separate ones in > > linux::php52::standalone and linux::php52::cluster. > > > That makes especial sense in this example because the two erstwhile > > subclasses don''t need any Service["php-fpm"] property values in > > common: the "require" property they both inherit is redundant with the > > "subscribe" property that the standalone class provides. > > > Class inheritance is a convenience in certain special circumstances, > > but only a complication in most. You don''t ever need it in any > > absolute sense. > > not commenting on what would be "best approach" here, I believe everyone > has let themselves get distracted from the problem at hand. > > What should work is this structure: Given > class mod::class($param1, $param2) { ... } > class mod::class::sub1 inherits mod::class { ... } > class mod::class::sub2 inherits mod::class { ... } > > You will then use these as > > class { "mod::class": > param1 => ..., > param2 => ...} > > include mod::class::sub1 # <- this does the overriding > # or > #include mod::class::sub2 > # ...or even both (not in the presented use case, though) > > This is a bit confusing, but mixing includes of base classes and > subclasses is quite common when using the inheritance paradigm, and this > is just an irky notation of the same, seeing as the base class is > parameterized. > > HTH, > Felix-- 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.
Reasonably Related Threads
- roolback to previouse configuration
- multiplying values in data frame by corresponding value in the first column
- Passing extra parameters to functions called from Observers
- XML parameters to Column Headers for importing into a dataset
- accessing extra request parameters