summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/metatype/instances.rb37
-rw-r--r--lib/puppet/metatype/metaparams.rb11
-rw-r--r--lib/puppet/metatype/relationships.rb16
-rw-r--r--lib/puppet/metatype/schedules.rb4
-rw-r--r--lib/puppet/network/client/master.rb28
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb7
-rwxr-xr-xlib/puppet/network/handler/resource.rb31
-rw-r--r--lib/puppet/node/configuration.rb21
-rw-r--r--lib/puppet/transportable.rb15
-rw-r--r--lib/puppet/type.rb12
-rw-r--r--lib/puppet/type/component.rb8
-rw-r--r--lib/puppet/type/pfile.rb63
-rwxr-xr-xlib/puppet/type/pfilebucket.rb17
-rwxr-xr-xlib/puppet/type/schedule.rb29
-rwxr-xr-xlib/puppet/util/filetype.rb2
15 files changed, 179 insertions, 122 deletions
diff --git a/lib/puppet/metatype/instances.rb b/lib/puppet/metatype/instances.rb
index 8fc25d0bb..8cc648e8f 100644
--- a/lib/puppet/metatype/instances.rb
+++ b/lib/puppet/metatype/instances.rb
@@ -8,13 +8,11 @@ class Puppet::Type
# retrieve a named instance of the current type
def self.[](name)
- raise "DEPRECATED [], yo"
@objects[name] || @aliases[name]
end
# add an instance by name to the class list of instances
def self.[]=(name,object)
- raise "DEPRECATED []=, yo"
newobj = nil
if object.is_a?(Puppet::Type)
newobj = object
@@ -130,6 +128,36 @@ class Puppet::Type
#Puppet.debug "Creating %s[%s]" % [self.name, title]
+ # if the object already exists
+ if self.isomorphic? and retobj = self[title]
+ # if only one of our objects is implicit, then it's easy to see
+ # who wins -- the non-implicit one.
+ if retobj.implicit? and ! implicit
+ Puppet.notice "Removing implicit %s" % retobj.title
+ # Remove all of the objects, but do not remove their subscriptions.
+ retobj.remove(false)
+
+ # now pass through and create the new object
+ elsif implicit
+ Puppet.debug "Ignoring implicit %s[%s]" % [self.name, title]
+ return nil
+ else
+ # If only one of the objects is being managed, then merge them
+ if retobj.managed?
+ raise Puppet::Error, "%s '%s' is already being managed" %
+ [self.name, title]
+ else
+ retobj.merge(hash)
+ return retobj
+ end
+ # We will probably want to support merging of some kind in
+ # the future, but for now, just throw an error.
+ #retobj.merge(hash)
+
+ #return retobj
+ end
+ end
+
# create it anew
# if there's a failure, destroy the object if it got that far, but raise
# the error.
@@ -139,6 +167,8 @@ class Puppet::Type
Puppet.err "Could not create %s: %s" % [title, detail.to_s]
if obj
obj.remove(true)
+ elsif obj = self[title]
+ obj.remove(true)
end
raise
end
@@ -147,6 +177,9 @@ class Puppet::Type
obj.implicit = true
end
+ # Store the object by title
+ self[obj.title] = obj
+
return obj
end
diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb
index 8ac2ead9f..eb158a47d 100644
--- a/lib/puppet/metatype/metaparams.rb
+++ b/lib/puppet/metatype/metaparams.rb
@@ -272,11 +272,16 @@ class Puppet::Type
# which resource is applied first and which resource is considered
# to be the event generator.
def to_edges
- raise(Puppet::DevError, "Cannot create dependencies without a configuration") unless resource.configuration
- @value.collect do |tname, name|
+ @value.collect do |value|
# we just have a name and a type, and we need to convert it
# to an object...
- object = resource.configuration.resource(tname, name)
+ tname, name = value
+ object = nil
+ if type = Puppet::Type.type(tname)
+ object = type[name]
+ else # try to treat it as a component
+ object = Puppet::Type::Component["#{tname}[#{name}]"]
+ end
# Either of the two retrieval attempts could have returned
# nil.
diff --git a/lib/puppet/metatype/relationships.rb b/lib/puppet/metatype/relationships.rb
index 2a5341e5e..4fb78ae56 100644
--- a/lib/puppet/metatype/relationships.rb
+++ b/lib/puppet/metatype/relationships.rb
@@ -18,9 +18,11 @@ class Puppet::Type
# Figure out of there are any objects we can automatically add as
# dependencies.
def autorequire
- raise(ArgumentError, "Cannot autorequire resources without a configuration") unless configuration
reqs = []
self.class.eachautorequire { |type, block|
+ # Ignore any types we can't find, although that would be a bit odd.
+ next unless typeobj = Puppet.type(type)
+
# Retrieve the list of names from the block.
next unless list = self.instance_eval(&block)
unless list.is_a?(Array)
@@ -29,16 +31,16 @@ class Puppet::Type
# Collect the current prereqs
list.each { |dep|
+ obj = nil
# Support them passing objects directly, to save some effort.
- if dep.is_a?(Puppet::Type)
- next unless configuration.resource(type, dep.title)
- resource = dep
- else
+ unless dep.is_a? Puppet::Type
# Skip autorequires that we aren't managing
- next unless resource = configuration.resource(type, dep)
+ unless dep = typeobj[dep]
+ next
+ end
end
- reqs << Puppet::Relationship.new(resource, self)
+ reqs << Puppet::Relationship.new(dep, self)
}
}
diff --git a/lib/puppet/metatype/schedules.rb b/lib/puppet/metatype/schedules.rb
index 4d4f93764..96ebce0ab 100644
--- a/lib/puppet/metatype/schedules.rb
+++ b/lib/puppet/metatype/schedules.rb
@@ -4,8 +4,8 @@ class Puppet::Type
# file.
def schedule
unless defined? @schedule
- if name = self[:schedule] and self.configuration
- if sched = configuration.resource(:schedule, name)
+ if name = self[:schedule]
+ if sched = Puppet.type(:schedule)[name]
@schedule = sched
else
self.fail "Could not find schedule %s" % name
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index 691681f9e..ea351ddc3 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -69,6 +69,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
def clear
@configuration.clear(true) if @configuration
Puppet::Type.allclear
+ mkdefault_objects
@configuration = nil
end
@@ -189,8 +190,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
# Keep the state database up to date.
@configuration.host_config = true
-
- add_default_resources(@configuration)
end
# A simple proxy method, so it's easy to test.
@@ -205,6 +204,17 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
self.class.instance = self
@running = false
+
+ mkdefault_objects
+ end
+
+ # Make the default objects necessary for function.
+ def mkdefault_objects
+ # First create the default scheduling objects
+ Puppet::Type.type(:schedule).mkdefaultschedules
+
+ # And filebuckets
+ Puppet::Type.type(:filebucket).mkdefaultbucket
end
# Mark that we should restart. The Puppet module checks whether we're running,
@@ -549,18 +559,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
private
- # Add our default resources to the configuration.
- def add_default_resources(configuration)
- # These are the only two resource types with default resources.
- # We should probably iterate across all of them, but I think that's
- # unnecessarily expensive at this point.
- [:schedule, :filebucket].each do |resource_type|
- Puppet::Type.type(resource_type).create_default_resources.each do |resource|
- configuration.add_resource(resource) unless configuration.resource(resource_type, resource.title)
- end
- end
- end
-
# Use our cached config, optionally specifying whether this is
# necessary because of a failure.
def use_cached_config(because_of_failure = false)
@@ -584,8 +582,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
clear
return false
end
-
- add_default_resources(@configuration)
return true
end
end
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index 7a5a1fe9a..dd00450be 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -551,25 +551,22 @@ class Puppet::Network::Handler
@path = nil
end
- @cache = {}
-
super()
end
def fileobj(path, links)
obj = nil
- if obj = @cache[path]
+ if obj = Puppet.type(:file)[path]
# This can only happen in local fileserving, but it's an
# important one. It'd be nice if we didn't just set
# the check params every time, but I'm not sure it's worth
# the effort.
obj[:check] = CHECKPARAMS
else
- obj = Puppet::Type.type(:file).create(
+ obj = Puppet.type(:file).create(
:name => path,
:check => CHECKPARAMS
)
- @cache[path] = obj
end
if links == :manage
diff --git a/lib/puppet/network/handler/resource.rb b/lib/puppet/network/handler/resource.rb
index c96bdf6a6..0fcd694fb 100755
--- a/lib/puppet/network/handler/resource.rb
+++ b/lib/puppet/network/handler/resource.rb
@@ -53,8 +53,8 @@ class Puppet::Network::Handler
return "success"
end
- # Describe a given resource. This returns the 'is' values for every property
- # available on the resource type.
+ # Describe a given object. This returns the 'is' values for every property
+ # available on the object type.
def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
Puppet.info "Describing %s[%s]" % [type.to_s.capitalize, name]
@local = true unless client
@@ -63,23 +63,29 @@ class Puppet::Network::Handler
raise Puppet::Error, "Puppet type %s is unsupported" % type
end
+ obj = nil
+
retrieve ||= :all
ignore ||= []
- begin
- resource = typeklass.create(:name => name, :check => retrieve)
- rescue Puppet::Error => detail
- raise Puppet::Error, "%s[%s] could not be created: %s" %
- [type, name, detail]
+ if obj = typeklass[name]
+ obj[:check] = retrieve
+ else
+ begin
+ obj = typeklass.create(:name => name, :check => retrieve)
+ rescue Puppet::Error => detail
+ raise Puppet::Error, "%s[%s] could not be created: %s" %
+ [type, name, detail]
+ end
end
- unless resource
+ unless obj
raise XMLRPC::FaultException.new(
1, "Could not create %s[%s]" % [type, name]
)
end
- trans = resource.to_trans
+ trans = obj.to_trans
# Now get rid of any attributes they specifically don't want
ignore.each do |st|
@@ -132,10 +138,11 @@ class Puppet::Network::Handler
bucket = Puppet::TransBucket.new
bucket.type = typeklass.name
- typeklass.instances.each do |resource|
- next if ignore.include? resource.name
+ typeklass.instances.each do |obj|
+ next if ignore.include? obj.name
- bucket << resource.to_trans
+ #object = Puppet::TransObject.new(obj.name, typeklass.name)
+ bucket << obj.to_trans
end
unless @local
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index e131839df..804f357d1 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -60,22 +60,11 @@ class Puppet::Node::Configuration < Puppet::PGraph
end
ref = resource.ref
-
if @resource_table.include?(ref)
raise ArgumentError, "Resource %s is already defined" % ref
else
@resource_table[ref] = resource
end
-
- # If the name and title differ, set up an alias
- if ! resource.is_a?(Puppet::Type::Component) and resource.respond_to?(:title) and resource.name != resource.title
- if obj = resource(resource.class.name, resource.name)
- raise Puppet::Error, "%s already exists with name %s" % [obj.title, self.name] if resource.class.isomorphic?
- else
- self.alias(resource, resource.name)
- end
- end
-
resource.configuration = self unless is_relationship_graph
add_vertex!(resource)
end
@@ -194,11 +183,6 @@ class Puppet::Node::Configuration < Puppet::PGraph
unless klass = Puppet::Type.type(type)
raise ArgumentError, "Unknown resource type %s" % type
end
- if options.is_a?(Puppet::TransObject)
- options.configuration = self
- else
- options[:configuration] = self
- end
return unless resource = klass.create(options)
@transient_resources << resource if applying?
@@ -386,11 +370,6 @@ class Puppet::Node::Configuration < Puppet::PGraph
end
end
- # Return an array of the currently-defined resources.
- def resources
- @resource_table.keys
- end
-
# Add a tag.
def tag(*names)
names.each do |name|
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 8f8c32b8d..6a573489c 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -52,10 +52,13 @@ module Puppet
def to_component
tmpname = nil
- tmpname = "%s[%s]" % [type_capitalized, self.name]
-
+ # 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)
-
@params.each { |param,value|
next unless Puppet::Type::Component.validattr?(param)
Puppet.debug "Defining %s on %s of type %s" % [param,@name,@type]
@@ -88,7 +91,11 @@ module Puppet
def to_ref
unless defined? @res_ref
- @res_ref = "%s[%s]" % [type_capitalized, self.name]
+ if self.type and self.name
+ @res_ref = "%s[%s]" % [type_capitalized, self.name]
+ else
+ @res_ref = nil
+ end
end
@res_ref
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 3f69bc8b1..f5dd0f8dd 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -228,6 +228,18 @@ class Type
self.devfail "I was not passed a namevar"
end
+ # If the name and title differ, set up an alias
+ if self.name != self.title
+ if obj = self.class[self.name]
+ if self.class.isomorphic?
+ raise Puppet::Error, "%s already exists with name %s" %
+ [obj.title, self.name]
+ end
+ else
+ self.class.alias(self.name, self)
+ end
+ end
+
if hash.include?(:provider)
self[:provider] = hash[:provider]
hash.delete(:provider)
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index 0a7c182cf..7aa24a302 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -20,7 +20,7 @@ Puppet::Type.newtype(:component) do
desc "The type that this component maps to. Generally some kind of
class from the language."
- defaultto "class"
+ defaultto "component"
end
# Remove a child from the component.
@@ -97,8 +97,10 @@ Puppet::Type.newtype(:component) do
@children = []
super
- unless @title.include?("[")
- @title = "%s[%s]" % [self[:type].capitalize, @title]
+ # If the title isn't a full resource reference, assume
+ # we're a class and make an alias for that.
+ unless @title.to_s.include?("[")
+ self.class.alias("class[%s]" % @title, self)
end
end
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index d6dfd86e0..73c60bd14 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -73,11 +73,10 @@ module Puppet
"
defaultto do
- if resource.configuration and bucket_resource = resource.configuration.resource(:filebucket, "puppet")
- bucket_resource.bucket
- else
- nil
- end
+ # Make sure the default file bucket exists.
+ obj = Puppet::Type.type(:filebucket)["puppet"] ||
+ Puppet::Type.type(:filebucket).create(:name => "puppet")
+ obj.bucket
end
munge do |value|
@@ -96,7 +95,7 @@ module Puppet
# We can't depend on looking this up right now,
# we have to do it after all of the objects
# have been instantiated.
- if @resource.configuration and bucketobj = @resource.configuration.resource(:filebucket, value)
+ if bucketobj = Puppet::Type.type(:filebucket)[value]
@resource.bucket = bucketobj.bucket
bucketobj.title
else
@@ -254,6 +253,11 @@ module Puppet
end
end
+ def self.[](path)
+ return nil unless path
+ super(path.gsub(/\/+/, '/').sub(/\/$/, ''))
+ end
+
# List files, but only one level deep.
def self.instances(base = "/")
unless FileTest.directory?(base)
@@ -309,32 +313,31 @@ module Puppet
# a couple of these buckets
@@filebuckets ||= {}
- super
-
# Look up our bucket, if there is one
- return unless bucket_name = self.bucket
-
- return if bucket_name.is_a?(Puppet::Network::Client.dipper)
-
- self.fail("Invalid bucket type %s" % bucket_name.class) unless bucket_name.is_a?(String)
-
- return self.bucket = bucket if bucket = @@filebuckets[bucket_name]
-
- if configuration and bucket_resource = configuration.resource(:filebucket, bucket_name)
- @@filebuckets[bucket_name] = bucket_resource.bucket
- self.bucket = bucket
- return
- end
-
- if bucket_name == "puppet"
- puts "Creating default bucket"
- bucket_resource = Puppet::Type.type(:filebucket).create_default_resources
- self.bucket = bucket_resource.bucket
- configuration.add_resource(bucket_resource) if configuration
- @@filebuckets[bucket_name] = bucket
- else
- self.fail "Could not find filebucket '%s'" % bucket_name
+ if bucket = self.bucket
+ case bucket
+ when String:
+ if obj = @@filebuckets[bucket]
+ # This sets the @value on :backup, too
+ self.bucket = obj
+ elsif bucket == "puppet"
+ obj = Puppet::Network::Client.client(:Dipper).new(
+ :Path => Puppet[:clientbucketdir]
+ )
+ self.bucket = obj
+ @@filebuckets[bucket] = obj
+ elsif obj = Puppet::Type.type(:filebucket).bucket(bucket)
+ @@filebuckets[bucket] = obj
+ self.bucket = obj
+ else
+ self.fail "Could not find filebucket %s" % bucket
+ end
+ when Puppet::Network::Client.client(:Dipper): # things are hunky-dorey
+ else
+ self.fail "Invalid bucket type %s" % bucket.class
+ end
end
+ super
end
# Create any children via recursion or whatever.
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index 27fea6ac8..cf4e5aac3 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -53,11 +53,22 @@ module Puppet
defaultto { Puppet[:clientbucketdir] }
end
+
+ # get the actual filebucket object
+ def self.bucket(name)
+ if object = self[name]
+ return object.bucket
+ else
+ return nil
+ end
+ end
# Create a default filebucket.
- def self.create_default_resources
- Puppet.debug "Creating default local filebucket"
- [self.create(:name => "puppet", :path => Puppet[:clientbucketdir])]
+ def self.mkdefaultbucket
+ unless default = self["puppet"]
+ default = self.create :name => "puppet", :path => Puppet[:clientbucketdir]
+ end
+ default
end
def self.instances
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index 3f4014cd8..46cff10f5 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -311,27 +311,30 @@ module Puppet
[]
end
- def self.create_default_resources
- Puppet.debug "Creating default schedules"
- resources = []
+ def self.mkdefaultschedules
# Create our default schedule
- resources << self.create(
- :name => "puppet",
- :period => :hourly,
- :repeat => "2"
- )
+ unless self["puppet"]
+ Puppet.debug "Creating default schedules"
+ self.create(
+ :name => "puppet",
+ :period => :hourly,
+ :repeat => "2"
+ )
+ end
# And then one for every period
@parameters.find { |p| p.name == :period }.values.each { |value|
- resources << self.create(
- :name => value.to_s,
- :period => value
- )
+ unless self[value.to_s]
+ self.create(
+ :name => value.to_s,
+ :period => value
+ )
+ end
}
- resources
end
def match?(previous = nil, now = nil)
+
# If we've got a value, then convert it to a Time instance
if previous
previous = Time.at(previous)
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index b1b2c1d96..2f1dabe62 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -74,7 +74,7 @@ class Puppet::Util::FileType
# Pick or create a filebucket to use.
def bucket
- Puppet::Type.type(:filebucket).create_default_resources[0].bucket
+ Puppet::Type.type(:filebucket).mkdefaultbucket.bucket
end
def initialize(path)