[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. 5ed1ad6cbc31ad07f131a86117bc4150fedf0e61
Micah Anderson
micah at riseup.net
Tue Mar 25 22:15:57 UTC 2008
The following commit has been merged in the master branch:
commit 5ed1ad6cbc31ad07f131a86117bc4150fedf0e61
Author: Micah Anderson <micah at riseup.net>
Date: Tue Mar 25 18:12:33 2008 -0400
fix pieces missing from previous merge
also add bin/pi to be installed
diff --git a/bin/pi b/bin/pi
new file mode 100755
index 0000000..5416e69
--- /dev/null
+++ b/bin/pi
@@ -0,0 +1,234 @@
+#!/usr/bin/ruby
+
+#
+# = Synopsis
+#
+# Print help about puppet types on the console. Run with '-h' to get detailed
+# help.
+#
+
+# FIXME: (1) Formatting could be a lot prettier
+# (2) The command line options are kinda screwy; unclear how best to
+# present the various pieces of info to user
+
+require 'puppet'
+require 'optparse'
+
+class Formatter
+
+ def initialize(width)
+ @width = width
+ end
+
+ def wrap(txt, opts)
+ return "" unless txt && !txt.empty?
+ work = (opts[:scrub] ? scrub(txt) : txt)
+ indent = (opts[:indent] ? opts[:indent] : 0)
+ textLen = @width - indent
+ patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
+ prefix = " " * indent
+
+ res = []
+
+ while work.length > textLen
+ if work =~ patt
+ res << $1
+ work.slice!(0, $&.length)
+ else
+ res << work.slice!(0, textLen)
+ end
+ end
+ res << work if work.length.nonzero?
+ return prefix + res.join("\n" + prefix)
+ end
+
+ def header(txt, sep = "-")
+ "\n#{txt}\n" + sep * txt.size
+ end
+
+ private
+
+ def scrub(text)
+ # For text with no carriage returns, there's nothing to do.
+ if text !~ /\n/
+ return text
+ end
+ indent = nil
+
+ # If we can match an indentation, then just remove that same level of
+ # indent from every line.
+ if text =~ /^(\s+)/
+ indent = $1
+ return text.gsub(/^#{indent}/,'')
+ else
+ return text
+ end
+ end
+
+end
+
+class TypeDoc
+
+ def initialize
+ @format = Formatter.new(76)
+ @types = {}
+ Puppet::Type.loadall
+ Puppet::Type.eachtype { |type|
+ next if type.name == :component
+ @types[type.name] = type
+ }
+ end
+
+ def list_types
+ puts "These are the types known to puppet:\n"
+ @types.keys.sort { |a, b|
+ a.to_s <=> b.to_s
+ }.each do |name|
+ type = @types[name]
+ s = type.doc.gsub(/\s+/, " ")
+ n = s.index(".")
+ if n.nil?
+ s = ".. no documentation .."
+ elsif n > 45
+ s = s[0, 45] + " ..."
+ else
+ s = s[0, n]
+ end
+ printf "%-15s - %s\n", name, s
+ end
+ end
+
+ def format_type(name, opts)
+ name = name.to_sym
+ unless @types.has_key?(name)
+ puts "Unknown type #{name}"
+ return
+ end
+ type = @types[name]
+ puts @format.header(name.to_s, "=")
+ puts @format.wrap(type.doc, :indent => 0, :scrub => true) + "\n\n"
+
+ puts @format.header("Parameters")
+ if opts[:parameters]
+ format_attrs(type, [:property, :param])
+ else
+ list_attrs(type, [:property, :param])
+ end
+
+ if opts[:metaparams]
+ puts @format.header("Meta Parameters")
+ if opts[:parameters]
+ format_attrs(type, [:meta])
+ else
+ list_attrs(type, [:meta])
+ end
+ end
+
+ if type.providers.size > 0
+ puts @format.header("Providers")
+ if opts[:providers]
+ format_providers(type)
+ else
+ list_providers(type)
+ end
+ end
+ end
+
+ # List details about attributes
+ def format_attrs(type, attrs)
+ docs = {}
+ type.eachattr do |obj, kind|
+ if attrs.include?(kind) && obj.name != :provider
+ docs[obj.name] = obj.doc
+ end
+ end
+
+ docs.sort { |a,b|
+ a[0].to_s <=> b[0].to_s
+ }.each { |name, doc|
+ print "\n- **%s**" % name
+ if type.namevar == name and name != :name
+ puts " (*namevar*)"
+ else
+ puts ""
+ end
+ puts @format.wrap(doc, :indent => 4, :scrub => true)
+ }
+ end
+
+ # List the names of attributes
+ def list_attrs(type, attrs)
+ params = []
+ type.eachattr do |obj, kind|
+ if attrs.include?(kind) && obj.name != :provider
+ params << obj.name.to_s
+ end
+ end
+ puts @format.wrap(params.sort.join(", "), :indent => 4)
+ end
+
+ def format_providers(type)
+ type.providers.sort { |a,b|
+ a.to_s <=> b.to_s
+ }.each { |prov|
+ puts "\n- **%s**" % prov
+ puts @format.wrap(type.provider(prov).doc,
+ :indent => 4, :scrub => true)
+ }
+ end
+
+ def list_providers(type)
+ list = type.providers.sort { |a,b|
+ a.to_s <=> b.to_s
+ }.join(", ")
+ puts @format.wrap(list, :indent => 4)
+ end
+
+end
+
+def process_args
+ result = {
+ :list => false,
+ :providers => false,
+ :parameters => true,
+ :metaparams => false
+ }
+ opts = OptionParser.new("#{$0} [options] [type]")
+ opts.separator(" Print documentation for puppet types and their parameters")
+ opts.on("-l", "--list", "List all types") do |val|
+ result[:list] = true
+ end
+ opts.on("-p", "--providers",
+ "Describe providers in detail") do |val|
+ result[:providers] = true
+ end
+ opts.on("-s", "--short",
+ "Only list parameters without detail") do |val|
+ result[:parameters] = false
+ end
+ opts.on("-m", "--meta",
+ "Include metaparams") do |val|
+ result[:metaparams] = true
+ end
+ result[:types] = opts.order(ARGV)
+ # Check for obviously bogus options
+ unless result[:list] || result[:types].size > 0
+ $stderr.puts opts
+ exit(1)
+ end
+ if result[:list] && result[:types].size > 0
+ $stderr.puts "Warning: ignoring types when listing all types"
+ end
+
+ return result
+end
+
+opts = process_args
+
+doc = TypeDoc.new
+
+if opts[:list]
+ doc.list_types
+else
+ opts[:types].each { |name| doc.format_type(name, opts) }
+end
diff --git a/bin/puppetd b/bin/puppetd
index e993d3a..f652e6b 100755
--- a/bin/puppetd
+++ b/bin/puppetd
@@ -188,6 +188,8 @@ args = {}
options = {
:waitforcert => 120, # Default to checking for certs every 5 minutes
:onetime => false,
+ :verbose => false,
+ :debug => false,
:centrallogs => false,
:setdest => false,
:enable => false,
@@ -228,11 +230,9 @@ begin
puts "%s" % Puppet.version
exit
when "--verbose"
- Puppet::Util::Log.level = :info
- Puppet::Util::Log.newdestination(:console)
+ options[:verbose] = true
when "--debug"
- Puppet::Util::Log.level = :debug
- Puppet::Util::Log.newdestination(:console)
+ options[:debug] = true
when "--fqdn"
options[:fqdn] = arg
when "--no-client"
@@ -247,6 +247,9 @@ begin
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
+ if Puppet[:debug]
+ puts detail.backtrace
+ end
$stderr.puts detail.to_s
end
when "--waitforcert"
@@ -272,12 +275,23 @@ if options[:test]
Puppet.settings.handlearg("--no-splay")
Puppet.settings.handlearg("--show_diff")
Puppet.settings.handlearg("--no-daemonize")
+ options[:verbose] = true
options[:onetime] = true
options[:waitforcert] = 0
- unless Puppet::Util::Log.level == :debug
+end
+
+# Handle the logging settings.
+if options[:debug] or options[:verbose]
+ Puppet::Util::Log.newdestination(:console)
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ else
Puppet::Util::Log.level = :info
end
- Puppet::Util::Log.newdestination(:console)
+end
+
+unless options[:setdest]
+ Puppet::Util::Log.newdestination(:syslog)
end
Puppet.genconfig
@@ -288,10 +302,6 @@ if Puppet[:noop]
Puppet[:show_diff] = true
end
-unless options[:setdest]
- Puppet::Util::Log.newdestination(:syslog)
-end
-
args[:Server] = Puppet[:server]
if options[:fqdn]
args[:FQDN] = options[:fqdn]
diff --git a/bin/puppetmasterd b/bin/puppetmasterd
index 33e4f43..b4733e6 100755
--- a/bin/puppetmasterd
+++ b/bin/puppetmasterd
@@ -188,6 +188,9 @@ Puppet.genmanifest
# A temporary solution, to at least make the master work for now.
Puppet::Node::Facts.terminus_class = :yaml
+# Cache our nodes in yaml. Currently not configurable.
+Puppet::Node.cache_class = :yaml
+
require 'etc'
handlers = {
diff --git a/debian/puppet.files b/debian/puppet.files
index d92ac32..4cf8567 100644
--- a/debian/puppet.files
+++ b/debian/puppet.files
@@ -1,5 +1,6 @@
usr/bin/puppet
usr/bin/puppetdoc
+usr/bin/pi
usr/sbin/puppetd
usr/lib/ruby/1.8/
var/log/puppet
diff --git a/debian/rules b/debian/rules
index 851eefd..27f2279 100755
--- a/debian/rules
+++ b/debian/rules
@@ -56,7 +56,7 @@ install: build
install -d -m0755 $(localstatedir)/run
install -d -m0755 $(localstatedir)/log/puppet
- $(INSTALL) -m0755 bin/puppet bin/puppetdoc $(bindir)
+ $(INSTALL) -m0755 bin/puppet bin/puppetdoc bin/pi $(bindir)
$(INSTALL) -m0755 bin/puppetd bin/puppetmasterd bin/puppetca bin/puppetrun $(sbindir)
$(INSTALL) -m0644 lib/puppet.rb $(rubylibdir)/puppet.rb
cp -a lib/puppet $(rubylibdir)
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list