puppet 0.13.6 → 0.16.0
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 +57 -0
- data/Rakefile +38 -410
- data/bin/puppet +14 -12
- data/bin/puppetca +1 -3
- data/bin/puppetd +25 -7
- data/bin/puppetdoc +161 -104
- data/bin/puppetmasterd +4 -4
- data/conf/epm.list +8 -0
- data/conf/redhat/client.init +6 -1
- data/conf/redhat/no-chuser-0.15.1.patch +38 -0
- data/conf/redhat/puppet.spec +20 -5
- data/conf/redhat/puppetd.conf +1 -1
- data/conf/redhat/puppetmasterd.conf +1 -1
- data/conf/redhat/server.init +2 -4
- data/examples/code/snippets/{casestatement → casestatement.pp} +12 -1
- data/examples/code/snippets/selectorvalues.pp +15 -0
- data/examples/code/snippets/singleselector.pp +22 -0
- data/examples/code/snippets/tag.pp +9 -0
- data/ext/module_puppet +1 -1
- data/install.rb +303 -303
- data/lib/puppet.rb +7 -9
- data/lib/puppet/client.rb +18 -5
- data/lib/puppet/client/dipper.rb +12 -10
- data/lib/puppet/client/master.rb +113 -41
- data/lib/puppet/client/pelement.rb +20 -0
- data/lib/puppet/config.rb +113 -6
- data/lib/puppet/element.rb +1 -3
- data/lib/puppet/event.rb +12 -23
- data/lib/puppet/filetype.rb +93 -5
- data/lib/puppet/inifile.rb +201 -0
- data/lib/puppet/log.rb +18 -6
- data/lib/puppet/parameter.rb +80 -29
- data/lib/puppet/parser/ast.rb +6 -4
- data/lib/puppet/parser/ast/caseopt.rb +13 -4
- data/lib/puppet/parser/ast/casestatement.rb +2 -2
- data/lib/puppet/parser/ast/component.rb +4 -14
- data/lib/puppet/parser/ast/hostclass.rb +1 -1
- data/lib/puppet/parser/ast/leaf.rb +12 -0
- data/lib/puppet/parser/ast/node.rb +4 -4
- data/lib/puppet/parser/ast/objectdef.rb +5 -51
- data/lib/puppet/parser/ast/selector.rb +2 -0
- data/lib/puppet/parser/ast/tag.rb +26 -0
- data/lib/puppet/parser/interpreter.rb +89 -74
- data/lib/puppet/parser/lexer.rb +4 -3
- data/lib/puppet/parser/parser.rb +440 -378
- data/lib/puppet/parser/scope.rb +844 -887
- data/lib/puppet/server.rb +12 -1
- data/lib/puppet/server/authconfig.rb +166 -0
- data/lib/puppet/server/authstore.rb +8 -6
- data/lib/puppet/server/ca.rb +23 -26
- data/lib/puppet/server/filebucket.rb +24 -23
- data/lib/puppet/server/fileserver.rb +116 -47
- data/lib/puppet/server/master.rb +58 -19
- data/lib/puppet/server/pelement.rb +176 -0
- data/lib/puppet/server/rights.rb +78 -0
- data/lib/puppet/server/servlet.rb +19 -6
- data/lib/puppet/sslcertificates.rb +4 -2
- data/lib/puppet/sslcertificates/ca.rb +66 -34
- data/lib/puppet/storage.rb +20 -26
- data/lib/puppet/transaction.rb +49 -92
- data/lib/puppet/type.rb +142 -35
- data/lib/puppet/type/cron.rb +29 -14
- data/lib/puppet/type/exec.rb +92 -35
- data/lib/puppet/type/group.rb +29 -11
- data/lib/puppet/type/nameservice.rb +50 -1
- data/lib/puppet/type/nameservice/netinfo.rb +68 -1
- data/lib/puppet/type/nameservice/objectadd.rb +1 -0
- data/lib/puppet/type/package.rb +150 -109
- data/lib/puppet/type/package/apple.rb +27 -0
- data/lib/puppet/type/package/apt.rb +1 -0
- data/lib/puppet/type/package/darwinport.rb +97 -0
- data/lib/puppet/type/package/dpkg.rb +10 -2
- data/lib/puppet/type/package/freebsd.rb +19 -0
- data/lib/puppet/type/package/{bsd.rb → openbsd.rb} +36 -7
- data/lib/puppet/type/package/ports.rb +98 -0
- data/lib/puppet/type/package/rpm.rb +43 -7
- data/lib/puppet/type/package/sun.rb +53 -36
- data/lib/puppet/type/package/yum.rb +5 -16
- data/lib/puppet/type/parsedtype.rb +41 -29
- data/lib/puppet/type/parsedtype/host.rb +13 -5
- data/lib/puppet/type/parsedtype/mount.rb +250 -0
- data/lib/puppet/type/parsedtype/port.rb +8 -6
- data/lib/puppet/type/pfile.rb +284 -30
- data/lib/puppet/type/pfile/checksum.rb +96 -68
- data/lib/puppet/type/pfile/content.rb +16 -13
- data/lib/puppet/type/pfile/ensure.rb +64 -126
- data/lib/puppet/type/pfile/group.rb +12 -5
- data/lib/puppet/type/pfile/mode.rb +16 -4
- data/lib/puppet/type/pfile/source.rb +47 -73
- data/lib/puppet/type/pfile/target.rb +81 -0
- data/lib/puppet/type/pfile/uid.rb +10 -3
- data/lib/puppet/type/pfilebucket.rb +12 -3
- data/lib/puppet/type/schedule.rb +5 -1
- data/lib/puppet/type/service.rb +138 -66
- data/lib/puppet/type/service/debian.rb +9 -3
- data/lib/puppet/type/service/init.rb +51 -56
- data/lib/puppet/type/service/smf.rb +16 -6
- data/lib/puppet/type/state.rb +71 -32
- data/lib/puppet/type/symlink.rb +12 -7
- data/lib/puppet/type/tidy.rb +5 -1
- data/lib/puppet/type/user.rb +116 -20
- data/lib/puppet/type/yumrepo.rb +314 -0
- data/lib/puppet/util.rb +84 -14
- data/test/client/client.rb +41 -18
- data/test/client/master.rb +50 -4
- data/test/executables/puppetbin.rb +31 -4
- data/test/executables/puppetca.rb +18 -2
- data/test/language/ast.rb +201 -31
- data/test/language/interpreter.rb +8 -2
- data/test/{parser → language}/lexer.rb +1 -1
- data/test/language/node.rb +84 -0
- data/test/{parser → language}/parser.rb +1 -1
- data/test/language/scope.rb +101 -2
- data/test/language/snippets.rb +23 -2
- data/test/other/config.rb +99 -1
- data/test/other/filetype.rb +95 -0
- data/test/other/inifile.rb +114 -0
- data/test/other/log.rb +3 -2
- data/test/other/transactions.rb +55 -10
- data/test/puppet/utiltest.rb +25 -1
- data/test/puppettest.rb +140 -46
- data/test/server/authconfig.rb +56 -0
- data/test/server/bucket.rb +32 -18
- data/test/server/fileserver.rb +75 -30
- data/test/server/master.rb +27 -4
- data/test/server/pelement.rb +298 -0
- data/test/server/rights.rb +41 -0
- data/test/server/server.rb +2 -2
- data/test/tagging/tagging.rb +100 -1
- data/test/types/basic.rb +3 -3
- data/test/types/cron.rb +24 -1
- data/test/types/exec.rb +99 -1
- data/test/types/file.rb +298 -2
- data/test/types/filebucket.rb +4 -15
- data/test/types/filesources.rb +43 -14
- data/test/types/group.rb +1 -13
- data/test/types/mount.rb +277 -0
- data/test/types/package.rb +164 -33
- data/test/types/parameter.rb +107 -0
- data/test/types/port.rb +2 -1
- data/test/types/service.rb +37 -2
- data/test/types/state.rb +92 -0
- data/test/types/symlink.rb +30 -2
- data/test/types/tidy.rb +2 -14
- data/test/types/type.rb +35 -1
- data/test/types/user.rb +110 -1
- data/test/types/yumrepo.rb +95 -0
- metadata +316 -290
- data/test/types/filetype.rb +0 -160
@@ -1,34 +1,7 @@
|
|
1
1
|
module Puppet
|
2
|
-
Puppet.type(:package).newpkgtype(:
|
3
|
-
|
4
|
-
|
5
|
-
raise Puppet::Error, "Sun packages must specify a package source"
|
6
|
-
end
|
7
|
-
#cmd = "pkgadd -d %s -n %s 2>&1" % [self[:source], self[:name]]
|
8
|
-
cmd = ["pkgadd"]
|
9
|
-
|
10
|
-
if self[:adminfile]
|
11
|
-
cmd += ["-a", self[:adminfile]]
|
12
|
-
end
|
13
|
-
|
14
|
-
if self[:responsefile]
|
15
|
-
cmd += ["-r", self[:responsefile]]
|
16
|
-
end
|
17
|
-
|
18
|
-
cmd += ["-d", self[:source]]
|
19
|
-
cmd += ["-n", self[:name]]
|
20
|
-
cmd << "2>&1"
|
21
|
-
cmd = cmd.join(" ")
|
22
|
-
|
23
|
-
self.info "Executing %s" % cmd.inspect
|
24
|
-
output = %x{#{cmd} 2>&1}
|
25
|
-
|
26
|
-
unless $? == 0
|
27
|
-
raise Puppet::PackageError.new(output)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def query
|
2
|
+
Puppet.type(:package).newpkgtype(:sun) do
|
3
|
+
# Get info on a package, optionally specifying a device.
|
4
|
+
def info2hash(device = nil)
|
32
5
|
names = {
|
33
6
|
"PKGINST" => :name,
|
34
7
|
"NAME" => nil,
|
@@ -48,9 +21,14 @@ module Puppet
|
|
48
21
|
}
|
49
22
|
|
50
23
|
hash = {}
|
24
|
+
cmd = "pkginfo -l"
|
25
|
+
if device
|
26
|
+
cmd += " -d #{device}"
|
27
|
+
end
|
28
|
+
cmd += " #{self[:name]} 2>/dev/null"
|
51
29
|
|
52
30
|
# list out all of the packages
|
53
|
-
open("|
|
31
|
+
open("| #{cmd}") { |process|
|
54
32
|
# we're using the long listing, so each line is a separate
|
55
33
|
# piece of information
|
56
34
|
process.each { |line|
|
@@ -79,6 +57,39 @@ module Puppet
|
|
79
57
|
end
|
80
58
|
end
|
81
59
|
|
60
|
+
def install
|
61
|
+
unless self[:source]
|
62
|
+
raise Puppet::Error, "Sun packages must specify a package source"
|
63
|
+
end
|
64
|
+
cmd = ["pkgadd"]
|
65
|
+
|
66
|
+
if self[:adminfile]
|
67
|
+
cmd += ["-a", self[:adminfile]]
|
68
|
+
end
|
69
|
+
|
70
|
+
if self[:responsefile]
|
71
|
+
cmd += ["-r", self[:responsefile]]
|
72
|
+
end
|
73
|
+
|
74
|
+
cmd += ["-d", self[:source]]
|
75
|
+
cmd += ["-n", self[:name]]
|
76
|
+
cmd << "2>&1"
|
77
|
+
cmd = cmd.join(" ")
|
78
|
+
|
79
|
+
self.info "Executing %s" % cmd.inspect
|
80
|
+
output = %x{#{cmd} 2>&1}
|
81
|
+
|
82
|
+
unless $? == 0
|
83
|
+
raise Puppet::PackageError.new(output)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Retrieve the version from the current package file.
|
88
|
+
def latest
|
89
|
+
hash = info2hash(self[:source])
|
90
|
+
hash[:ensure]
|
91
|
+
end
|
92
|
+
|
82
93
|
def list
|
83
94
|
packages = []
|
84
95
|
hash = {}
|
@@ -126,11 +137,9 @@ module Puppet
|
|
126
137
|
return packages
|
127
138
|
end
|
128
139
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
# raise "installation not implemented yet"
|
133
|
-
#}
|
140
|
+
def query
|
141
|
+
info2hash()
|
142
|
+
end
|
134
143
|
|
135
144
|
def uninstall
|
136
145
|
cmd = "pkgrm -n %s 2>&1" % self[:name]
|
@@ -139,5 +148,13 @@ module Puppet
|
|
139
148
|
raise Puppet::Error, "Removal of %s failed: %s" % [self.name, output]
|
140
149
|
end
|
141
150
|
end
|
151
|
+
|
152
|
+
# Remove the old package, and install the new one
|
153
|
+
def update
|
154
|
+
if @states[:ensure].is != :absent
|
155
|
+
self.uninstall
|
156
|
+
end
|
157
|
+
self.install
|
158
|
+
end
|
142
159
|
end
|
143
160
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Puppet
|
2
2
|
Puppet.type(:package).newpkgtype(:yum, :rpm) do
|
3
|
-
|
4
3
|
# Install a package using 'yum'.
|
5
4
|
def install
|
6
5
|
cmd = "yum -y install %s" % self[:name]
|
@@ -15,7 +14,7 @@ module Puppet
|
|
15
14
|
|
16
15
|
# What's the latest package version available?
|
17
16
|
def latest
|
18
|
-
cmd = "yum list
|
17
|
+
cmd = "yum list available %s" % self[:name]
|
19
18
|
self.info "Executing %s" % cmd.inspect
|
20
19
|
output = %x{#{cmd} 2>&1}
|
21
20
|
|
@@ -33,20 +32,8 @@ module Puppet
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def update
|
36
|
-
#
|
37
|
-
|
38
|
-
if self.is(:ensure) == :absent
|
39
|
-
self.info "performing initial install"
|
40
|
-
return self.install
|
41
|
-
end
|
42
|
-
cmd = "yum -y update %s" % self[:name]
|
43
|
-
|
44
|
-
self.info "Executing %s" % cmd.inspect
|
45
|
-
output = %x{#{cmd} 2>&1}
|
46
|
-
|
47
|
-
unless $? == 0
|
48
|
-
raise Puppet::PackageError.new(output)
|
49
|
-
end
|
35
|
+
# Install in yum can be used for update, too
|
36
|
+
self.install
|
50
37
|
end
|
51
38
|
|
52
39
|
def versionable?
|
@@ -54,3 +41,5 @@ module Puppet
|
|
54
41
|
end
|
55
42
|
end
|
56
43
|
end
|
44
|
+
|
45
|
+
# $Id: yum.rb 1128 2006-04-21 03:06:54Z luke $
|
@@ -123,13 +123,6 @@ module Puppet
|
|
123
123
|
super
|
124
124
|
end
|
125
125
|
|
126
|
-
# Override the Puppet::Type#[]= method so that we can store the
|
127
|
-
# instances in per-user arrays. Then just call +super+.
|
128
|
-
def self.[]=(name, object)
|
129
|
-
self.instance(object)
|
130
|
-
super
|
131
|
-
end
|
132
|
-
|
133
126
|
# In addition to removing the instances in @objects, we have to remove
|
134
127
|
# per-user host tab information.
|
135
128
|
def self.clear
|
@@ -138,6 +131,11 @@ module Puppet
|
|
138
131
|
super
|
139
132
|
end
|
140
133
|
|
134
|
+
# Add a non-object comment or whatever to our list of instances
|
135
|
+
def self.comment(line)
|
136
|
+
@instances << line
|
137
|
+
end
|
138
|
+
|
141
139
|
# Override the default Puppet::Type method, because instances
|
142
140
|
# also need to be deleted from the @instances hash
|
143
141
|
def self.delete(child)
|
@@ -155,13 +153,6 @@ module Puppet
|
|
155
153
|
# HEADER: is definitely not recommended.\n}
|
156
154
|
end
|
157
155
|
|
158
|
-
# Store a new instance of a host. Called from Host#initialize.
|
159
|
-
def self.instance(obj)
|
160
|
-
unless @instances.include?(obj)
|
161
|
-
@instances << obj
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
156
|
# Parse a file
|
166
157
|
#
|
167
158
|
# Subclasses must override this method.
|
@@ -174,12 +165,13 @@ module Puppet
|
|
174
165
|
def self.hash2obj(hash)
|
175
166
|
obj = nil
|
176
167
|
|
177
|
-
|
178
|
-
|
168
|
+
namevar = self.namevar
|
169
|
+
unless hash.include?(namevar) and hash[namevar]
|
170
|
+
raise Puppet::DevError, "Hash was not passed with namevar"
|
179
171
|
end
|
180
172
|
|
181
173
|
# if the obj already exists with that name...
|
182
|
-
if obj = self[hash[
|
174
|
+
if obj = self[hash[namevar]]
|
183
175
|
# We're assuming here that objects with the same name
|
184
176
|
# are the same object, which *should* be the case, assuming
|
185
177
|
# we've set up our naming stuff correctly everywhere.
|
@@ -200,15 +192,27 @@ module Puppet
|
|
200
192
|
else
|
201
193
|
# create a new obj, since no existing one seems to
|
202
194
|
# match
|
203
|
-
obj = self.create(
|
195
|
+
obj = self.create(namevar => hash[namevar])
|
204
196
|
|
205
197
|
# We can't just pass the hash in at object creation time,
|
206
198
|
# because it sets the should value, not the is value.
|
207
|
-
hash.delete(
|
199
|
+
hash.delete(namevar)
|
208
200
|
hash.each { |param, value|
|
209
201
|
obj.is = [param, value]
|
210
202
|
}
|
211
203
|
end
|
204
|
+
|
205
|
+
# And then add it to our list of instances. This maintains the order
|
206
|
+
# in the file.
|
207
|
+
@instances << obj
|
208
|
+
end
|
209
|
+
|
210
|
+
def self.list
|
211
|
+
retrieve
|
212
|
+
|
213
|
+
self.collect do |obj|
|
214
|
+
obj
|
215
|
+
end
|
212
216
|
end
|
213
217
|
|
214
218
|
# Retrieve the text for the file. Returns nil in the unlikely
|
@@ -223,10 +227,11 @@ module Puppet
|
|
223
227
|
# First we mark all of our objects absent; any objects
|
224
228
|
# subsequently found will be marked present
|
225
229
|
self.each { |obj|
|
226
|
-
obj.
|
227
|
-
state.is = :absent
|
228
|
-
}
|
230
|
+
obj.is = [:ensure, :absent]
|
229
231
|
}
|
232
|
+
|
233
|
+
# We clear this, so that non-objects don't get duplicated
|
234
|
+
@instances.clear
|
230
235
|
self.parse(text)
|
231
236
|
end
|
232
237
|
end
|
@@ -235,6 +240,11 @@ module Puppet
|
|
235
240
|
def self.store
|
236
241
|
@fileobj ||= @filetype.new(@path)
|
237
242
|
|
243
|
+
# Make sure all of our instances are in the to-be-written array
|
244
|
+
self.each do |inst|
|
245
|
+
@instances << inst unless @instances.include? inst
|
246
|
+
end
|
247
|
+
|
238
248
|
if @instances.empty?
|
239
249
|
Puppet.notice "No %s instances for %s" % [self.name, @path]
|
240
250
|
else
|
@@ -275,8 +285,13 @@ module Puppet
|
|
275
285
|
@fileobj.loaded
|
276
286
|
end
|
277
287
|
|
288
|
+
# The 'store' method knows how to handle absence vs. presence
|
278
289
|
def create
|
279
|
-
self
|
290
|
+
self.store
|
291
|
+
end
|
292
|
+
|
293
|
+
# The 'store' method knows how to handle absence vs. presence
|
294
|
+
def destroy
|
280
295
|
self.store
|
281
296
|
end
|
282
297
|
|
@@ -285,11 +300,6 @@ module Puppet
|
|
285
300
|
@states.include?(:ensure) and @states[:ensure].is == :present
|
286
301
|
end
|
287
302
|
|
288
|
-
def destroy
|
289
|
-
self[:ensure] = :absent
|
290
|
-
self.store
|
291
|
-
end
|
292
|
-
|
293
303
|
# Override the default Puppet::Type method because we need to call
|
294
304
|
# the +@filetype+ retrieve method.
|
295
305
|
def retrieve
|
@@ -326,5 +336,7 @@ end
|
|
326
336
|
|
327
337
|
require 'puppet/type/parsedtype/host'
|
328
338
|
require 'puppet/type/parsedtype/port'
|
339
|
+
require 'puppet/type/parsedtype/mount'
|
340
|
+
require 'puppet/type/parsedtype/sshkey'
|
329
341
|
|
330
|
-
# $Id: parsedtype.rb
|
342
|
+
# $Id: parsedtype.rb 1125 2006-04-20 19:38:48Z luke $
|
@@ -35,7 +35,11 @@ module Puppet
|
|
35
35
|
# value.
|
36
36
|
def should
|
37
37
|
if defined? @should
|
38
|
-
|
38
|
+
if @should == [:absent]
|
39
|
+
return :absent
|
40
|
+
else
|
41
|
+
return @should
|
42
|
+
end
|
39
43
|
else
|
40
44
|
return []
|
41
45
|
end
|
@@ -52,9 +56,13 @@ module Puppet
|
|
52
56
|
end
|
53
57
|
|
54
58
|
munge do |value|
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
if value == :absent or value == "absent"
|
60
|
+
:absent
|
61
|
+
else
|
62
|
+
# Add the :alias metaparam in addition to the state
|
63
|
+
@parent.newmetaparam(@parent.class.metaparamclass(:alias), value)
|
64
|
+
value
|
65
|
+
end
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
@@ -133,4 +141,4 @@ module Puppet
|
|
133
141
|
end
|
134
142
|
end
|
135
143
|
|
136
|
-
# $Id: host.rb
|
144
|
+
# $Id: host.rb 1124 2006-04-20 07:00:10Z luke $
|
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'etc'
|
2
|
+
require 'facter'
|
3
|
+
require 'puppet/type/parsedtype'
|
4
|
+
require 'puppet/type/state'
|
5
|
+
|
6
|
+
module Puppet
|
7
|
+
newtype(:mount, Puppet::Type::ParsedType) do
|
8
|
+
ensurable do
|
9
|
+
desc "Create, remove, or mount a filesystem mount."
|
10
|
+
|
11
|
+
newvalue(:present) do
|
12
|
+
@parent.create()
|
13
|
+
end
|
14
|
+
|
15
|
+
newvalue(:absent) do
|
16
|
+
@parent.destroy()
|
17
|
+
|
18
|
+
if @parent.mounted?
|
19
|
+
@parent.unmount
|
20
|
+
end
|
21
|
+
|
22
|
+
:mount_removed
|
23
|
+
end
|
24
|
+
|
25
|
+
newvalue(:mounted) do
|
26
|
+
if @is == :absent
|
27
|
+
set_present
|
28
|
+
end
|
29
|
+
|
30
|
+
@parent.mount
|
31
|
+
|
32
|
+
:mount_mounted
|
33
|
+
end
|
34
|
+
|
35
|
+
def retrieve
|
36
|
+
if @parent.mounted?
|
37
|
+
@is = :mounted
|
38
|
+
else
|
39
|
+
val = super()
|
40
|
+
@is = val
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
newstate(:device) do
|
46
|
+
desc "The device providing the mount. This can be whatever
|
47
|
+
device is supporting by the mount, including network
|
48
|
+
devices or devices specified by UUID rather than device
|
49
|
+
path, depending on the operating system."
|
50
|
+
end
|
51
|
+
|
52
|
+
# Solaris specifies two devices, not just one.
|
53
|
+
newstate(:blockdevice) do
|
54
|
+
desc "The the device to fsck. This is state is only valid
|
55
|
+
on Solaris, and in most cases will default to the correct
|
56
|
+
value."
|
57
|
+
|
58
|
+
# Default to the device but with "dsk" replaced with "rdsk".
|
59
|
+
defaultto do
|
60
|
+
if Facter["operatingsystem"].value == "Solaris"
|
61
|
+
device = @parent.value(:device)
|
62
|
+
if device =~ %r{/dsk/}
|
63
|
+
device.sub(%r{/dsk/}, "/rdsk/")
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
newstate(:fstype) do
|
74
|
+
desc "The mount type. Valid values depend on the
|
75
|
+
operating system."
|
76
|
+
end
|
77
|
+
|
78
|
+
newstate(:options) do
|
79
|
+
desc "Mount options for the mounts, as they would
|
80
|
+
appear in the fstab."
|
81
|
+
end
|
82
|
+
|
83
|
+
newstate(:pass) do
|
84
|
+
desc "The pass in which the mount is checked."
|
85
|
+
end
|
86
|
+
|
87
|
+
newstate(:atboot) do
|
88
|
+
desc "Whether to mount the mount at boot. Not all platforms
|
89
|
+
support this."
|
90
|
+
end
|
91
|
+
|
92
|
+
newstate(:dump) do
|
93
|
+
desc "Whether to dump the mount. Not all platforms
|
94
|
+
support this."
|
95
|
+
end
|
96
|
+
|
97
|
+
newparam(:path) do
|
98
|
+
desc "The mount path for the mount."
|
99
|
+
|
100
|
+
isnamevar
|
101
|
+
end
|
102
|
+
|
103
|
+
@doc = "Manages mounted mounts, including putting mount
|
104
|
+
information into the mount table."
|
105
|
+
|
106
|
+
@instances = []
|
107
|
+
|
108
|
+
@platform = Facter["operatingsystem"].value
|
109
|
+
case @platform
|
110
|
+
when "Solaris":
|
111
|
+
@path = "/etc/vfstab"
|
112
|
+
@fields = [:device, :blockdevice, :path, :fstype, :pass, :atboot,
|
113
|
+
:options]
|
114
|
+
when "Darwin":
|
115
|
+
@filetype = Puppet::FileType.filetype(:netinfo)
|
116
|
+
@filetype.format = "fstab"
|
117
|
+
@path = "mounts"
|
118
|
+
@fields = [:device, :path, :fstype, :options, :dump, :pass]
|
119
|
+
|
120
|
+
# How to map the dumped table to what we want
|
121
|
+
@fieldnames = {
|
122
|
+
"name" => :device,
|
123
|
+
"dir" => :path,
|
124
|
+
"dump_freq" => :dump,
|
125
|
+
"passno" => :pass,
|
126
|
+
"vfstype" => :fstype,
|
127
|
+
"opts" => :options
|
128
|
+
}
|
129
|
+
else
|
130
|
+
@path = "/etc/fstab"
|
131
|
+
@fields = [:device, :path, :fstype, :options, :dump, :pass]
|
132
|
+
end
|
133
|
+
|
134
|
+
# Allow Darwin to override the default filetype
|
135
|
+
unless defined? @filetype
|
136
|
+
@filetype = Puppet::FileType.filetype(:flat)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Parse a mount tab.
|
140
|
+
#
|
141
|
+
# This method also stores existing comments, and it stores all
|
142
|
+
# mounts in order, mostly so that comments are retained in the
|
143
|
+
# order they were written and in proximity to the same fses.
|
144
|
+
def self.parse(text)
|
145
|
+
# provide a single exception for darwin & netinfo
|
146
|
+
if @filetype == Puppet::FileType.filetype(:netinfo)
|
147
|
+
parseninfo(text)
|
148
|
+
return
|
149
|
+
end
|
150
|
+
count = 0
|
151
|
+
hash = {}
|
152
|
+
text.chomp.split("\n").each { |line|
|
153
|
+
case line
|
154
|
+
when /^#/, /^\s*$/:
|
155
|
+
# add comments and blank lines to the list as they are
|
156
|
+
comment(line)
|
157
|
+
else
|
158
|
+
values = line.split(/\s+/)
|
159
|
+
unless @fields.length == values.length
|
160
|
+
raise Puppet::Error, "Could not parse line %s" % line
|
161
|
+
end
|
162
|
+
|
163
|
+
@fields.zip(values).each do |field, value|
|
164
|
+
hash[field] = value
|
165
|
+
end
|
166
|
+
|
167
|
+
hash2obj(hash)
|
168
|
+
|
169
|
+
hash.clear
|
170
|
+
count += 1
|
171
|
+
end
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
# Parse a netinfo table.
|
176
|
+
def self.parseninfo(text)
|
177
|
+
array = @fileobj.to_array(text)
|
178
|
+
|
179
|
+
hash = {}
|
180
|
+
array.each do |record|
|
181
|
+
@fieldnames.each do |name, field|
|
182
|
+
if value = record[name]
|
183
|
+
if field == :options
|
184
|
+
hash[field] = value.join(",")
|
185
|
+
else
|
186
|
+
hash[field] = value[0]
|
187
|
+
end
|
188
|
+
else
|
189
|
+
raise ArgumentError, "Field %s was not provided" % [name]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
hash2obj(hash)
|
195
|
+
hash.clear
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# This only works when the mount point is synced to the fstab.
|
200
|
+
def mount
|
201
|
+
output = %x{mount #{self[:path]} 2>&1}
|
202
|
+
|
203
|
+
unless $? == 0
|
204
|
+
raise Puppet::Error, "Could not mount %s: %s" % [self[:path], output]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# This only works when the mount point is synced to the fstab.
|
209
|
+
def unmount
|
210
|
+
output = %x{umount #{self[:path]}}
|
211
|
+
|
212
|
+
unless $? == 0
|
213
|
+
raise Puppet::Error, "Could not mount %s" % self[:path]
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# Is the mount currently mounted?
|
218
|
+
def mounted?
|
219
|
+
platform = Facter["operatingsystem"].value
|
220
|
+
df = "df"
|
221
|
+
case Facter["operatingsystem"].value
|
222
|
+
# Solaris's df prints in a very weird format
|
223
|
+
when "Solaris": df = "df -k"
|
224
|
+
end
|
225
|
+
%x{#{df}}.split("\n").find do |line|
|
226
|
+
fs = line.split(/\s+/)[-1]
|
227
|
+
if platform == "Darwin"
|
228
|
+
fs == "/private/var/automount" + self[:path] or
|
229
|
+
fs == self[:path]
|
230
|
+
else
|
231
|
+
fs == self[:path]
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# Convert the current object into an fstab-style string.
|
237
|
+
def to_record
|
238
|
+
self.class.fields.collect do |field|
|
239
|
+
if value = self.value(field)
|
240
|
+
value
|
241
|
+
else
|
242
|
+
raise Puppet::Error,
|
243
|
+
"Could not retrieve value for %s" % field
|
244
|
+
end
|
245
|
+
end.join("\t")
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# $Id: mount.rb 1113 2006-04-17 16:15:33Z luke $
|