Issue #2596 has been updated by James Turnbull.

Status changed from Ready for Testing to Closed

Pushed in commit:"8971d8beae2c409f9052f27c3f80ad3bdfff4de2" in branch master.
----------------------------------------
Refactor #2596: HostClass/Definition/Node should be extracted from AST classes 
into a common resource type model
http://projects.reductivelabs.com/issues/2596

Author: Luke Kanies
Status: Closed
Priority: Normal
Assigned to: James Turnbull
Category: parser
Target version: Rowlf
Affected version: 0.24.8
Branch: luke/tickets/master/2596


Currently, the AST classes for HostClass/Definition/Node have two kinds of 
functionality:  The parts that behave like an AST instance, and the parts that 
behave like resource types (which each of these functionally are).

We should extract this functionality from the AST code, so the AST code is 
smaller and the resource type code is exposed and directly usable.

The primary goals of this would be to have this new code be a platform for 
future remodeling of the RAL - defining new resource types here would become 
the way to define resource types in the RAL.

These types would need to be per-environment, like they are now, which would 
*also* be a good thing, because it would give us the opportunity to have 
builtin, per-environment types, which we can't do right now (at least, not on 
the server).

There are two interesting aspects of this problem related to the RAL:

We need to be able to define all, or at least most, of the same functionality 
in the RAL:  Parameter defaults, dependencies, validation, etc.

We also need a smoother, meant-for-humans pseudo-DSL for making this easy to 
define.  See below for examples.

The goal here is to make it easier to have parse-time information about the 
resource types/classes/etc. defined in the language, and preferably, allow 
users to define defined resources type in pure ruby.  E.g., the normal means of 
defining a resource type in the language limits you to just having defaults, 
but no validation.  If you wanted defaults plus validation, you could take your 
pure-Puppet resource type and convert it to ruby.  This:
<pre>
define foo($val = "bar", $other) {
  file { "/my/$name/$val": ... }
}
</pre>
Becomes:
<pre>
Puppet::ResourceType.new(:foo) do
  add_parameter(:val) do
    defaultto "bar"
    validate do |...| ... end
  end
  add_parameter(:other) do ... end

  includes do
    file "/my/#{name}/#{val}", ...
  end
end
</pre>
This gives us a clean path from Puppet resource types, to mostly ruby, to 
entirely ruby.

Setting for 0.26, but I think it's unlikely.
-----------
Example API stuff
<pre>
type = Puppet::Parser::ResourceType.new(:file)
mode = type.add_parameter(:mode)
mode.validate do |...|
end
</pre>
vs.:
<pre>
Puppet::Parser::ResourceType.new(:file) do
  add_parameter(:mode) do
    validate do |...|
    end
  end
end
</pre>
Probably, you'd do something like this:
<pre>
class Puppet::ResourceType
  def add_parameter(...) ... end
  
  include Puppet::DslMaker
  self_methods :initialize
  other_methods :add_parameter
end

class Puppet::ResourceType::Parameter
  def validate(...) ... end
  include Puppet::DslMaker

  self_methods :validate, :initialize
end
</pre>
You could instead do something like:
<pre>
class Puppet::ResourceType
  def add_parameter(...) ... end
end

Puppet::DSLMaker.new(Puppet::ResourceType) do
  self_methods :initialize
  other_methods :add_parameter
end

class Puppet::ResourceType::Parameter
  def validate(...) ... end
end

Puppet::DslMaker.new(Puppet::ResourceType::Parameter) do
  self_methods :validate, :initialize
end
</pre>


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://reductivelabs.com/redmine/my/account

--

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


Reply via email to