summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/metatype/container.rb1
-rw-r--r--lib/puppet/metatype/instances.rb36
-rw-r--r--lib/puppet/metatype/metaparams.rb1
-rw-r--r--lib/puppet/metatype/relationships.rb4
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb7
-rw-r--r--lib/puppet/node/catalog.rb2
-rw-r--r--lib/puppet/resource_reference.rb11
-rw-r--r--lib/puppet/type.rb6
-rw-r--r--lib/puppet/type/component.rb4
-rw-r--r--lib/puppet/type/pfile.rb35
-rwxr-xr-xlib/puppet/type/pfilebucket.rb14
-rwxr-xr-xlib/puppet/type/schedule.rb12
-rwxr-xr-xlib/puppet/util/filetype.rb6
13 files changed, 40 insertions, 99 deletions
diff --git a/lib/puppet/metatype/container.rb b/lib/puppet/metatype/container.rb
index 2bbe3f546..dbc8a3dee 100644
--- a/lib/puppet/metatype/container.rb
+++ b/lib/puppet/metatype/container.rb
@@ -36,7 +36,6 @@ class Puppet::Type
obj.remove
end
@parameters.clear
- self.class.delete(self)
@parent = nil
diff --git a/lib/puppet/metatype/instances.rb b/lib/puppet/metatype/instances.rb
index 3f44413f8..9d4fce909 100644
--- a/lib/puppet/metatype/instances.rb
+++ b/lib/puppet/metatype/instances.rb
@@ -8,11 +8,13 @@ class Puppet::Type
# retrieve a named instance of the current type
def self.[](name)
+ raise "Global resource access is deprecated"
@objects[name] || @aliases[name]
end
# add an instance by name to the class list of instances
def self.[]=(name,object)
+ raise "Global resource storage is deprecated"
newobj = nil
if object.is_a?(Puppet::Type)
newobj = object
@@ -126,24 +128,6 @@ class Puppet::Type
# XXX This will have to change when transobjects change to using titles
title = hash.name
- # 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
- raise Puppet::Error, "%s is already being managed" % retobj.ref
- end
- end
-
# create it anew
# if there's a failure, destroy the object if it got that far, but raise
# the error.
@@ -153,8 +137,6 @@ 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
@@ -163,9 +145,6 @@ class Puppet::Type
obj.implicit = true
end
- # Store the object by title
- self[obj.title] = obj
-
return obj
end
@@ -258,10 +237,6 @@ class Puppet::Type
provider_instances = {}
providers_by_source.collect do |provider|
provider.instances.collect do |instance|
- # First try to get the resource if it already exists
- # Skip instances that map to a managed resource with a different provider
- next if resource = self[instance.name] and resource.provider.class != instance.class
-
# We always want to use the "first" provider instance we find, unless the resource
# is already managed and has a different provider set
if other = provider_instances[instance.name]
@@ -271,12 +246,7 @@ class Puppet::Type
end
provider_instances[instance.name] = instance
- if resource
- resource.provider = instance
- resource
- else
- create(:name => instance.name, :provider => instance, :check => :all)
- end
+ create(:name => instance.name, :provider => instance, :check => :all)
end
end.flatten.compact
end
diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb
index b35adae66..b0a4cfce5 100644
--- a/lib/puppet/metatype/metaparams.rb
+++ b/lib/puppet/metatype/metaparams.rb
@@ -277,6 +277,7 @@ class Puppet::Type
# to an object...
tname, name = value
reference = Puppet::ResourceReference.new(tname, name)
+ reference.catalog = resource.catalog
# 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 4fb78ae56..3433c4884 100644
--- a/lib/puppet/metatype/relationships.rb
+++ b/lib/puppet/metatype/relationships.rb
@@ -18,6 +18,8 @@ class Puppet::Type
# Figure out of there are any objects we can automatically add as
# dependencies.
def autorequire
+ raise(Puppet::DevError, "You cannot add relationships without a catalog") unless catalog
+
reqs = []
self.class.eachautorequire { |type, block|
# Ignore any types we can't find, although that would be a bit odd.
@@ -35,7 +37,7 @@ class Puppet::Type
# Support them passing objects directly, to save some effort.
unless dep.is_a? Puppet::Type
# Skip autorequires that we aren't managing
- unless dep = typeobj[dep]
+ unless dep = catalog.resource(type, dep)
next
end
end
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index e6378bf01..3ee4721f3 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -568,12 +568,14 @@ class Puppet::Network::Handler
@path = nil
end
+ @files = {}
+
super()
end
def fileobj(path, links, client)
obj = nil
- if obj = Puppet.type(:file)[file_path(path, client)]
+ if obj = @files[file_path(path, client)]
# 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
@@ -584,6 +586,7 @@ class Puppet::Network::Handler
:name => file_path(path, client),
:check => CHECKPARAMS
)
+ @files[file_path(path, client)] = obj
end
if links == :manage
@@ -600,7 +603,7 @@ class Puppet::Network::Handler
# Read the contents of the file at the relative path given.
def read_file(relpath, client)
- File.read(file_path(relpath, client))
+ File.read(file_path(relpath, client))
end
# Cache this manufactured map, since if it's used it's likely
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb
index 9601309d8..0dcfbaefc 100644
--- a/lib/puppet/node/catalog.rb
+++ b/lib/puppet/node/catalog.rb
@@ -293,7 +293,7 @@ class Puppet::Node::Catalog < Puppet::PGraph
# And filebuckets
if bucket = Puppet::Type.type(:filebucket).mkdefaultbucket
- add_resource(bucket)
+ add_resource(bucket) unless resource(bucket.ref)
end
end
diff --git a/lib/puppet/resource_reference.rb b/lib/puppet/resource_reference.rb
index 3e92662b2..8af17918a 100644
--- a/lib/puppet/resource_reference.rb
+++ b/lib/puppet/resource_reference.rb
@@ -22,15 +22,8 @@ class Puppet::ResourceReference
# Find our resource.
def resolve
- if catalog
- return catalog.resource(to_s)
- end
- # If it's builtin, then just ask for it directly from the type.
- if t = builtin_type
- t[@title]
- else # Else, look for a component with the full reference as the name.
- Puppet::Type::Component[to_s]
- end
+ return catalog.resource(to_s) if catalog
+ return nil
end
# If the title has square brackets, treat it like a reference and
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index def9e44e4..c7a6f4e40 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -231,14 +231,14 @@ class Type
end
# If the name and title differ, set up an alias
- if self.name != self.title
- if obj = self.class[self.name]
+ if self.name != self.title and self.catalog
+ if obj = catalog.resource(self.class.name, 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)
+ catalog.alias(self, self.name)
end
end
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index 356205089..1d1bc9ee8 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -88,8 +88,8 @@ Puppet::Type.newtype(:component) do
@reference = Puppet::ResourceReference.new(:component, @title)
- unless self.class[@reference.to_s]
- self.class.alias(@reference.to_s, self)
+ if catalog and ! catalog.resource[@reference.to_s]
+ catalog.alias(self, @reference.to_s)
end
end
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 7d928d959..c8e63b5ba 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -76,9 +76,8 @@ module Puppet
munge do |value|
# I don't really know how this is happening.
- if value.is_a?(Array)
- value = value.shift
- end
+ value = value.shift if value.is_a?(Array)
+
case value
when false, "false", :false:
false
@@ -90,7 +89,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 bucketobj = Puppet::Type.type(:filebucket)[value]
+ if resource.catalog and bucketobj = resource.catalog.resource(:filebucket, value)
@resource.bucket = bucketobj.bucket
bucketobj.title
else
@@ -304,30 +303,23 @@ module Puppet
# We have to do some extra finishing, to retrieve our bucket if
# there is one.
def finish
- # Let's cache these values, since there should really only be
- # a couple of these buckets
- @@filebuckets ||= {}
-
# Look up our bucket, if there is one
if bucket = self.bucket
case bucket
when String:
- if obj = @@filebuckets[bucket]
- # This sets the @value on :backup, too
- self.bucket = obj
+ if catalog and obj = catalog.resource(:filebucket, bucket)
+ self.bucket = obj.bucket
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
+ self.fail "Could not find filebucket '%s'" % bucket
end
when Puppet::Network::Client.client(:Dipper): # things are hunky-dorey
+ when Puppet::Type::Filebucket # things are hunky-dorey
+ self.bucket = bucket.bucket
else
self.fail "Invalid bucket type %s" % bucket.class
end
@@ -432,8 +424,7 @@ module Puppet
end
when "link": return true
else
- self.notice "Cannot backup files of type %s" %
- File.stat(file).ftype
+ self.notice "Cannot backup files of type %s" % File.stat(file).ftype
return false
end
end
@@ -783,13 +774,9 @@ module Puppet
def remove_existing(should)
return unless s = stat(true)
- unless handlebackup
- self.fail "Could not back up; will not replace"
- end
+ self.fail "Could not back up; will not replace" unless handlebackup
- unless should.to_s == "link"
- return if s.ftype.to_s == should.to_s
- end
+ return if s.ftype.to_s == should.to_s unless should.to_s == "link"
case s.ftype
when "directory":
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index b268610e9..872bded4e 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -54,21 +54,9 @@ 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.mkdefaultbucket
- unless default = self["puppet"]
- return self.create(:name => "puppet", :path => Puppet[:clientbucketdir])
- end
- return nil
+ self.create(:name => "puppet", :path => Puppet[:clientbucketdir])
end
def self.instances
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index c494c5d94..ecbf7d49a 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -316,8 +316,6 @@ module Puppet
end
def self.mkdefaultschedules
- return [] if self["puppet"]
-
result = []
Puppet.debug "Creating default schedules"
result << self.create(
@@ -328,12 +326,10 @@ module Puppet
# And then one for every period
@parameters.find { |p| p.name == :period }.values.each { |value|
- unless self[value.to_s]
- result << self.create(
- :name => value.to_s,
- :period => value
- )
- end
+ result << self.create(
+ :name => value.to_s,
+ :period => value
+ )
}
result
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index 1c7734cc4..cddfc4689 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -74,8 +74,10 @@ class Puppet::Util::FileType
# Pick or create a filebucket to use.
def bucket
- filebucket = Puppet::Type.type(:filebucket)
- (filebucket["puppet"] || filebucket.mkdefaultbucket).bucket
+ unless defined?(@bucket)
+ @bucket = Puppet::Type.type(:filebucket).mkdefaultbucket.bucket
+ end
+ @bucket
end
def initialize(path)