summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-22 15:04:34 -0500
committerLuke Kanies <luke@madstop.com>2007-09-22 15:04:34 -0500
commitd6e91ae78698bdbec818d383574f4c279735e172 (patch)
tree7072c2a71ef1c05c6a46b6050f52bf3d01ae2843 /lib/puppet/util
parenta66699596452f88d2bc467af4cff3f9a1aec3d1e (diff)
parent86dde63473d29c45d8698ce4edd53c820a621362 (diff)
downloadpuppet-d6e91ae78698bdbec818d383574f4c279735e172.tar.gz
puppet-d6e91ae78698bdbec818d383574f4c279735e172.tar.xz
puppet-d6e91ae78698bdbec818d383574f4c279735e172.zip
Merge branch 'configurations' into indirection
Conflicts: lib/puppet/defaults.rb lib/puppet/indirector/facts/yaml.rb spec/unit/indirector/indirection.rb spec/unit/indirector/indirector.rb
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/config.rb197
-rw-r--r--lib/puppet/util/storage.rb2
2 files changed, 99 insertions, 100 deletions
diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb
index 9cdb4cfe3..4b6ae9e5b 100644
--- a/lib/puppet/util/config.rb
+++ b/lib/puppet/util/config.rb
@@ -69,14 +69,14 @@ class Puppet::Util::Config
return options
end
- # Turn the config into a transaction and apply it
+ # Turn the config into a Puppet configuration and apply it
def apply
trans = self.to_transportable
begin
- comp = trans.to_type
- trans = comp.evaluate
- trans.evaluate
- comp.remove
+ config = trans.to_configuration
+ config.store_state = false
+ config.apply
+ config.clear
rescue => detail
if Puppet[:trace]
puts detail.backtrace
@@ -476,57 +476,15 @@ class Puppet::Util::Config
end
# Convert a single section into transportable objects.
- def section_to_transportable(section, done = nil, includefiles = true)
+ def section_to_transportable(section, done = nil)
done ||= Hash.new { |hash, key| hash[key] = {} }
objects = []
persection(section) do |obj|
if @config[:mkusers] and value(:mkusers)
- [:owner, :group].each do |attr|
- type = nil
- if attr == :owner
- type = :user
- else
- type = attr
- end
- # If a user and/or group is set, then make sure we're
- # managing that object
- if obj.respond_to? attr and name = obj.send(attr)
- # Skip root or wheel
- next if %w{root wheel}.include?(name.to_s)
-
- # Skip owners and groups we've already done, but tag
- # them with our section if necessary
- if done[type].include?(name)
- tags = done[type][name].tags
- unless tags.include?(section)
- done[type][name].tags = tags << section
- end
- elsif newobj = Puppet::Type.type(type)[name]
- unless newobj.property(:ensure)
- newobj[:ensure] = "present"
- end
- newobj.tag(section)
- if type == :user
- newobj[:comment] ||= "%s user" % name
- end
- else
- newobj = Puppet::TransObject.new(name, type.to_s)
- newobj.tags = ["puppet", "configuration", section]
- newobj[:ensure] = "present"
- if type == :user
- newobj[:comment] ||= "%s user" % name
- end
- # Set the group appropriately for the user
- if type == :user
- newobj[:gid] = Puppet[:group]
- end
- done[type][name] = newobj
- objects << newobj
- end
- end
- end
+ objects += add_user_resources(section, obj, done)
end
+ # Only files are convertable to transportable resources.
if obj.respond_to? :to_transportable
next if value(obj.name) =~ /^\/dev/
transobjects = obj.to_transportable
@@ -544,7 +502,8 @@ class Puppet::Util::Config
end
bucket = Puppet::TransBucket.new
- bucket.type = section
+ bucket.type = "Configuration"
+ bucket.name = section
bucket.push(*objects)
bucket.keyword = "class"
@@ -596,9 +555,9 @@ class Puppet::Util::Config
end
# Convert our list of objects into a component that can be applied.
- def to_component
+ def to_configuration
transport = self.to_transportable
- return transport.to_type
+ return transport.to_configuration
end
# Convert our list of objects into a configuration file.
@@ -634,7 +593,7 @@ Generated on #{Time.now}.
end
# Convert our configuration into a list of transportable objects.
- def to_transportable
+ def to_transportable(*sections)
done = Hash.new { |hash, key|
hash[key] = {}
}
@@ -643,14 +602,20 @@ Generated on #{Time.now}.
if defined? @file.file and @file.file
topbucket.name = @file.file
else
- topbucket.name = "configtop"
+ topbucket.name = "top"
end
- topbucket.type = "puppetconfig"
+ topbucket.type = "Configuration"
topbucket.top = true
# Now iterate over each section
- eachsection do |section|
- topbucket.push section_to_transportable(section, done)
+ if sections.empty?
+ eachsection do |section|
+ sections << section
+ end
+ end
+ sections.each do |section|
+ obj = section_to_transportable(section, done)
+ topbucket.push obj
end
topbucket
@@ -683,37 +648,31 @@ Generated on #{Time.now}.
}
return if runners.empty?
- bucket = Puppet::TransBucket.new
- bucket.type = "puppetconfig"
- bucket.top = true
-
- # Create a hash to keep track of what we've done so far.
- @done = Hash.new { |hash, key| hash[key] = {} }
- runners.each do |section|
- bucket.push section_to_transportable(section, @done, false)
- end
-
- objects = bucket.to_type
-
- objects.finalize
- tags = nil
- if Puppet[:tags]
- tags = Puppet[:tags]
- Puppet[:tags] = ""
- end
- trans = objects.evaluate
- trans.ignoretags = true
- trans.configurator = true
- trans.evaluate
- if tags
- Puppet[:tags] = tags
- end
-
- # Remove is a recursive process, so it's sufficient to just call
- # it on the component.
- objects.remove(true)
-
- objects = nil
+ bucket = to_transportable(*sections)
+
+ config = bucket.to_configuration
+ config.host_config = false
+ config.apply
+ config.clear
+
+# tags = nil
+# if Puppet[:tags]
+# tags = Puppet[:tags]
+# Puppet[:tags] = ""
+# end
+# trans = objects.evaluate
+# trans.ignoretags = true
+# trans.configurator = true
+# trans.evaluate
+# if tags
+# Puppet[:tags] = tags
+# end
+#
+# # Remove is a recursive process, so it's sufficient to just call
+# # it on the component.
+# objects.remove(true)
+#
+# objects = nil
runners.each { |s| @used << s }
end
@@ -845,6 +804,48 @@ Generated on #{Time.now}.
private
+ # Create the transportable objects for users and groups.
+ def add_user_resources(section, obj, done)
+ resources = []
+ [:owner, :group].each do |attr|
+ type = nil
+ if attr == :owner
+ type = :user
+ else
+ type = attr
+ end
+ # If a user and/or group is set, then make sure we're
+ # managing that object
+ if obj.respond_to? attr and name = obj.send(attr)
+ # Skip root or wheel
+ next if %w{root wheel}.include?(name.to_s)
+
+ # Skip owners and groups we've already done, but tag
+ # them with our section if necessary
+ if done[type].include?(name)
+ tags = done[type][name].tags
+ unless tags.include?(section)
+ done[type][name].tags = tags << section
+ end
+ else
+ newobj = Puppet::TransObject.new(name, type.to_s)
+ newobj.tags = ["puppet", "configuration", section]
+ newobj[:ensure] = :present
+ if type == :user
+ newobj[:comment] ||= "%s user" % name
+ end
+ # Set the group appropriately for the user
+ if type == :user
+ newobj[:gid] = Puppet[:group]
+ end
+ done[type][name] = newobj
+ resources << newobj
+ end
+ end
+ end
+ resources
+ end
+
# Extract extra setting information for files.
def extract_fileinfo(string)
result = {}
@@ -1105,6 +1106,11 @@ Generated on #{Time.now}.
# Set the type appropriately. Yep, a hack. This supports either naming
# the variable 'dir', or adding a slash at the end.
def munge(value)
+ # If it's not a fully qualified path...
+ if value.is_a?(String) and value !~ /^\$/ and value !~ /^\//
+ # Make it one
+ value = File.join(Dir.getwd, value)
+ end
if value.to_s =~ /\/$/
@type = :directory
return value.sub(/\/$/, '')
@@ -1127,9 +1133,6 @@ Generated on #{Time.now}.
end
# Convert the object to a TransObject instance.
- # FIXME There's no dependency system in place right now; if you use
- # a section that requires another section, there's nothing done to
- # correct that for you, at the moment.
def to_transportable
type = self.type
return nil unless type
@@ -1138,9 +1141,9 @@ Generated on #{Time.now}.
objects = []
path = self.value
- unless path =~ /^#{File::SEPARATOR}/
- path = File.join(Dir.getwd, path)
- end
+
+ # Skip plain files that don't exist, since we won't be managing them anyway.
+ return nil unless self.name.to_s =~ /dir$/ or File.exist?(path) or self.create
obj = Puppet::TransObject.new(path, "file")
# Only create directories, or files that are specifically marked to
@@ -1157,7 +1160,7 @@ Generated on #{Time.now}.
}
# Only chown or chgrp when root
- if Puppet::Util::SUIDManager.uid == 0
+ if Puppet.features.root?
[:group, :owner].each { |var|
if value = self.send(var)
obj[var] = value
@@ -1218,5 +1221,3 @@ Generated on #{Time.now}.
end
end
end
-
-# $Id$
diff --git a/lib/puppet/util/storage.rb b/lib/puppet/util/storage.rb
index a10183615..cd41aa572 100644
--- a/lib/puppet/util/storage.rb
+++ b/lib/puppet/util/storage.rb
@@ -99,5 +99,3 @@ class Puppet::Util::Storage
end
end
end
-
-# $Id$