On Mon, Jan 10, 2011 at 8:34 AM, Luke Kanies <[email protected]> wrote:

> Thanks.
>
> Any idea how this could be integrated into the Dashboard?
>


The easiest integration would require another patch:

one approach:

   - a param class should express its params as part of the  Dashboard class
object
   - Dashboard groups should be able to specify params to assign to the
classes in their class lists
   - Dashboard nodes - iterate through their groups based on group
inheritance, class params are overridden based on group inheritence

   - as a nice to have, Dashboard classes should be able to update their
attributes via introspection, they should also be able to specify which
params are required/optional (meaning they have defaults specified in the
Puppet code)

   - if we specify required params, it would be nice if the Dashboard could
fail if  a node's groups do not supply all required params

On Jan 9, 2011, at 6:17 PM, Dan Bode wrote:
>
> I finished writing unit tests for this patch. I also wound up refactoring
> the patch a little after the unit tests revealed that it could be optimized.
> Should I run mail_patches again? The same branch is the most up to date.
>
>
> https://github.com/bodepd/puppet/tree/ticket/2.6.4/5045
>
> On Sat, Jan 8, 2011 at 10:28 PM, Dan Bode <[email protected]> wrote:
>
>>
>>
>> On Fri, Jan 7, 2011 at 10:54 AM, Luke Kanies <[email protected]> wrote:
>>
>>> Hi Dan,
>>>
>>> I'm interested in testing this.  Where is this code available?  And do
>>> you have an example ENC plugin that uses it?
>>>
>>>
>> I verified that it works with hashes on Friday, I have all kinds of crazy
>> ideas of what I can do with ENC/param classes and hashes;)
>>
>> I just pushed a commit to my branch for this today, the unit tests are
>> still a little lacking, but otherwise it seems to work.
>>
>> https://github.com/bodepd/puppet/tree/ticket/2.6.4/5045
>>
>> I have been testing the functionality with the simplest ENC possible:
>>
>> #node.sh
>> #!/bin/bash
>> cat /etc/puppet/nodes/node.yaml
>>
>> #node.yaml
>>
>> parameters:
>>   fooarray: encfooarray
>>   foo: top
>> classes:
>>   foo:
>>
>> and my foo class:
>>
>> class foo($bar='default', $baz='default') inherits foo::parent {
>>   notify{ 'bar':
>>     message => $bar,
>>   }
>>   notify{ 'baz':
>>     message => $baz,
>>   }
>> }
>> class foo::parent {
>>   notify{'parent':}
>> }
>> class foo::blaher {
>>   notify{'blaher':}
>> }
>>
>>
>>
>>
>>
>>
>>
>>> On Jan 3, 2011, at 1:39 PM, Dan Bode wrote:
>>>
>>> >    This experimental patch is intended to add support for param classes
>>> to the ENC.
>>> >
>>> >    The patch does the following:
>>> >      1. adds the ability to accept attributes to ensure_in_catalog
>>> >      2. added hash support for a node's classes to accept a hash
>>> >
>>> > Signed-off-by: Dan Bode <[email protected]>
>>> > ---
>>> > lib/puppet/parser/compiler.rb     |   17 ++++++++++++++++-
>>> > lib/puppet/resource/type.rb       |    5 ++++-
>>> > spec/unit/parser/compiler_spec.rb |   22 ++++++++++++++++++++++
>>> > 3 files changed, 42 insertions(+), 2 deletions(-)
>>> >
>>> > diff --git a/lib/puppet/parser/compiler.rb
>>> b/lib/puppet/parser/compiler.rb
>>> > index c60e1d4..e29bdd7 100644
>>> > --- a/lib/puppet/parser/compiler.rb
>>> > +++ b/lib/puppet/parser/compiler.rb
>>> > @@ -129,6 +129,17 @@ class Puppet::Parser::Compiler
>>> >
>>> >   # Evaluate all of the classes specified by the node.
>>> >   def evaluate_node_classes
>>> > +    if @node.classes.class == Hash
>>> > +      @node.classes.each do |name, params|
>>> > +        params ||= {}
>>> > +        # I have to find the hostclass
>>> > +        if klass = topscope.find_hostclass(name)
>>> > +          #resource = Puppet::Resource::Type.new(:hostclass, name)
>>> > +          klass.ensure_in_catalog(topscope, params)
>>> > +        end
>>> > +      end
>>> > +      @node.classes = @node.classes.keys
>>> > +    end
>>> >     evaluate_classes(@node.classes, topscope)
>>> >   end
>>> >
>>> > @@ -432,7 +443,11 @@ class Puppet::Parser::Compiler
>>> >     @resources = []
>>> >
>>> >     # Make sure any external node classes are in our class list
>>> > -    @catalog.add_class(*[email protected])
>>> > +    if @node.classes.class == Hash
>>> > +      @catalog.add_class(*[email protected])
>>> > +    else
>>> > +      @catalog.add_class(*[email protected])
>>> > +    end
>>> >   end
>>> >
>>> >   # Set the node's parameters into the top-scope as variables.
>>> > diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
>>> > index d40adc1..80d1133 100644
>>> > --- a/lib/puppet/resource/type.rb
>>> > +++ b/lib/puppet/resource/type.rb
>>> > @@ -143,7 +143,7 @@ class Puppet::Resource::Type
>>> >   # classes and nodes.  No parameters are be supplied--if this is a
>>> >   # parameterized class, then all parameters take on their default
>>> >   # values.
>>> > -  def ensure_in_catalog(scope)
>>> > +  def ensure_in_catalog(scope, attributes={})
>>> >     type == :definition and raise ArgumentError, "Cannot create
>>> resources for defined resource types"
>>> >     resource_type = type == :hostclass ? :class : :node
>>> >
>>> > @@ -155,6 +155,9 @@ class Puppet::Resource::Type
>>> >     end
>>> >
>>> >     resource = Puppet::Parser::Resource.new(resource_type, name, :scope
>>> => scope, :source => self)
>>> > +    attributes.each do |k,v|
>>> > +      resource.set_parameter(k,v)
>>> > +    end
>>> >     instantiate_resource(scope, resource)
>>> >     scope.compiler.add_resource(scope, resource)
>>> >     resource
>>> > diff --git a/spec/unit/parser/compiler_spec.rb
>>> b/spec/unit/parser/compiler_spec.rb
>>> > index 95f3853..f569328 100755
>>> > --- a/spec/unit/parser/compiler_spec.rb
>>> > +++ b/spec/unit/parser/compiler_spec.rb
>>> > @@ -109,6 +109,16 @@ describe Puppet::Parser::Compiler do
>>> >       compiler.classlist.should include("bar")
>>> >     end
>>> >
>>> > +    it "should transform node class hashes into a class list" do
>>> > +      node = Puppet::Node.new("mynode")
>>> > +      @node.classes = {'foo'=>{'one'=>'1'}, 'bar'=>{'two'=>'2'}}
>>> > +      node.classes = {'foo'=>{'one'=>'1'}, 'bar'=>{'two'=>'2'}}
>>> > +      compiler = Puppet::Parser::Compiler.new(node)
>>> > +
>>> > +      compiler.classlist.should include("foo")
>>> > +      compiler.classlist.should include("bar")
>>> > +    end
>>> > +
>>> >     it "should add a 'main' stage to the catalog" do
>>> >       @compiler.catalog.resource(:stage, :main).should
>>> be_instance_of(Puppet::Parser::Resource)
>>> >     end
>>> > @@ -185,6 +195,18 @@ describe Puppet::Parser::Compiler do
>>> >       @compiler.class.publicize_methods(:evaluate_node_classes) {
>>> @compiler.evaluate_node_classes }
>>> >     end
>>> >
>>> > +    it "should evaluate any parameterized classes named in the node"
>>> do
>>> > +      classes = {'foo'=>{'one'=>'1'}, 'bar'=>{'two'=>'2'}}
>>> > +      main = stub 'main'
>>> > +      one = stub 'one', :name => "one"
>>> > +      three = stub 'three', :name => "three"
>>> > +      @node.stubs(:name).returns("whatever")
>>> > +      @node.stubs(:classes).returns(classes)
>>> > +
>>> > +      @compiler.expects(:evaluate_classes).with(classes,
>>> @compiler.topscope)
>>> > +      @compiler.class.publicize_methods(:evaluate_node_classes) {
>>> @compiler.evaluate_node_classes }
>>> > +    end
>>> > +
>>> >     it "should evaluate the main class if it exists" do
>>> >       compile_stub(:evaluate_main)
>>> >       main_class = @known_resource_types.add
>>> Puppet::Resource::Type.new(:hostclass, "")
>>> > --
>>> > 1.5.5.6
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups "Puppet Developers" group.
>>> > To post to this group, send email to [email protected].
>>> > To unsubscribe from this group, send email to
>>> [email protected]<puppet-dev%[email protected]>
>>> .
>>> > For more options, visit this group at
>>> http://groups.google.com/group/puppet-dev?hl=en.
>>> >
>>>
>>>
>>> --
>>> To get back my youth I would do anything in the world, except take
>>> exercise, get up early, or be respectable.  -- Oscar Wilde
>>> ---------------------------------------------------------------------
>>> Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199
>>>
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Puppet Developers" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<puppet-dev%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/puppet-dev?hl=en.
>>>
>>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" 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-dev?hl=en.
>
>
>
> --
> The trouble with the world is that the stupid are cocksure and the
> intelligent are full of doubt.    -- Bertrand Russell
>
> ---------------------------------------------------------------------
>
> Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<puppet-dev%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" 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-dev?hl=en.

Reply via email to