<Derek.Whayman@barclayscapital.com>
2007-Sep-25 15:42 UTC
"Have I included class X" function?
Anyone know if it would be straightforward to extract this information from Puppet, probably in a custom function: The classes included as a result of the client''s parsed configuration - or - Am I in class X as a result of my parsed configuration? I''m thinking it would result in a more elegant manifest if classes X and Y behaved differently if they were both included compared to if just class X or class Y was. Rather than some ugly Z class. Cheers, Derek ------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------
On Sep 25, 2007, at 10:42 AM, <Derek.Whayman@barclayscapital.com> wrote:> Anyone know if it would be straightforward to extract this information > from Puppet, probably in a custom function: > > The classes included as a result of the client''s parsed configuration > - or - > Am I in class X as a result of my parsed configuration? > > I''m thinking it would result in a more elegant manifest if classes > X and > Y behaved differently if they were both included compared to if just > class X or class Y was. Rather than some ugly Z class.It should be pretty darn straightforward. You should be able to just do something like this: if class_scope("class_name") return true else return false end Note that class_scope expects a fully-qualified class. If you need to look up a class name, then you can do this: if class_scope(findclass("unqualified-class")) ... end -- Susskind''s Rule of Thumb: Don''t ask what they think. Ask what they do. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
<Derek.Whayman@barclayscapital.com>
2007-Sep-26 12:10 UTC
Re: "Have I included class X" function?
Works perfectly, much obliged. In addition to the justification below, this means the only real downside of the dynamic variable scoping model - where an "assignment" to a variable in one class is not visible in a sister class - is no longer an issue in most cases. The manifest can be refactored to use this code instead. For example, if I have a templated file that has inputs from two classes (that are not hierarchical) it''s now easy to organise this. I know that said file should be managed by a custom type with resources in both classes, but hey sometimes I just don''t have the time to go that far ;-) Many thanks, Derek -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Luke Kanies Sent: 25 September 2007 17:41 To: Puppet User Discussion Subject: Re: [Puppet-users] "Have I included class X" function? On Sep 25, 2007, at 10:42 AM, <Derek.Whayman@barclayscapital.com> wrote:> Anyone know if it would be straightforward to extract this information> from Puppet, probably in a custom function: > > The classes included as a result of the client''s parsed configuration > - or - > Am I in class X as a result of my parsed configuration? > > I''m thinking it would result in a more elegant manifest if classes X > and Y behaved differently if they were both included compared to if > just class X or class Y was. Rather than some ugly Z class.It should be pretty darn straightforward. You should be able to just do something like this: if class_scope("class_name") return true else return false end Note that class_scope expects a fully-qualified class. If you need to look up a class name, then you can do this: if class_scope(findclass("unqualified-class")) ... end -- Susskind''s Rule of Thumb: Don''t ask what they think. Ask what they do. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users ------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------
<Derek.Whayman@barclayscapital.com>
2007-Sep-27 14:07 UTC
Re: "Have I included class X" function?
Ah, there''s only one point to note about this. It was in the back of my mind when I posed the question, I think I was blinded by the possibilities. E.g. node myhost { include dummycat include base } If I call class_scope("dummycat") within a class included from base it works fine. However: node myhost { include base include dummycat } If I now call class_scope("dummycat") within a class included from base it is always false. This is presumably because the included classes are built during the parsing - and the call to class_scope is during the parsing - and at what point depends on the ordering in the manifest. Making the manifests order-sensitive is clearly not the Puppet Way. It''s slightly uglier than before, but it still works for what I''m trying to do provided I don''t stray beyond these boundaries. Maybe I should move back towards external node classification ;-) Regards, Derek -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Whayman, Derek: IT (LDN) Sent: 26 September 2007 13:10 To: puppet-users@madstop.com Subject: Re: [Puppet-users] "Have I included class X" function? Works perfectly, much obliged. In addition to the justification below, this means the only real downside of the dynamic variable scoping model - where an "assignment" to a variable in one class is not visible in a sister class - is no longer an issue in most cases. The manifest can be refactored to use this code instead. For example, if I have a templated file that has inputs from two classes (that are not hierarchical) it''s now easy to organise this. I know that said file should be managed by a custom type with resources in both classes, but hey sometimes I just don''t have the time to go that far ;-) Many thanks, Derek -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Luke Kanies Sent: 25 September 2007 17:41 To: Puppet User Discussion Subject: Re: [Puppet-users] "Have I included class X" function? On Sep 25, 2007, at 10:42 AM, <Derek.Whayman@barclayscapital.com> wrote:> Anyone know if it would be straightforward to extract this information> from Puppet, probably in a custom function: > > The classes included as a result of the client''s parsed configuration > - or - > Am I in class X as a result of my parsed configuration? > > I''m thinking it would result in a more elegant manifest if classes X > and Y behaved differently if they were both included compared to if > just class X or class Y was. Rather than some ugly Z class.It should be pretty darn straightforward. You should be able to just do something like this: if class_scope("class_name") return true else return false end Note that class_scope expects a fully-qualified class. If you need to look up a class name, then you can do this: if class_scope(findclass("unqualified-class")) ... end -- Susskind''s Rule of Thumb: Don''t ask what they think. Ask what they do. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users ------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------ _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
On Sep 27, 2007, at 9:07 AM, <Derek.Whayman@barclayscapital.com> wrote:> Maybe I should move back towards external node classification ;-)This, and the thousand or so problems that are like it, are a big part of why we''re moving toward external nodes. That being said, I''ve significantly refactored how this works in the current source tree, so there''s a good chance you could get the functionality you want if I can finish this xmlrpc => rest conversion. I''m actually doing all class and node evaluation via resources, so you could do something like: if defined(Class[myclass]) { ... } -- A gentleman is a man who can play the accordion but doesn''t. -- Unknown --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com