summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/indirector/code/configuration.rb10
-rw-r--r--lib/puppet/indirector/indirection.rb9
-rw-r--r--lib/puppet/indirector/terminus.rb10
-rw-r--r--lib/puppet/indirector/yaml.rb18
-rw-r--r--lib/puppet/indirector/yaml/configuration.rb18
-rw-r--r--lib/puppet/network/handler/configuration.rb10
-rw-r--r--lib/puppet/node/configuration.rb57
-rw-r--r--lib/puppet/pgraph.rb4
-rw-r--r--lib/puppet/transportable.rb68
-rw-r--r--lib/puppet/type/component.rb10
10 files changed, 162 insertions, 52 deletions
diff --git a/lib/puppet/indirector/code/configuration.rb b/lib/puppet/indirector/code/configuration.rb
index 2d8fedcc8..949926a3c 100644
--- a/lib/puppet/indirector/code/configuration.rb
+++ b/lib/puppet/indirector/code/configuration.rb
@@ -21,9 +21,13 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code
node = find_node(key)
end
- configuration = compile(node)
-
- return configuration
+ if configuration = compile(node)
+ return configuration.to_transportable
+ else
+ # This shouldn't actually happen; we should either return
+ # a config or raise an exception.
+ return nil
+ end
end
def initialize
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index cd71c4d66..5f7baa3da 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -91,12 +91,15 @@ class Puppet::Indirector::Indirection
end
def find(key, *args)
- if cache? and terminus.fresh?(key, cache.version(key))
+ if cache? and cache.has_most_recent?(key, terminus.version(key))
return cache.find(key, *args)
end
if result = terminus.find(key, *args)
result.version ||= Time.now.utc
- cache.save(result, *args) if cache?
+ if cache?
+ Puppet.info "Caching %s %s" % [self.name, key]
+ cache.save(result, *args)
+ end
return result
end
end
@@ -113,7 +116,7 @@ class Puppet::Indirector::Indirection
def save(instance, *args)
instance.version ||= Time.now.utc
dest = cache? ? cache : terminus
- return if dest.fresh?(instance.name, instance.version)
+ return if dest.has_most_recent?(instance.name, instance.version)
cache.save(instance, *args) if cache?
terminus.save(instance, *args)
end
diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb
index 5aeb4c6d7..37cfdc499 100644
--- a/lib/puppet/indirector/terminus.rb
+++ b/lib/puppet/indirector/terminus.rb
@@ -95,13 +95,15 @@ class Puppet::Indirector::Terminus
end
end
- # Is this instance fresh? Meaning, is the version we have equivalent or better
- # than the version being asked about
- def fresh?(key, vers)
+ # Do we have an update for this object? This compares the provided version
+ # to our version, and returns true if our version is at least as high
+ # as the asked-about version.
+ def has_most_recent?(key, vers)
raise Puppet::DevError.new("Cannot check update status when no 'version' method is defined") unless respond_to?(:version)
if existing_version = version(key)
- existing_version >= vers
+ #puts "%s fresh: %s (%s vs %s)" % [self.name, (existing_version.to_f >= vers.to_f).inspect, existing_version.to_f, vers.to_f]
+ existing_version.to_f >= vers.to_f
else
false
end
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb
index b9ea54f39..e11c88474 100644
--- a/lib/puppet/indirector/yaml.rb
+++ b/lib/puppet/indirector/yaml.rb
@@ -14,9 +14,9 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
return nil unless FileTest.exist?(file)
begin
- return YAML.load(File.read(file))
+ return from_yaml(File.read(file))
rescue => detail
- raise Puppet::Error, "Could not read YAML data for %s(%s): %s" % [indirection.name, name, detail]
+ raise Puppet::Error, "Could not read YAML data for %s %s: %s" % [indirection.name, name, detail]
end
end
@@ -33,11 +33,23 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
Dir.mkdir(basedir)
end
- File.open(file, "w", 0660) { |f| f.print YAML.dump(object) }
+ begin
+ File.open(file, "w", 0660) { |f| f.print to_yaml(object) }
+ rescue TypeError => detail
+ Puppet.err "Could not save %s %s: %s" % [self.name, object.name, detail]
+ end
end
private
+ def from_yaml(text)
+ YAML.load(text)
+ end
+
+ def to_yaml(object)
+ YAML.dump(object)
+ end
+
# Return the path to a given node's file.
def path(name)
File.join(Puppet[:yamldir], self.name.to_s, name.to_s + ".yaml")
diff --git a/lib/puppet/indirector/yaml/configuration.rb b/lib/puppet/indirector/yaml/configuration.rb
index 691f0e343..8e40ff9bf 100644
--- a/lib/puppet/indirector/yaml/configuration.rb
+++ b/lib/puppet/indirector/yaml/configuration.rb
@@ -2,4 +2,22 @@ require 'puppet/indirector/yaml'
class Puppet::Indirector::Yaml::Configuration < Puppet::Indirector::Yaml
desc "Store configurations as flat files, serialized using YAML."
+
+ private
+
+ # Override these, because yaml doesn't want to convert our self-referential
+ # objects. This is hackish, but eh.
+ def from_yaml(text)
+ if config = YAML.load(text)
+ # We can't yaml-dump classes.
+ #config.edgelist_class = Puppet::Relationship
+ return config
+ end
+ end
+
+ def to_yaml(config)
+ # We can't yaml-dump classes.
+ #config.edgelist_class = nil
+ YAML.dump(config)
+ end
end
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb
index 09c4b971a..680304e2a 100644
--- a/lib/puppet/network/handler/configuration.rb
+++ b/lib/puppet/network/handler/configuration.rb
@@ -13,7 +13,7 @@ class Puppet::Network::Handler
include Puppet::Util
- attr_accessor :local
+ attr_accessor :local, :classes
@interface = XMLRPC::Service::Interface.new("configuration") { |iface|
iface.add_method("string configuration(string)")
@@ -43,16 +43,10 @@ class Puppet::Network::Handler
end
def initialize(options = {})
- if options[:Local]
- @local = options[:Local]
- else
- @local = false
- end
-
options.each do |param, value|
case param
when :Classes: @classes = value
- when :Local: self.local = true
+ when :Local: self.local = value
else
raise ArgumentError, "Configuration handler does not accept %s" % param
end
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index 084bdf880..da8dc3a9a 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -22,6 +22,10 @@ class Puppet::Node::Configuration < Puppet::PGraph
# How we should extract the configuration for sending to the client.
attr_reader :extraction_format
+ # We need the ability to set this externally, so we can yaml-dump the
+ # configuration.
+ attr_accessor :edgelist_class
+
# Whether this is a host configuration, which behaves very differently.
# In particular, reports are sent, graphs are made, and state is
# stored in the state database. If this is set incorrectly, then you often
@@ -355,6 +359,16 @@ class Puppet::Node::Configuration < Puppet::PGraph
@tags.dup
end
+ # Convert our configuration into a RAL configuration.
+ def to_ral
+ to_configuration :to_type
+ end
+
+ # Turn our parser configuration into a transportable configuration.
+ def to_transportable
+ to_configuration :to_transobject
+ end
+
# Produce the graph files if requested.
def write_graph(name)
# We only want to graph the main host configuration.
@@ -370,6 +384,14 @@ class Puppet::Node::Configuration < Puppet::PGraph
}
end
+ # LAK:NOTE We cannot yaml-dump the class in the edgelist_class, because classes cannot be
+ # dumped by default, nor does yaml-dumping # the edge-labels work at this point (I don't
+ # know why).
+ # Neither of these matters right now, but I suppose it could at some point.
+ def to_yaml_properties
+ instance_variables.reject { |v| %w{@edgelist_class @edge_labels}.include?(v) }
+ end
+
private
def cleanup
@@ -379,4 +401,39 @@ class Puppet::Node::Configuration < Puppet::PGraph
@relationship_graph = nil
end
end
+
+ # An abstracted method for converting one configuration into another type of configuration.
+ # This pretty much just converts all of the resources from one class to another, using
+ # a conversion method.
+ def to_configuration(convert)
+ result = self.class.new(self.name)
+
+ vertices.each do |resource|
+ next if resource.respond_to?(:virtual?) and resource.virtual?
+
+ result.add_resource resource.send(convert)
+ end
+
+ message = convert.to_s.gsub "_", " "
+ edges.each do |edge|
+ # Skip edges between virtual resources.
+ next if edge.source.respond_to?(:virtual?) and edge.source.virtual?
+ next if edge.target.respond_to?(:virtual?) and edge.target.virtual?
+
+ unless source = result.resource(edge.source.ref)
+ raise Puppet::DevError, "Could not find vertex for %s when converting %s" % [edge.source.ref, message]
+ end
+
+ unless target = result.resource(edge.target.ref)
+ raise Puppet::DevError, "Could not find vertex for %s when converting %s" % [edge.target.ref, message]
+ end
+
+ result.add_edge!(source, target, edge.label)
+ end
+
+ result.add_class *self.classes
+ result.tag(*self.tags)
+
+ return result
+ end
end
diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb
index 2399d1651..ca45aa2b3 100644
--- a/lib/puppet/pgraph.rb
+++ b/lib/puppet/pgraph.rb
@@ -190,6 +190,10 @@ class Puppet::PGraph < GRATR::Digraph
return result
end
+ def to_yaml_properties
+ instance_variables
+ end
+
# A different way of walking a tree, and a much faster way than the
# one that comes with GRATR.
def tree_from_vertex2(start, direction = :out)
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index ecd179ed7..2a600b50e 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -8,7 +8,7 @@ module Puppet
# YAML.
class TransObject
include Enumerable
- attr_accessor :type, :name, :file, :line, :collectable, :collected
+ attr_accessor :type, :name, :file, :line, :configuration
attr_writer :tags
@@ -25,7 +25,6 @@ module Puppet
def initialize(name,type)
@type = type
@name = name
- @collectable = false
@params = {}
@tags = []
end
@@ -34,10 +33,44 @@ module Puppet
return [@type,@name].join('--')
end
+ def ref
+ unless defined? @ref
+ if @type == :component
+ @ref = @name
+ else
+ @ref = "%s[%s]" % [type_capitalized, name]
+ end
+ end
+ @ref
+ end
+
def tags
return @tags
end
+ # Convert a defined type into a component.
+ def to_component
+ tmpname = nil
+
+ # Nodes have the same name and type
+ if self.name
+ tmpname = "%s[%s]" % [type_capitalized, self.name]
+ else
+ tmpname = @type
+ end
+ trans = TransObject.new(tmpname, :component)
+ if defined? @parameters
+ @parameters.each { |param,value|
+ Puppet.debug "Defining %s on %s of type %s" %
+ [param,@name,@type]
+ trans[param] = value
+ }
+ else
+ #Puppet.debug "%s[%s] has no parameters" % [@type, @name]
+ end
+ Puppet::Type::Component.create(trans)
+ end
+
def to_hash
@params.dup
end
@@ -57,18 +90,18 @@ module Puppet
end
def to_yaml_properties
- instance_variables
+ instance_variables.reject { |v| %w{@ref}.include?(v) }
end
def to_ref
- unless defined? @ref
+ unless defined? @res_ref
if self.type and self.name
- @ref = "%s[%s]" % [self.type, self.name]
+ @res_ref = "%s[%s]" % [type_capitalized, self.name]
else
- @ref = nil
+ @res_ref = nil
end
end
- @ref
+ @res_ref
end
def to_type
@@ -85,11 +118,16 @@ module Puppet
end
end
else
- raise Puppet::Error.new("Could not find object type %s" % self.type)
+ return to_component
end
return retobj
end
+
+ # Return the type fully capitalized correctly.
+ def type_capitalized
+ type.split("::").collect { |s| s.capitalize }.join("::")
+ end
end
# Just a linear container for objects. Behaves mostly like an array, except
@@ -107,20 +145,6 @@ module Puppet
end
}
- # Remove all collectable objects from our tree, since the client
- # should not see them.
- def collectstrip!
- @children.dup.each do |child|
- if child.is_a? self.class
- child.collectstrip!
- else
- if child.collectable and ! child.collected
- @children.delete(child)
- end
- end
- end
- end
-
# Recursively yield everything.
def delve(&block)
@children.each do |obj|
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index c5842e0e7..4dc542a65 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -109,14 +109,6 @@ Puppet::Type.newtype(:component) do
@children = []
end
- def parent=(parent)
- if self.parentof?(parent)
- devfail "%s[%s] is already the parent of %s[%s]" %
- [self.class.name, self.title, parent.class.name, parent.title]
- end
- @parent = parent
- end
-
# Add a hook for testing for recursion.
def parentof?(child)
if super(child)
@@ -133,7 +125,7 @@ Puppet::Type.newtype(:component) do
def pathbuilder
tmp = []
myname = ""
- if self.title =~ /^class\[(.+)\]$/
+ if self.title =~ /^class\[(.+)\]$/i
# 'main' is the top class, so we want to see '//' instead of
# its name.
unless $1 == "main"