summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/metatype/relationships.rb12
-rw-r--r--lib/puppet/metatype/schedules.rb4
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb7
-rwxr-xr-xlib/puppet/network/handler/resource.rb31
-rw-r--r--lib/puppet/node/configuration.rb16
-rw-r--r--lib/puppet/type.rb12
-rw-r--r--lib/puppet/type/pfile.rb60
-rwxr-xr-xlib/puppet/type/pfilebucket.rb11
-rwxr-xr-xlib/puppet/type/schedule.rb4
-rwxr-xr-xlib/puppet/util/filetype.rb2
10 files changed, 72 insertions, 87 deletions
diff --git a/lib/puppet/metatype/relationships.rb b/lib/puppet/metatype/relationships.rb
index 332702a25..2a5341e5e 100644
--- a/lib/puppet/metatype/relationships.rb
+++ b/lib/puppet/metatype/relationships.rb
@@ -29,16 +29,16 @@ class Puppet::Type
# Collect the current prereqs
list.each { |dep|
- obj = nil
# Support them passing objects directly, to save some effort.
- unless dep.is_a? Puppet::Type
+ if dep.is_a?(Puppet::Type)
+ next unless configuration.resource(type, dep.title)
+ resource = dep
+ else
# Skip autorequires that we aren't managing
- unless dep = configuration.resource(type, dep)
- next
- end
+ next unless resource = configuration.resource(type, dep)
end
- reqs << Puppet::Relationship.new(dep, self)
+ reqs << Puppet::Relationship.new(resource, self)
}
}
diff --git a/lib/puppet/metatype/schedules.rb b/lib/puppet/metatype/schedules.rb
index 96ebce0ab..4d4f93764 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]
- if sched = Puppet.type(:schedule)[name]
+ if name = self[:schedule] and self.configuration
+ if sched = configuration.resource(:schedule, name)
@schedule = sched
else
self.fail "Could not find schedule %s" % name
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index dd00450be..7a5a1fe9a 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -551,22 +551,25 @@ class Puppet::Network::Handler
@path = nil
end
+ @cache = {}
+
super()
end
def fileobj(path, links)
obj = nil
- if obj = Puppet.type(:file)[path]
+ if obj = @cache[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(:file).create(
+ obj = Puppet::Type.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 0fcd694fb..c96bdf6a6 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 object. This returns the 'is' values for every property
- # available on the object type.
+ # Describe a given resource. This returns the 'is' values for every property
+ # available on the resource 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,29 +63,23 @@ class Puppet::Network::Handler
raise Puppet::Error, "Puppet type %s is unsupported" % type
end
- obj = nil
-
retrieve ||= :all
ignore ||= []
- 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
+ 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]
end
- unless obj
+ unless resource
raise XMLRPC::FaultException.new(
1, "Could not create %s[%s]" % [type, name]
)
end
- trans = obj.to_trans
+ trans = resource.to_trans
# Now get rid of any attributes they specifically don't want
ignore.each do |st|
@@ -138,11 +132,10 @@ class Puppet::Network::Handler
bucket = Puppet::TransBucket.new
bucket.type = typeklass.name
- typeklass.instances.each do |obj|
- next if ignore.include? obj.name
+ typeklass.instances.each do |resource|
+ next if ignore.include? resource.name
- #object = Puppet::TransObject.new(obj.name, typeklass.name)
- bucket << obj.to_trans
+ bucket << resource.to_trans
end
unless @local
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index 061e83f4b..e131839df 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -60,11 +60,22 @@ 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
@@ -183,6 +194,11 @@ 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?
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 02e04653c..3f69bc8b1 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -228,18 +228,6 @@ class Type
self.devfail "I was not passed a namevar"
end
- # If the name and title differ, set up an alias
- if self.configuration and (self.name != self.title)
- if obj = self.configuration.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.configuration.alias(self, self.name)
- end
- end
-
if hash.include?(:provider)
self[:provider] = hash[:provider]
hash.delete(:provider)
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 723fecde2..d6dfd86e0 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -73,10 +73,8 @@ module Puppet
"
defaultto do
- if resource.configuration
- # Make sure the default file bucket exists.
- obj = resource.configuration.resource(:filebucket, "puppet") || resource.configuration.create_resource(:filebucket, :name => "puppet")
- obj.bucket
+ if resource.configuration and bucket_resource = resource.configuration.resource(:filebucket, "puppet")
+ bucket_resource.bucket
else
nil
end
@@ -98,7 +96,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.configuration and bucketobj = @resource.configuration.resource(:filebucket, value)
@resource.bucket = bucketobj.bucket
bucketobj.title
else
@@ -256,11 +254,6 @@ 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)
@@ -316,31 +309,32 @@ module Puppet
# a couple of these buckets
@@filebuckets ||= {}
+ super
+
# 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
- 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
+ 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
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 5ce81858b..27fea6ac8 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -53,20 +53,11 @@ 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]
+ [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 72d649584..3f4014cd8 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -311,7 +311,7 @@ module Puppet
[]
end
- def self.create_default_schedules
+ def self.create_default_resources
Puppet.debug "Creating default schedules"
resources = []
# Create our default schedule
@@ -323,7 +323,7 @@ module Puppet
# And then one for every period
@parameters.find { |p| p.name == :period }.values.each { |value|
- resources << self.create(:schedule,
+ resources << self.create(
:name => value.to_s,
:period => value
)
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index 2f1dabe62..b1b2c1d96 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).mkdefaultbucket.bucket
+ Puppet::Type.type(:filebucket).create_default_resources[0].bucket
end
def initialize(path)