puppet 0.16.0 → 0.18.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +98 -0
- data/Rakefile +5 -1
- data/bin/puppet +1 -1
- data/bin/puppetca +25 -11
- data/bin/puppetd +189 -66
- data/bin/puppetdoc +79 -62
- data/bin/puppetmasterd +93 -49
- data/bin/puppetrun +385 -0
- data/conf/redhat/client.init +5 -2
- data/conf/redhat/fileserver.conf +1 -1
- data/conf/redhat/lsb-config.patch +51 -0
- data/conf/redhat/puppet.spec +45 -18
- data/conf/redhat/puppetd.conf +32 -4
- data/conf/redhat/server.init +5 -2
- data/conf/solaris/pkginfo +7 -0
- data/conf/solaris/smf/puppetd.xml +77 -0
- data/conf/solaris/smf/puppetmasterd.xml +77 -0
- data/conf/solaris/smf/svc-puppetd +66 -0
- data/conf/solaris/smf/svc-puppetmasterd +62 -0
- data/examples/code/failers/noobjectrvalue +1 -0
- data/examples/code/snippets/deepclassheirarchy.pp +23 -0
- data/examples/code/snippets/defineoverrides.pp +17 -0
- data/examples/code/snippets/emptyexec.pp +3 -0
- data/examples/code/snippets/selectorvalues.pp +6 -1
- data/examples/code/snippets/tagged.pp +35 -0
- data/ext/ldap/puppet.schema +2 -2
- data/install.rb +4 -2
- data/lib/puppet.rb +206 -15
- data/lib/puppet/client.rb +30 -20
- data/lib/puppet/client/ca.rb +2 -2
- data/lib/puppet/client/dipper.rb +5 -9
- data/lib/puppet/client/master.rb +224 -44
- data/lib/puppet/client/pelement.rb +54 -9
- data/lib/puppet/client/proxy.rb +3 -2
- data/lib/puppet/client/reporter.rb +34 -0
- data/lib/puppet/client/runner.rb +17 -0
- data/lib/puppet/config.rb +136 -55
- data/lib/puppet/daemon.rb +59 -37
- data/lib/puppet/element.rb +2 -1
- data/lib/puppet/event.rb +14 -3
- data/lib/puppet/filetype.rb +28 -19
- data/lib/puppet/log.rb +297 -132
- data/lib/puppet/metric.rb +31 -131
- data/lib/puppet/networkclient.rb +73 -46
- data/lib/puppet/parameter.rb +49 -1
- data/lib/puppet/parsedfile.rb +32 -12
- data/lib/puppet/parser/ast.rb +6 -1
- data/lib/puppet/parser/ast/astarray.rb +32 -6
- data/lib/puppet/parser/ast/collection.rb +91 -0
- data/lib/puppet/parser/ast/compdef.rb +2 -2
- data/lib/puppet/parser/ast/component.rb +24 -11
- data/lib/puppet/parser/ast/function.rb +50 -0
- data/lib/puppet/parser/ast/hostclass.rb +70 -22
- data/lib/puppet/parser/ast/node.rb +17 -8
- data/lib/puppet/parser/ast/nodedef.rb +1 -1
- data/lib/puppet/parser/ast/objectdef.rb +28 -10
- data/lib/puppet/parser/ast/selector.rb +4 -1
- data/lib/puppet/parser/functions.rb +145 -0
- data/lib/puppet/parser/interpreter.rb +243 -86
- data/lib/puppet/parser/lexer.rb +5 -4
- data/lib/puppet/parser/parser.rb +586 -505
- data/lib/puppet/parser/scope.rb +337 -187
- data/lib/puppet/rails.rb +115 -0
- data/lib/puppet/rails/database.rb +40 -0
- data/lib/puppet/rails/host.rb +83 -0
- data/lib/puppet/rails/rails_object.rb +42 -0
- data/lib/puppet/rails/rails_parameter.rb +5 -0
- data/lib/puppet/reports/rrdgraph.rb +20 -0
- data/lib/puppet/reports/tagmail.rb +94 -0
- data/lib/puppet/server.rb +20 -4
- data/lib/puppet/server/authconfig.rb +14 -3
- data/lib/puppet/server/authstore.rb +2 -2
- data/lib/puppet/server/ca.rb +23 -11
- data/lib/puppet/server/filebucket.rb +10 -10
- data/lib/puppet/server/fileserver.rb +4 -8
- data/lib/puppet/server/master.rb +19 -22
- data/lib/puppet/server/pelement.rb +28 -16
- data/lib/puppet/server/report.rb +184 -0
- data/lib/puppet/server/runner.rb +62 -0
- data/lib/puppet/server/servlet.rb +23 -9
- data/lib/puppet/sslcertificates/ca.rb +25 -1
- data/lib/puppet/statechange.rb +34 -53
- data/lib/puppet/storage.rb +1 -2
- data/lib/puppet/transaction.rb +305 -133
- data/lib/puppet/transaction/report.rb +42 -0
- data/lib/puppet/transportable.rb +57 -33
- data/lib/puppet/type.rb +260 -127
- data/lib/puppet/type/component.rb +9 -21
- data/lib/puppet/type/cron.rb +367 -116
- data/lib/puppet/type/exec.rb +15 -16
- data/lib/puppet/type/group.rb +9 -1
- data/lib/puppet/type/nameservice.rb +2 -5
- data/lib/puppet/type/nameservice/netinfo.rb +3 -0
- data/lib/puppet/type/nameservice/objectadd.rb +23 -10
- data/lib/puppet/type/nameservice/pw.rb +16 -3
- data/lib/puppet/type/package.rb +25 -75
- data/lib/puppet/type/package/apple.rb +15 -1
- data/lib/puppet/type/package/apt.rb +37 -2
- data/lib/puppet/type/package/blastwave.rb +136 -0
- data/lib/puppet/type/package/dpkg.rb +4 -4
- data/lib/puppet/type/package/gem.rb +119 -0
- data/lib/puppet/type/package/openbsd.rb +7 -6
- data/lib/puppet/type/package/ports.rb +7 -2
- data/lib/puppet/type/package/rpm.rb +1 -1
- data/lib/puppet/type/package/sun.rb +23 -9
- data/lib/puppet/type/package/sunfreeware.rb +7 -0
- data/lib/puppet/type/package/yum.rb +16 -9
- data/lib/puppet/type/parsedtype.rb +7 -5
- data/lib/puppet/type/parsedtype/mount.rb +55 -34
- data/lib/puppet/type/parsedtype/port.rb +7 -1
- data/lib/puppet/type/parsedtype/sshkey.rb +6 -16
- data/lib/puppet/type/pfile.rb +115 -23
- data/lib/puppet/type/pfile/checksum.rb +18 -5
- data/lib/puppet/type/pfile/content.rb +2 -2
- data/lib/puppet/type/pfile/ensure.rb +3 -3
- data/lib/puppet/type/pfile/group.rb +2 -2
- data/lib/puppet/type/pfile/source.rb +28 -17
- data/lib/puppet/type/pfile/target.rb +25 -17
- data/lib/puppet/type/pfilebucket.rb +25 -6
- data/lib/puppet/type/schedule.rb +6 -6
- data/lib/puppet/type/service.rb +24 -14
- data/lib/puppet/type/service/debian.rb +1 -1
- data/lib/puppet/type/service/redhat.rb +13 -10
- data/lib/puppet/type/service/smf.rb +3 -3
- data/lib/puppet/type/state.rb +1 -2
- data/lib/puppet/type/symlink.rb +3 -4
- data/lib/puppet/type/user.rb +22 -10
- data/lib/puppet/type/yumrepo.rb +6 -1
- data/lib/puppet/type/zone.rb +595 -0
- data/lib/puppet/util.rb +58 -12
- data/test/client/client.rb +2 -2
- data/test/client/master.rb +92 -3
- data/test/client/pelement.rb +99 -0
- data/test/executables/puppetbin.rb +3 -4
- data/test/executables/puppetca.rb +3 -3
- data/test/executables/puppetd.rb +3 -3
- data/test/executables/puppetmasterd.rb +1 -5
- data/test/executables/puppetmodule.rb +2 -2
- data/test/language/ast.rb +200 -11
- data/test/language/functions.rb +245 -0
- data/test/language/interpreter.rb +155 -6
- data/test/language/lexer.rb +35 -2
- data/test/language/node.rb +48 -1
- data/test/language/parser.rb +250 -1
- data/test/language/rails.rb +105 -0
- data/test/language/scope.rb +304 -10
- data/test/language/snippets.rb +54 -5
- data/test/language/transportable.rb +60 -28
- data/test/other/config.rb +214 -1
- data/test/other/events.rb +67 -9
- data/test/other/log.rb +31 -5
- data/test/other/metrics.rb +23 -21
- data/test/other/parsedfile.rb +29 -2
- data/test/other/puppet.rb +79 -0
- data/test/other/report.rb +106 -0
- data/test/other/storage.rb +2 -2
- data/test/other/transactions.rb +128 -2
- data/test/puppet/utiltest.rb +10 -5
- data/test/puppettest.rb +193 -21
- data/test/server/authstore.rb +13 -4
- data/test/server/bucket.rb +33 -8
- data/test/server/ca.rb +44 -6
- data/test/server/master.rb +6 -7
- data/test/server/pelement.rb +15 -5
- data/test/server/report.rb +93 -0
- data/test/server/runner.rb +107 -0
- data/test/server/server.rb +28 -1
- data/test/types/cron.rb +339 -31
- data/test/types/file.rb +256 -24
- data/test/types/filebucket.rb +6 -2
- data/test/types/filesources.rb +41 -92
- data/test/types/group.rb +31 -1
- data/test/types/host.rb +2 -1
- data/test/types/mount.rb +18 -1
- data/test/types/package.rb +200 -18
- data/test/types/service.rb +5 -1
- data/test/types/sshkey.rb +2 -1
- data/test/types/symlink.rb +3 -2
- data/test/types/type.rb +180 -1
- data/test/types/user.rb +65 -27
- data/test/types/yumrepo.rb +15 -0
- data/test/types/zone.rb +437 -0
- metadata +43 -4
- data/bin/cf2puppet +0 -186
- data/conf/redhat/puppetmasterd.conf +0 -5
@@ -34,6 +34,8 @@ class AuthConfig < Puppet::ParsedFile
|
|
34
34
|
namespace = namespace.intern
|
35
35
|
method = method.intern
|
36
36
|
|
37
|
+
read()
|
38
|
+
|
37
39
|
if @rights.include?(name)
|
38
40
|
return @rights[name].allowed?(host, ip)
|
39
41
|
elsif @rights.include?(namespace)
|
@@ -51,10 +53,15 @@ class AuthConfig < Puppet::ParsedFile
|
|
51
53
|
|
52
54
|
def initialize(file = nil, parsenow = true)
|
53
55
|
@file ||= Puppet[:authconfig]
|
56
|
+
|
57
|
+
unless @file
|
58
|
+
raise Puppet::DevError, "No authconfig file defined"
|
59
|
+
end
|
54
60
|
return unless self.exists?
|
55
|
-
super(file)
|
61
|
+
super(@file)
|
56
62
|
@rights = Rights.new
|
57
|
-
@configstamp = @
|
63
|
+
@configstamp = @configstatted = nil
|
64
|
+
@configtimeout = 60
|
58
65
|
|
59
66
|
if parsenow
|
60
67
|
read()
|
@@ -73,10 +80,14 @@ class AuthConfig < Puppet::ParsedFile
|
|
73
80
|
|
74
81
|
if tmp == @configstamp
|
75
82
|
return
|
83
|
+
else
|
84
|
+
Puppet.notice "%s vs %s" % [tmp, @configstamp]
|
76
85
|
end
|
77
86
|
else
|
78
87
|
return
|
79
88
|
end
|
89
|
+
else
|
90
|
+
Puppet.notice "%s and %s" % [@configtimeout, @configstatted]
|
80
91
|
end
|
81
92
|
end
|
82
93
|
|
@@ -163,4 +174,4 @@ end
|
|
163
174
|
end
|
164
175
|
end
|
165
176
|
|
166
|
-
# $Id: authconfig.rb
|
177
|
+
# $Id: authconfig.rb 1148 2006-04-28 19:46:04Z luke $
|
@@ -210,7 +210,7 @@ class Server
|
|
210
210
|
when /^([a-zA-Z][-\w]*\.)+[-\w]+$/: # a full hostname
|
211
211
|
type = :hostname
|
212
212
|
value = pattern.split(".").reverse
|
213
|
-
when
|
213
|
+
when /^\*(\.([a-zA-Z][-\w]*)){1,}$/:
|
214
214
|
type = :domain
|
215
215
|
value = pattern.split(".").reverse
|
216
216
|
else
|
@@ -223,4 +223,4 @@ class Server
|
|
223
223
|
end
|
224
224
|
end
|
225
225
|
#
|
226
|
-
# $Id: authstore.rb
|
226
|
+
# $Id: authstore.rb 1248 2006-06-08 21:46:07Z luke $
|
data/lib/puppet/server/ca.rb
CHANGED
@@ -16,28 +16,36 @@ class Server
|
|
16
16
|
iface.add_method("array getcert(csr)")
|
17
17
|
}
|
18
18
|
|
19
|
+
def autosign
|
20
|
+
if defined? @autosign
|
21
|
+
@autosign
|
22
|
+
else
|
23
|
+
Puppet[:autosign]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
19
27
|
# FIXME autosign? should probably accept both hostnames and IP addresses
|
20
28
|
def autosign?(hostname)
|
21
29
|
# simple values are easy
|
22
|
-
if
|
23
|
-
return
|
30
|
+
if autosign == true or autosign == false
|
31
|
+
return autosign
|
24
32
|
end
|
25
33
|
|
26
34
|
# we only otherwise know how to handle files
|
27
|
-
unless
|
35
|
+
unless autosign =~ /^\//
|
28
36
|
raise Puppet::Error, "Invalid autosign value %s" %
|
29
|
-
|
37
|
+
autosign.inspect
|
30
38
|
end
|
31
39
|
|
32
|
-
unless FileTest.exists?(
|
40
|
+
unless FileTest.exists?(autosign)
|
33
41
|
unless defined? @@warnedonautosign
|
34
42
|
@@warnedonautosign = true
|
35
|
-
Puppet.info "Autosign is enabled but %s is missing" %
|
43
|
+
Puppet.info "Autosign is enabled but %s is missing" % autosign
|
36
44
|
end
|
37
45
|
return false
|
38
46
|
end
|
39
47
|
auth = Puppet::Server::AuthStore.new
|
40
|
-
File.open(
|
48
|
+
File.open(autosign) { |f|
|
41
49
|
f.each { |line|
|
42
50
|
auth.allow(line.chomp)
|
43
51
|
}
|
@@ -49,7 +57,10 @@ class Server
|
|
49
57
|
|
50
58
|
def initialize(hash = {})
|
51
59
|
Puppet.config.use(:puppet, :certificates, :ca)
|
52
|
-
|
60
|
+
if hash.include? :autosign
|
61
|
+
@autosign = hash[:autosign]
|
62
|
+
end
|
63
|
+
|
53
64
|
@ca = Puppet::SSLCertificates::CA.new(hash)
|
54
65
|
end
|
55
66
|
|
@@ -101,13 +112,14 @@ class Server
|
|
101
112
|
# the csr and return the results
|
102
113
|
Puppet.info "Signing certificate for %s" % hostname
|
103
114
|
cert, cacert = @ca.sign(csr)
|
104
|
-
Puppet.info "Cert: %s; Cacert: %s" % [cert.class, cacert.class]
|
115
|
+
#Puppet.info "Cert: %s; Cacert: %s" % [cert.class, cacert.class]
|
105
116
|
return [cert.to_pem, cacert.to_pem]
|
106
117
|
else # just write out the csr for later signing
|
107
118
|
if @ca.getclientcsr(hostname)
|
108
119
|
Puppet.info "Not replacing existing request from %s" % hostname
|
109
120
|
else
|
110
|
-
Puppet.
|
121
|
+
Puppet.notice "Host %s has a waiting certificate request" %
|
122
|
+
hostname
|
111
123
|
@ca.storeclientcsr(csr)
|
112
124
|
end
|
113
125
|
return ["", ""]
|
@@ -138,4 +150,4 @@ class Server
|
|
138
150
|
end
|
139
151
|
end
|
140
152
|
|
141
|
-
# $Id: ca.rb
|
153
|
+
# $Id: ca.rb 1414 2006-07-21 15:20:44Z luke $
|
@@ -16,7 +16,7 @@ class Server
|
|
16
16
|
Puppet.config.setdefaults("filebucket",
|
17
17
|
:bucketdir => {
|
18
18
|
:default => "$vardir/bucket",
|
19
|
-
:mode =>
|
19
|
+
:mode => 0750,
|
20
20
|
:owner => "$user",
|
21
21
|
:group => "$group",
|
22
22
|
:desc => "Where FileBucket files are stored."
|
@@ -28,7 +28,7 @@ class Server
|
|
28
28
|
}
|
29
29
|
|
30
30
|
Puppet::Util.logmethods(self, true)
|
31
|
-
attr_reader :name
|
31
|
+
attr_reader :name, :path
|
32
32
|
|
33
33
|
# this doesn't work for relative paths
|
34
34
|
def FileBucket.paths(base,md5)
|
@@ -48,19 +48,19 @@ class Server
|
|
48
48
|
end
|
49
49
|
|
50
50
|
if hash.include?(:Path)
|
51
|
-
@
|
51
|
+
@path = hash[:Path]
|
52
52
|
hash.delete(:Path)
|
53
53
|
else
|
54
54
|
if defined? Puppet
|
55
|
-
@
|
55
|
+
@path = Puppet[:bucketdir]
|
56
56
|
else
|
57
|
-
@
|
57
|
+
@path = File.expand_path("~/.filebucket")
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
Puppet.config.use(:filebucket)
|
62
62
|
|
63
|
-
@name = "filebucket[#{
|
63
|
+
@name = "filebucket[#{@path}]"
|
64
64
|
end
|
65
65
|
|
66
66
|
# accept a file from a client
|
@@ -68,7 +68,7 @@ class Server
|
|
68
68
|
contents = Base64.decode64(string)
|
69
69
|
md5 = Digest::MD5.hexdigest(contents)
|
70
70
|
|
71
|
-
bpath, bfile, pathpath = FileBucket.paths(@
|
71
|
+
bpath, bfile, pathpath = FileBucket.paths(@path,md5)
|
72
72
|
|
73
73
|
# if it's a new directory...
|
74
74
|
if Puppet.recmkdir(bpath)
|
@@ -109,7 +109,7 @@ class Server
|
|
109
109
|
addpath = false
|
110
110
|
if FileTest.exists?(pathpath)
|
111
111
|
File.open(pathpath) { |of|
|
112
|
-
paths = of.readlines
|
112
|
+
paths = of.readlines.collect { |l| l.chomp }
|
113
113
|
}
|
114
114
|
|
115
115
|
# unless our path is already there...
|
@@ -131,7 +131,7 @@ class Server
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def getfile(md5, client = nil, clientip = nil)
|
134
|
-
bpath, bfile, bpaths = FileBucket.paths(@
|
134
|
+
bpath, bfile, bpaths = FileBucket.paths(@path,md5)
|
135
135
|
|
136
136
|
unless FileTest.exists?(bfile)
|
137
137
|
return false
|
@@ -152,4 +152,4 @@ class Server
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
#
|
155
|
-
# $Id: filebucket.rb
|
155
|
+
# $Id: filebucket.rb 1392 2006-07-11 20:58:25Z luke $
|
@@ -60,11 +60,6 @@ class Server
|
|
60
60
|
return ""
|
61
61
|
end
|
62
62
|
|
63
|
-
#if links == :ignore and obj[:type] == "link"
|
64
|
-
# mount.info "Ignoring link %s" % obj.name
|
65
|
-
# return ""
|
66
|
-
#end
|
67
|
-
|
68
63
|
desc = []
|
69
64
|
CHECKPARAMS.each { |check|
|
70
65
|
if state = obj.state(check)
|
@@ -278,7 +273,7 @@ class Server
|
|
278
273
|
Puppet.err "FileServer error: Cannot read %s; cannot serve" % @config
|
279
274
|
#raise Puppet::Error, "Cannot read %s" % @config
|
280
275
|
rescue Errno::ENOENT => detail
|
281
|
-
Puppet.err "FileServer error: '%s' does not
|
276
|
+
Puppet.err "FileServer error: '%s' does not exist; cannot serve" %
|
282
277
|
@config
|
283
278
|
#raise Puppet::Error, "%s does not exit" % @config
|
284
279
|
#rescue FileServerError => detail
|
@@ -423,8 +418,9 @@ class Server
|
|
423
418
|
path = nil
|
424
419
|
else
|
425
420
|
# Remove any double slashes that might have occurred
|
426
|
-
path.gsub
|
421
|
+
path = URI.unescape(path.gsub(/\/\//, "/"))
|
427
422
|
end
|
423
|
+
|
428
424
|
return mount, path
|
429
425
|
end
|
430
426
|
|
@@ -562,4 +558,4 @@ class Server
|
|
562
558
|
end
|
563
559
|
end
|
564
560
|
|
565
|
-
# $Id: fileserver.rb
|
561
|
+
# $Id: fileserver.rb 1315 2006-06-27 05:15:51Z luke $
|
data/lib/puppet/server/master.rb
CHANGED
@@ -25,16 +25,15 @@ class Server
|
|
25
25
|
facts["serverversion"] = Puppet.version.to_s
|
26
26
|
|
27
27
|
# And then add the server name and IP
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@interpreter.filetimeout = int
|
28
|
+
{"servername" => "hostname",
|
29
|
+
"serverip" => "ipaddress"
|
30
|
+
}.each do |var, fact|
|
31
|
+
if obj = Facter[fact]
|
32
|
+
facts[var] = obj.value
|
33
|
+
else
|
34
|
+
Puppet.warning "Could not retrieve fact %s" % fact
|
35
|
+
end
|
36
|
+
end
|
38
37
|
end
|
39
38
|
|
40
39
|
# Tell a client whether there's a fresh config for it
|
@@ -70,8 +69,6 @@ class Server
|
|
70
69
|
@ca = nil
|
71
70
|
end
|
72
71
|
|
73
|
-
args[:ParseCheck] = hash[:FileTimeout] || 15
|
74
|
-
|
75
72
|
Puppet.debug("Creating interpreter")
|
76
73
|
|
77
74
|
if hash.include?(:UseNodes)
|
@@ -135,17 +132,17 @@ class Server
|
|
135
132
|
# This is hackish, but there's no "silence" option for benchmarks
|
136
133
|
# right now
|
137
134
|
if @local
|
138
|
-
begin
|
135
|
+
#begin
|
139
136
|
retobjects = @interpreter.run(client, facts)
|
140
|
-
rescue Puppet::Error => detail
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
rescue => detail
|
146
|
-
|
147
|
-
|
148
|
-
end
|
137
|
+
#rescue Puppet::Error => detail
|
138
|
+
# Puppet.err detail
|
139
|
+
# raise XMLRPC::FaultException.new(
|
140
|
+
# 1, detail.to_s
|
141
|
+
# )
|
142
|
+
#rescue => detail
|
143
|
+
# Puppet.err detail.to_s
|
144
|
+
# return ""
|
145
|
+
#end
|
149
146
|
else
|
150
147
|
benchmark(:notice, "Compiled configuration for %s" % client) do
|
151
148
|
begin
|
@@ -19,8 +19,7 @@ class Server::PElement < Server::Handler
|
|
19
19
|
begin
|
20
20
|
case format
|
21
21
|
when "yaml":
|
22
|
-
|
23
|
-
bucket = tmp
|
22
|
+
bucket = YAML::load(Base64.decode64(bucket))
|
24
23
|
else
|
25
24
|
raise Puppet::Error, "Unsupported format '%s'" % format
|
26
25
|
end
|
@@ -50,6 +49,7 @@ class Server::PElement < Server::Handler
|
|
50
49
|
# Describe a given object. This returns the 'is' values for every state
|
51
50
|
# available on the object type.
|
52
51
|
def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
|
52
|
+
Puppet.info "Describing %s[%s]" % [type, name]
|
53
53
|
@local = true unless client
|
54
54
|
typeklass = nil
|
55
55
|
unless typeklass = Puppet.type(type)
|
@@ -59,6 +59,7 @@ class Server::PElement < Server::Handler
|
|
59
59
|
obj = nil
|
60
60
|
|
61
61
|
retrieve ||= :all
|
62
|
+
ignore ||= []
|
62
63
|
|
63
64
|
if obj = typeklass[name]
|
64
65
|
obj[:check] = retrieve
|
@@ -71,6 +72,12 @@ class Server::PElement < Server::Handler
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
75
|
+
unless obj
|
76
|
+
raise XMLRPC::FaultException.new(
|
77
|
+
1, "Could not create %s[%s]" % [type, name]
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
74
81
|
trans = obj.to_trans
|
75
82
|
|
76
83
|
# Now get rid of any attributes they specifically don't want
|
@@ -87,20 +94,18 @@ class Server::PElement < Server::Handler
|
|
87
94
|
end
|
88
95
|
end
|
89
96
|
|
90
|
-
|
91
|
-
return trans
|
92
|
-
else
|
93
|
-
str = nil
|
97
|
+
unless @local
|
94
98
|
case format
|
95
99
|
when "yaml":
|
96
|
-
|
100
|
+
trans = Base64.encode64(YAML::dump(trans))
|
97
101
|
else
|
98
102
|
raise XMLRPC::FaultException.new(
|
99
103
|
1, "Unavailable config format %s" % format
|
100
104
|
)
|
101
105
|
end
|
102
|
-
return CGI.escape(str)
|
103
106
|
end
|
107
|
+
|
108
|
+
return trans
|
104
109
|
end
|
105
110
|
|
106
111
|
# Create a new fileserving module.
|
@@ -113,13 +118,15 @@ class Server::PElement < Server::Handler
|
|
113
118
|
end
|
114
119
|
|
115
120
|
# List all of the elements of a given type.
|
116
|
-
def list(type, ignore = [], base = nil, client = nil, clientip = nil)
|
121
|
+
def list(type, ignore = [], base = nil, format = "yaml", client = nil, clientip = nil)
|
117
122
|
@local = true unless client
|
118
123
|
typeklass = nil
|
119
124
|
unless typeklass = Puppet.type(type)
|
120
125
|
raise Puppet::Error, "Puppet type %s is unsupported" % type
|
121
126
|
end
|
122
127
|
|
128
|
+
# They can pass in false
|
129
|
+
ignore ||= []
|
123
130
|
ignore = [ignore] unless ignore.is_a? Array
|
124
131
|
bucket = TransBucket.new
|
125
132
|
bucket.type = typeklass.name
|
@@ -131,20 +138,25 @@ class Server::PElement < Server::Handler
|
|
131
138
|
bucket << object
|
132
139
|
end
|
133
140
|
|
134
|
-
|
135
|
-
return bucket
|
136
|
-
else
|
137
|
-
str = nil
|
141
|
+
unless @local
|
138
142
|
case format
|
139
143
|
when "yaml":
|
140
|
-
|
144
|
+
begin
|
145
|
+
bucket = Base64.encode64(YAML::dump(bucket))
|
146
|
+
rescue => detail
|
147
|
+
Puppet.err detail
|
148
|
+
raise XMLRPC::FaultException.new(
|
149
|
+
1, detail.to_s
|
150
|
+
)
|
151
|
+
end
|
141
152
|
else
|
142
153
|
raise XMLRPC::FaultException.new(
|
143
154
|
1, "Unavailable config format %s" % format
|
144
155
|
)
|
145
156
|
end
|
146
|
-
return CGI.escape(str)
|
147
157
|
end
|
158
|
+
|
159
|
+
return bucket
|
148
160
|
end
|
149
161
|
|
150
162
|
private
|
@@ -173,4 +185,4 @@ class Server::PElement < Server::Handler
|
|
173
185
|
end
|
174
186
|
end
|
175
187
|
|
176
|
-
# $Id: pelement.rb
|
188
|
+
# $Id: pelement.rb 1145 2006-04-28 04:08:38Z luke $
|
@@ -0,0 +1,184 @@
|
|
1
|
+
module Puppet
|
2
|
+
class Server
|
3
|
+
# A simple server for triggering a new run on a Puppet client.
|
4
|
+
class Report < Handler
|
5
|
+
@interface = XMLRPC::Service::Interface.new("puppetreports") { |iface|
|
6
|
+
iface.add_method("string report(array)")
|
7
|
+
}
|
8
|
+
|
9
|
+
Puppet.setdefaults(:reporting,
|
10
|
+
:reportdirectory => {:default => "$vardir/reports",
|
11
|
+
:mode => 0750,
|
12
|
+
:owner => "$user",
|
13
|
+
:group => "$group",
|
14
|
+
:desc => "The directory in which to store reports received from the
|
15
|
+
client. Each client gets a separate subdirectory."},
|
16
|
+
:reports => ["none",
|
17
|
+
"The list of reports to generate. All reports are looked for
|
18
|
+
in puppet/reports/<name>.rb, and multiple report names should be
|
19
|
+
comma-separated (whitespace is okay)."
|
20
|
+
]
|
21
|
+
)
|
22
|
+
|
23
|
+
@reports = {}
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_reader :hooks
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.reportmethod(report)
|
30
|
+
"report_" + report.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
# Add a hook for processing reports.
|
34
|
+
def self.newreport(name, &block)
|
35
|
+
name = name.intern if name.is_a? String
|
36
|
+
method = reportmethod(name)
|
37
|
+
|
38
|
+
# We want to define a method so that reports can use 'return'.
|
39
|
+
define_method(method, &block)
|
40
|
+
|
41
|
+
@reports[name] = method
|
42
|
+
end
|
43
|
+
|
44
|
+
# Load a report.
|
45
|
+
def self.report(name)
|
46
|
+
name = name.intern if name.is_a? String
|
47
|
+
unless @reports.include? reportmethod(name)
|
48
|
+
begin
|
49
|
+
require "puppet/reports/#{name.to_s}"
|
50
|
+
unless @reports.include? name
|
51
|
+
Puppet.warning(
|
52
|
+
"Loaded report file for %s but report was not defined" %
|
53
|
+
name
|
54
|
+
)
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
rescue LoadError => detail
|
58
|
+
if Puppet[:debug]
|
59
|
+
puts detail.backtrace
|
60
|
+
end
|
61
|
+
Puppet.warning "Could not load report %s: %s" %
|
62
|
+
[name, detail]
|
63
|
+
return nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
@reports[name]
|
68
|
+
end
|
69
|
+
|
70
|
+
def initialize(*args)
|
71
|
+
super
|
72
|
+
Puppet.config.use(:reporting)
|
73
|
+
Puppet.config.use(:metrics)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Dynamically create the report methods as necessary.
|
77
|
+
def method_missing(name, *args)
|
78
|
+
if name.to_s =~ /^report_(.+)$/
|
79
|
+
if self.class.report($1)
|
80
|
+
send(name, *args)
|
81
|
+
else
|
82
|
+
super
|
83
|
+
end
|
84
|
+
else
|
85
|
+
super
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Accept a report from a client.
|
90
|
+
def report(report, client = nil, clientip = nil)
|
91
|
+
# We need the client name for storing files.
|
92
|
+
client ||= Facter["hostname"].value
|
93
|
+
|
94
|
+
# Unescape the report
|
95
|
+
unless @local
|
96
|
+
report = CGI.unescape(report)
|
97
|
+
end
|
98
|
+
|
99
|
+
process(report)
|
100
|
+
|
101
|
+
# We don't want any tracking back in the fs. Unlikely, but there
|
102
|
+
# you go.
|
103
|
+
client.gsub("..",".")
|
104
|
+
|
105
|
+
dir = File.join(Puppet[:reportdirectory], client)
|
106
|
+
|
107
|
+
unless FileTest.exists?(dir)
|
108
|
+
mkclientdir(client, dir)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Now store the report.
|
112
|
+
now = Time.now.gmtime
|
113
|
+
name = %w{year month day hour min}.collect do |method|
|
114
|
+
# Make sure we're at least two digits everywhere
|
115
|
+
"%02d" % now.send(method).to_s
|
116
|
+
end.join("") + ".yaml"
|
117
|
+
|
118
|
+
file = File.join(dir, name)
|
119
|
+
|
120
|
+
begin
|
121
|
+
File.open(file, "w", 0640) do |f|
|
122
|
+
f.puts report
|
123
|
+
end
|
124
|
+
rescue => detail
|
125
|
+
if Puppet[:debug]
|
126
|
+
puts detail.backtrace
|
127
|
+
end
|
128
|
+
Puppet.warning "Could not write report for %s at %s: %s" %
|
129
|
+
[client, file, detail]
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
# Our report is in YAML
|
134
|
+
return file
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def mkclientdir(client, dir)
|
140
|
+
Puppet.config.setdefaults("reportclient-#{client}",
|
141
|
+
"clientdir-#{client}" => { :default => dir,
|
142
|
+
:mode => 0750,
|
143
|
+
:owner => "$user",
|
144
|
+
:group => "$group"
|
145
|
+
}
|
146
|
+
)
|
147
|
+
|
148
|
+
Puppet.config.use("reportclient-#{client}")
|
149
|
+
end
|
150
|
+
|
151
|
+
# Process the report using all of the existing hooks.
|
152
|
+
def process(report)
|
153
|
+
return if Puppet[:reports] == "none"
|
154
|
+
|
155
|
+
# First convert the report to real objects
|
156
|
+
begin
|
157
|
+
report = YAML.load(report)
|
158
|
+
rescue => detail
|
159
|
+
Puppet.warning "Could not load report: %s" % detail
|
160
|
+
return
|
161
|
+
end
|
162
|
+
|
163
|
+
Puppet[:reports].split(/\s*,\s*/).each do |name|
|
164
|
+
method = self.class.reportmethod(name)
|
165
|
+
|
166
|
+
Puppet.info "Processing report %s" % name
|
167
|
+
begin
|
168
|
+
send(method, report)
|
169
|
+
rescue NoMethodError => detail
|
170
|
+
Puppet.warning "No report named '%s'" % name
|
171
|
+
rescue => detail
|
172
|
+
if Puppet[:debug]
|
173
|
+
puts detail.backtrace
|
174
|
+
end
|
175
|
+
Puppet.err "Report %s failed: %s" %
|
176
|
+
[name, detail]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# $Id: report.rb 1390 2006-07-11 20:22:27Z luke $
|