summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-12-11 17:59:41 -0600
committerLuke Kanies <luke@madstop.com>2008-12-18 11:10:23 -0600
commit91ff7c1f9c591936b0d39349baf0d1602a69923b (patch)
tree5cb4018e95bebc276790c9d78d3e75f8f4e08147 /lib/puppet
parentfae30756e48184dfc8238dcfe80b843f981b6070 (diff)
downloadpuppet-91ff7c1f9c591936b0d39349baf0d1602a69923b.tar.gz
puppet-91ff7c1f9c591936b0d39349baf0d1602a69923b.tar.xz
puppet-91ff7c1f9c591936b0d39349baf0d1602a69923b.zip
TransObject is nearly deprecated now.
This is all of the plumbing work, the only real thing left to do is to fix the Settings class so that it uses Puppet::Resource instances instead of TransObject and TransBucket. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/resource/catalog.rb10
-rw-r--r--lib/puppet/resource/reference.rb4
-rw-r--r--lib/puppet/transportable.rb32
-rw-r--r--lib/puppet/type.rb77
-rw-r--r--lib/puppet/type/component.rb44
5 files changed, 71 insertions, 96 deletions
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 56534b6be..ce54f6d75 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -209,7 +209,8 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
end
# Create the traditional TransBuckets and TransObjects from our catalog
- # graph. This will hopefully be deprecated soon.
+ # graph. LAK:NOTE(20081211): This is a pre-0.25 backward compatibility method.
+ # It can be removed as soon as xmlrpc is killed.
def extract_to_transportable
top = nil
current = nil
@@ -338,7 +339,6 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
end
end
end
-
@relationship_graph.write_graph(:relationships) if host_config?
# Then splice in the container information
@@ -388,9 +388,9 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
to_catalog :to_ral
end
- # Turn our parser catalog into a transportable catalog.
- def to_transportable
- to_catalog :to_transobject
+ # Convert our catalog into a catalog of Puppet::Resource instances.
+ def to_resource
+ to_catalog :to_resource
end
# Produce the graph files if requested.
diff --git a/lib/puppet/resource/reference.rb b/lib/puppet/resource/reference.rb
index d17b3e558..7f33160bd 100644
--- a/lib/puppet/resource/reference.rb
+++ b/lib/puppet/resource/reference.rb
@@ -24,7 +24,9 @@ class Puppet::Resource::Reference
def initialize(argtype, argtitle = nil)
if argtitle.nil?
self.title = argtype
- raise ArgumentError, "No title provided and title '%s' is not a valid resource reference" % argtype if self.title == argtype
+ if self.title == argtype
+ raise ArgumentError, "No title provided and title '%s' is not a valid resource reference" % argtype
+ end
else
# This will set @type if it looks like a resource reference.
self.title = argtitle
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index c63e2419c..052f6bab1 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -78,6 +78,14 @@ module Puppet
]
end
+ # Create a normalized resource from our TransObject.
+ def to_resource
+ result = Puppet::Resource.new(type, name, @params.dup)
+ result.tag(*tags)
+
+ result
+ end
+
def to_yaml_properties
instance_variables.reject { |v| %w{@ref}.include?(v) }
end
@@ -87,11 +95,7 @@ module Puppet
end
def to_ral
- if typeklass = Puppet::Type.type(self.type)
- return typeklass.create(self)
- else
- return to_component
- end
+ to_resource.to_ral
end
end
@@ -234,17 +238,13 @@ module Puppet
end
def to_ral
- Puppet.debug("TransBucket '%s' has no type" % @name) unless defined? @type
-
- # Nodes have the same name and type
- trans = TransObject.new(to_ref, :component)
- if defined? @parameters
- @parameters.each { |param,value|
- Puppet.debug "Defining %s on %s" % [param, to_ref]
- trans[param] = value
- }
- end
- return Puppet::Type::Component.create(trans)
+ to_resource.to_ral
+ end
+
+ # Create a normalized resource from our TransObject.
+ def to_resource
+ params = defined?(@parameters) ? @parameters.dup : {}
+ Puppet::Resource.new(type, name, params)
end
def param(param,value)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 200a05e60..2f1a19ea8 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -185,8 +185,6 @@ class Type
end
end
end
-
- # If this param handles relationships, store that information
end
# Is the parameter in question a meta-parameter?
@@ -1209,47 +1207,6 @@ class Type
}
end
end
-
- # We've got four relationship metaparameters, so this method is used
- # to reduce code duplication between them.
- def munge_relationship(param, values)
- # We need to support values passed in as an array or as a
- # resource reference.
- result = []
-
- # 'values' could be an array or a reference. If it's an array,
- # it could be an array of references or an array of arrays.
- if values.is_a?(Puppet::Type)
- result << [values.class.name, values.title]
- else
- unless values.is_a?(Array)
- devfail "Relationships must be resource references"
- end
- if values[0].is_a?(String) or values[0].is_a?(Symbol)
- # we're a type/title array reference
- values[0] = symbolize(values[0])
- result << values
- else
- # we're an array of stuff
- values.each do |value|
- if value.is_a?(Puppet::Type)
- result << [value.class.name, value.title]
- elsif value.is_a?(Array)
- value[0] = symbolize(value[0])
- result << value
- else
- devfail "Invalid relationship %s" % value.inspect
- end
- end
- end
- end
-
- if existing = self[param]
- result = existing + result
- end
-
- result
- end
newmetaparam(:loglevel) do
desc "Sets the level that information will be logged.
@@ -1363,16 +1320,22 @@ class Type
@subclasses << sub
end
- def munge(rels)
- @resource.munge_relationship(self.class.name, rels)
+ def munge(references)
+ references = [references] unless references.is_a?(Array)
+ references.collect do |ref|
+ if ref.is_a?(Puppet::Resource::Reference)
+ ref
+ else
+ Puppet::Resource::Reference.new(ref)
+ end
+ end
end
def validate_relationship
- @value.each do |value|
- unless @resource.catalog.resource(*value)
+ @value.each do |ref|
+ unless @resource.catalog.resource(ref.to_s)
description = self.class.direction == :in ? "dependency" : "dependent"
- fail Puppet::Error, "Could not find %s %s[%s] for %s" %
- [description, value[0].to_s.capitalize, value[1], resource.ref]
+ fail "Could not find %s %s for %s" % [description, ref.to_s, resource.ref]
end
end
end
@@ -1386,27 +1349,23 @@ class Type
# which resource is applied first and which resource is considered
# to be the event generator.
def to_edges
- @value.collect do |value|
- # we just have a name and a type, and we need to convert it
- # to an object...
- tname, name = value
- reference = Puppet::Resource::Reference.new(tname, name)
+ @value.collect do |reference|
reference.catalog = resource.catalog
# Either of the two retrieval attempts could have returned
# nil.
- unless object = reference.resolve
+ unless related_resource = reference.resolve
self.fail "Could not retrieve dependency '%s' of %s" % [reference, @resource.ref]
end
# Are we requiring them, or vice versa? See the method docs
# for futher info on this.
if self.class.direction == :in
- source = object
+ source = related_resource
target = @resource
else
source = @resource
- target = object
+ target = related_resource
end
if method = self.class.callback
@@ -1414,12 +1373,12 @@ class Type
:event => self.class.events,
:callback => method
}
- self.debug("subscribes to %s" % [object.ref])
+ self.debug("subscribes to %s" % [related_resource.ref])
else
# If there's no callback, there's no point in even adding
# a label.
subargs = nil
- self.debug("requires %s" % [object.ref])
+ self.debug("requires %s" % [related_resource.ref])
end
rel = Puppet::Relationship.new(source, target, subargs)
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index 37643f736..724e2985a 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -11,36 +11,42 @@ Puppet::Type.newtype(:component) do
isnamevar
end
- newparam(:type) do
- desc "The type that this component maps to. Generally some kind of
- class from the language."
+ # Override how parameters are handled so that we support the extra
+ # parameters that are used with defined resource types.
+ def [](param)
+ return super if self.class.validattr?(param)
+ @extra_parameters[param.to_sym]
+ end
- defaultto "component"
+ # Override how parameters are handled so that we support the extra
+ # parameters that are used with defined resource types.
+ def []=(param, value)
+ return super if self.class.validattr?(param)
+ @extra_parameters[param.to_sym] = value
end
# Initialize a new component
def initialize(*args)
+ @extra_parameters = {}
super
- @reference = Puppet::Resource::Reference.new(:component, @title)
-
- if catalog and ! catalog.resource(@reference.to_s)
- catalog.alias(self, @reference.to_s)
+ if catalog and ! catalog.resource(ref)
+ catalog.alias(self, ref)
end
end
# Component paths are special because they function as containers.
def pathbuilder
- if @reference.type == "Class"
+ if reference.type == "Class"
# 'main' is the top class, so we want to see '//' instead of
# its name.
- if @reference.title == "main"
+ if reference.title == "main"
myname = ""
else
- myname = @reference.title
+ myname = reference.title
end
else
- myname = @reference.to_s
+ myname = reference.to_s
end
if p = self.parent
return [p.pathbuilder, myname]
@@ -50,12 +56,16 @@ Puppet::Type.newtype(:component) do
end
def ref
- @reference.to_s
+ reference.to_s
end
# We want our title to just be the whole reference, rather than @title.
def title
- @reference.to_s
+ ref
+ end
+
+ def title=(str)
+ @reference = Puppet::Resource::Reference.new(str)
end
def refresh
@@ -68,6 +78,10 @@ Puppet::Type.newtype(:component) do
end
def to_s
- @reference.to_s
+ reference.to_s
end
+
+ private
+
+ attr_reader :reference
end