puppet 0.9.2
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 +0 -0
- data/COPYING +340 -0
- data/LICENSE +17 -0
- data/README +24 -0
- data/Rakefile +294 -0
- data/TODO +4 -0
- data/bin/cf2puppet +186 -0
- data/bin/puppet +176 -0
- data/bin/puppetca +213 -0
- data/bin/puppetd +246 -0
- data/bin/puppetdoc +184 -0
- data/bin/puppetmasterd +258 -0
- data/examples/code/allatonce +13 -0
- data/examples/code/assignments +11 -0
- data/examples/code/classing +35 -0
- data/examples/code/components +73 -0
- data/examples/code/execs +16 -0
- data/examples/code/failers/badclassnoparam +10 -0
- data/examples/code/failers/badclassparam +10 -0
- data/examples/code/failers/badcompnoparam +9 -0
- data/examples/code/failers/badcompparam +9 -0
- data/examples/code/failers/badtypeparam +3 -0
- data/examples/code/file.bl +11 -0
- data/examples/code/filedefaults +10 -0
- data/examples/code/fileparsing +116 -0
- data/examples/code/filerecursion +15 -0
- data/examples/code/functions +3 -0
- data/examples/code/groups +7 -0
- data/examples/code/head +30 -0
- data/examples/code/importing +8 -0
- data/examples/code/nodes +20 -0
- data/examples/code/one +8 -0
- data/examples/code/relationships +34 -0
- data/examples/code/selectors +28 -0
- data/examples/code/simpletests +11 -0
- data/examples/code/snippets/argumentdefaults +14 -0
- data/examples/code/snippets/casestatement +39 -0
- data/examples/code/snippets/classheirarchy.pp +15 -0
- data/examples/code/snippets/classincludes.pp +17 -0
- data/examples/code/snippets/classpathtest +11 -0
- data/examples/code/snippets/dirchmod +19 -0
- data/examples/code/snippets/failmissingexecpath.pp +13 -0
- data/examples/code/snippets/falsevalues.pp +3 -0
- data/examples/code/snippets/filecreate +11 -0
- data/examples/code/snippets/implicititeration +15 -0
- data/examples/code/snippets/multipleinstances +7 -0
- data/examples/code/snippets/namevartest +9 -0
- data/examples/code/snippets/scopetest +13 -0
- data/examples/code/snippets/selectorvalues.pp +22 -0
- data/examples/code/snippets/simpledefaults +5 -0
- data/examples/code/snippets/simpleselector +38 -0
- data/examples/code/svncommit +13 -0
- data/examples/root/bin/sleeper +69 -0
- data/examples/root/etc/configfile +0 -0
- data/examples/root/etc/debian-passwd +29 -0
- data/examples/root/etc/debian-syslog.conf +71 -0
- data/examples/root/etc/init.d/sleeper +65 -0
- data/examples/root/etc/otherfile +0 -0
- data/examples/root/etc/puppet/fileserver.conf +3 -0
- data/examples/root/etc/puppet/puppetmasterd.conf +10 -0
- data/ext/module:puppet +195 -0
- data/install.rb +270 -0
- data/lib/puppet.rb +249 -0
- data/lib/puppet/base64.rb +19 -0
- data/lib/puppet/client.rb +519 -0
- data/lib/puppet/config.rb +49 -0
- data/lib/puppet/daemon.rb +208 -0
- data/lib/puppet/element.rb +71 -0
- data/lib/puppet/event.rb +259 -0
- data/lib/puppet/log.rb +321 -0
- data/lib/puppet/metric.rb +250 -0
- data/lib/puppet/parsedfile.rb +38 -0
- data/lib/puppet/parser/ast.rb +1560 -0
- data/lib/puppet/parser/interpreter.rb +150 -0
- data/lib/puppet/parser/lexer.rb +226 -0
- data/lib/puppet/parser/parser.rb +1354 -0
- data/lib/puppet/parser/scope.rb +755 -0
- data/lib/puppet/server.rb +170 -0
- data/lib/puppet/server/authstore.rb +227 -0
- data/lib/puppet/server/ca.rb +140 -0
- data/lib/puppet/server/filebucket.rb +147 -0
- data/lib/puppet/server/fileserver.rb +477 -0
- data/lib/puppet/server/logger.rb +43 -0
- data/lib/puppet/server/master.rb +103 -0
- data/lib/puppet/server/servlet.rb +247 -0
- data/lib/puppet/sslcertificates.rb +737 -0
- data/lib/puppet/statechange.rb +150 -0
- data/lib/puppet/storage.rb +95 -0
- data/lib/puppet/transaction.rb +179 -0
- data/lib/puppet/transportable.rb +151 -0
- data/lib/puppet/type.rb +1354 -0
- data/lib/puppet/type/component.rb +141 -0
- data/lib/puppet/type/cron.rb +543 -0
- data/lib/puppet/type/exec.rb +316 -0
- data/lib/puppet/type/group.rb +152 -0
- data/lib/puppet/type/nameservice.rb +3 -0
- data/lib/puppet/type/nameservice/netinfo.rb +173 -0
- data/lib/puppet/type/nameservice/objectadd.rb +146 -0
- data/lib/puppet/type/nameservice/posix.rb +200 -0
- data/lib/puppet/type/package.rb +420 -0
- data/lib/puppet/type/package/apt.rb +70 -0
- data/lib/puppet/type/package/dpkg.rb +108 -0
- data/lib/puppet/type/package/rpm.rb +81 -0
- data/lib/puppet/type/package/sun.rb +117 -0
- data/lib/puppet/type/package/yum.rb +58 -0
- data/lib/puppet/type/pfile.rb +569 -0
- data/lib/puppet/type/pfile/checksum.rb +219 -0
- data/lib/puppet/type/pfile/create.rb +108 -0
- data/lib/puppet/type/pfile/group.rb +129 -0
- data/lib/puppet/type/pfile/mode.rb +131 -0
- data/lib/puppet/type/pfile/source.rb +264 -0
- data/lib/puppet/type/pfile/type.rb +31 -0
- data/lib/puppet/type/pfile/uid.rb +166 -0
- data/lib/puppet/type/pfilebucket.rb +80 -0
- data/lib/puppet/type/pprocess.rb +97 -0
- data/lib/puppet/type/service.rb +347 -0
- data/lib/puppet/type/service/base.rb +17 -0
- data/lib/puppet/type/service/debian.rb +50 -0
- data/lib/puppet/type/service/init.rb +145 -0
- data/lib/puppet/type/service/smf.rb +29 -0
- data/lib/puppet/type/state.rb +182 -0
- data/lib/puppet/type/symlink.rb +183 -0
- data/lib/puppet/type/tidy.rb +183 -0
- data/lib/puppet/type/typegen.rb +149 -0
- data/lib/puppet/type/typegen/filerecord.rb +243 -0
- data/lib/puppet/type/typegen/filetype.rb +316 -0
- data/lib/puppet/type/user.rb +290 -0
- data/lib/puppet/util.rb +138 -0
- data/test/certmgr/certmgr.rb +265 -0
- data/test/client/client.rb +203 -0
- data/test/executables/puppetbin.rb +53 -0
- data/test/executables/puppetca.rb +79 -0
- data/test/executables/puppetd.rb +71 -0
- data/test/executables/puppetmasterd.rb +153 -0
- data/test/executables/puppetmodule.rb +60 -0
- data/test/language/ast.rb +412 -0
- data/test/language/interpreter.rb +71 -0
- data/test/language/scope.rb +412 -0
- data/test/language/snippets.rb +445 -0
- data/test/other/events.rb +111 -0
- data/test/other/log.rb +195 -0
- data/test/other/metrics.rb +92 -0
- data/test/other/overrides.rb +115 -0
- data/test/other/parsedfile.rb +31 -0
- data/test/other/relationships.rb +113 -0
- data/test/other/state.rb +106 -0
- data/test/other/storage.rb +39 -0
- data/test/other/transactions.rb +235 -0
- data/test/parser/lexer.rb +120 -0
- data/test/parser/parser.rb +180 -0
- data/test/puppet/conffiles.rb +104 -0
- data/test/puppet/defaults.rb +100 -0
- data/test/puppet/error.rb +23 -0
- data/test/puppet/utiltest.rb +120 -0
- data/test/puppettest.rb +774 -0
- data/test/server/authstore.rb +209 -0
- data/test/server/bucket.rb +227 -0
- data/test/server/ca.rb +201 -0
- data/test/server/fileserver.rb +710 -0
- data/test/server/logger.rb +175 -0
- data/test/server/master.rb +150 -0
- data/test/server/server.rb +130 -0
- data/test/tagging/tagging.rb +80 -0
- data/test/test +51 -0
- data/test/types/basic.rb +119 -0
- data/test/types/component.rb +272 -0
- data/test/types/cron.rb +261 -0
- data/test/types/exec.rb +273 -0
- data/test/types/file.rb +616 -0
- data/test/types/filebucket.rb +167 -0
- data/test/types/fileignoresource.rb +287 -0
- data/test/types/filesources.rb +587 -0
- data/test/types/filetype.rb +162 -0
- data/test/types/group.rb +271 -0
- data/test/types/package.rb +205 -0
- data/test/types/query.rb +101 -0
- data/test/types/service.rb +100 -0
- data/test/types/symlink.rb +93 -0
- data/test/types/tidy.rb +124 -0
- data/test/types/type.rb +135 -0
- data/test/types/user.rb +371 -0
- metadata +243 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# $Id: tidy.rb 731 2005-10-26 04:44:25Z luke $
|
4
|
+
|
5
|
+
require 'etc'
|
6
|
+
require 'puppet/type/state'
|
7
|
+
require 'puppet/type/pfile'
|
8
|
+
|
9
|
+
module Puppet
|
10
|
+
# okay, how do we deal with parameters that don't have operations
|
11
|
+
# associated with them?
|
12
|
+
class State
|
13
|
+
class TidyUp < Puppet::State
|
14
|
+
require 'etc'
|
15
|
+
|
16
|
+
@nodoc = true
|
17
|
+
@name = :tidyup
|
18
|
+
|
19
|
+
def age(stat)
|
20
|
+
type = nil
|
21
|
+
if stat.ftype == "directory"
|
22
|
+
type = :mtime
|
23
|
+
else
|
24
|
+
type = @parent[:type] || :atime
|
25
|
+
end
|
26
|
+
|
27
|
+
return Integer(Time.now - stat.send(type))
|
28
|
+
end
|
29
|
+
|
30
|
+
def retrieve
|
31
|
+
stat = nil
|
32
|
+
unless stat = @parent.stat
|
33
|
+
@is = :unknown
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
@is = [:age, :size].collect { |param|
|
38
|
+
if @parent[param]
|
39
|
+
self.send(param, stat)
|
40
|
+
end
|
41
|
+
}.reject { |p| p == false or p.nil? }
|
42
|
+
end
|
43
|
+
|
44
|
+
def size(stat)
|
45
|
+
return stat.size
|
46
|
+
end
|
47
|
+
|
48
|
+
def sync
|
49
|
+
file = @parent[:path]
|
50
|
+
case File.lstat(file).ftype
|
51
|
+
when "directory":
|
52
|
+
if @parent[:rmdirs]
|
53
|
+
subs = Dir.entries(@parent[:path]).reject { |d|
|
54
|
+
d == "." or d == ".."
|
55
|
+
}.length
|
56
|
+
if subs > 0
|
57
|
+
self.info "%s has %s children; not tidying" %
|
58
|
+
[@parent[:path], subs]
|
59
|
+
self.info Dir.entries(@parent[:path]).inspect
|
60
|
+
else
|
61
|
+
Dir.rmdir(@parent[:path])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
self.debug "Not tidying directories"
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
when "file":
|
68
|
+
@parent.handlebackup(file)
|
69
|
+
File.unlink(file)
|
70
|
+
when "symlink": File.unlink(file)
|
71
|
+
else
|
72
|
+
raise Puppet::Error, "Cannot tidy files of type %s" %
|
73
|
+
File.lstat(file).ftype
|
74
|
+
end
|
75
|
+
|
76
|
+
return :file_tidied
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Type
|
82
|
+
class Tidy < PFile
|
83
|
+
|
84
|
+
# class instance variable
|
85
|
+
@states = [
|
86
|
+
Puppet::State::TidyUp
|
87
|
+
]
|
88
|
+
|
89
|
+
@parameters = [
|
90
|
+
:path,
|
91
|
+
:age,
|
92
|
+
:size,
|
93
|
+
:type,
|
94
|
+
:backup,
|
95
|
+
:rmdirs,
|
96
|
+
:recurse
|
97
|
+
]
|
98
|
+
|
99
|
+
@paramdoc[:age] = "Tidy files whose age is equal to or greater than
|
100
|
+
the specified number of days."
|
101
|
+
@paramdoc[:size] = "Tidy files whose size is equal to or greater than
|
102
|
+
the specified size. Unqualified values are in kilobytes, but
|
103
|
+
*b*, *k*, and *m* can be appended to specify *bytes*, *kilobytes*,
|
104
|
+
and *megabytes*, respectively. Only the first character is
|
105
|
+
significant, so the full word can also be used."
|
106
|
+
@paramdoc[:type] = "Set the mechanism for determining age. Access
|
107
|
+
time is the default mechanism, but modification."
|
108
|
+
@paramdoc[:recurse] = "If target is a directory, recursively descend
|
109
|
+
into the directory looking for files to tidy."
|
110
|
+
@paramdoc[:rmdirs] = "Tidy directories in addition to files."
|
111
|
+
@doc = "Remove unwanted files based on specific criteria."
|
112
|
+
@name = :tidy
|
113
|
+
@namevar = :path
|
114
|
+
|
115
|
+
@depthfirst = true
|
116
|
+
|
117
|
+
def initialize(hash)
|
118
|
+
super
|
119
|
+
|
120
|
+
unless @parameters.include?(:age) or
|
121
|
+
@parameters.include?(:size)
|
122
|
+
unless FileTest.directory?(self[:path])
|
123
|
+
# don't do size comparisons for directories
|
124
|
+
raise Puppet::Error, "Tidy must specify size, age, or both"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# only allow backing up into filebuckets
|
129
|
+
unless self[:backup].is_a? Puppet::Client::Dipper
|
130
|
+
self[:backup] = false
|
131
|
+
end
|
132
|
+
self[:tidyup] = [:age, :size].collect { |param|
|
133
|
+
@parameters[param]
|
134
|
+
}.reject { |p| p == false }
|
135
|
+
end
|
136
|
+
|
137
|
+
def paramage=(age)
|
138
|
+
@parameters[:age] = age
|
139
|
+
case age
|
140
|
+
when /^[0-9]+$/, /^[0-9]+[dD]/:
|
141
|
+
@parameters[:age] = Integer(age.gsub(/[^0-9]+/,'')) *
|
142
|
+
60 * 60 * 24
|
143
|
+
when /^[0-9]+$/, /^[0-9]+[hH]/:
|
144
|
+
@parameters[:age] = Integer(age.gsub(/[^0-9]+/,'')) * 60 * 60
|
145
|
+
when /^[0-9]+[mM]/:
|
146
|
+
@parameters[:age] = Integer(age.gsub(/[^0-9]+/,'')) * 60
|
147
|
+
when /^[0-9]+[sS]/:
|
148
|
+
@parameters[:age] = Integer(age.gsub(/[^0-9]+/,''))
|
149
|
+
else
|
150
|
+
raise Puppet::Error.new("Invalid tidy age %s" % age)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def paramsize=(size)
|
155
|
+
if FileTest.directory?(self[:path])
|
156
|
+
# don't do size comparisons for directories
|
157
|
+
return
|
158
|
+
end
|
159
|
+
case size
|
160
|
+
when /^[0-9]+$/, /^[0-9]+[kK]/:
|
161
|
+
@parameters[:size] = Integer(size.gsub(/[^0-9]+/,'')) * 1024
|
162
|
+
when /^[0-9]+[bB]/:
|
163
|
+
@parameters[:size] = Integer(size.gsub(/[^0-9]+/,''))
|
164
|
+
when /^[0-9]+[mM]/:
|
165
|
+
@parameters[:size] = Integer(size.gsub(/[^0-9]+/,'')) *
|
166
|
+
1024 * 1024
|
167
|
+
else
|
168
|
+
raise Puppet::Error.new("Invalid tidy size %s" % size)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def paramtype=(type)
|
173
|
+
case type
|
174
|
+
when "atime", "mtime", "ctime":
|
175
|
+
@parameters[:type] = type.intern
|
176
|
+
else
|
177
|
+
raise Puppet::Error.new("Invalid tidy type %s" % type)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end # Puppet::Type::Symlink
|
182
|
+
end # Puppet::Type
|
183
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# $Id: typegen.rb 576 2005-08-23 16:09:14Z luke $
|
4
|
+
|
5
|
+
# parse and write configuration files using objects with minimal parsing abilities
|
6
|
+
|
7
|
+
require 'etc'
|
8
|
+
require 'puppet/type'
|
9
|
+
|
10
|
+
module Puppet
|
11
|
+
class Type
|
12
|
+
class TypeGenerator < Puppet::Type
|
13
|
+
include Enumerable
|
14
|
+
|
15
|
+
@doc = "..."
|
16
|
+
@namevar = :name
|
17
|
+
@name = :typegen
|
18
|
+
@abstract = true
|
19
|
+
|
20
|
+
@parameters = [:name]
|
21
|
+
@states = []
|
22
|
+
|
23
|
+
@paramdoc[:name] = "..."
|
24
|
+
|
25
|
+
#---------------------------------------------------------------
|
26
|
+
def TypeGenerator.[](name)
|
27
|
+
return @subclasses[name]
|
28
|
+
end
|
29
|
+
#---------------------------------------------------------------
|
30
|
+
|
31
|
+
#---------------------------------------------------------------
|
32
|
+
def TypeGenerator.inherited(subclass)
|
33
|
+
#subclass.initvars
|
34
|
+
super(subclass)
|
35
|
+
end
|
36
|
+
#---------------------------------------------------------------
|
37
|
+
|
38
|
+
#---------------------------------------------------------------
|
39
|
+
# we don't need to 'super' here because type.rb already runs initvars
|
40
|
+
# in Type#inherited
|
41
|
+
def TypeGenerator.initvars
|
42
|
+
@subclasses = Hash.new(nil)
|
43
|
+
super
|
44
|
+
end
|
45
|
+
#---------------------------------------------------------------
|
46
|
+
|
47
|
+
#---------------------------------------------------------------
|
48
|
+
def TypeGenerator.name
|
49
|
+
return @name
|
50
|
+
end
|
51
|
+
#---------------------------------------------------------------
|
52
|
+
|
53
|
+
#---------------------------------------------------------------
|
54
|
+
def TypeGenerator.name=(name)
|
55
|
+
@name = name
|
56
|
+
end
|
57
|
+
#---------------------------------------------------------------
|
58
|
+
|
59
|
+
#---------------------------------------------------------------
|
60
|
+
def TypeGenerator.namevar
|
61
|
+
return @namevar || :name
|
62
|
+
end
|
63
|
+
#---------------------------------------------------------------
|
64
|
+
|
65
|
+
#---------------------------------------------------------------
|
66
|
+
def TypeGenerator.namevar=(namevar)
|
67
|
+
debug "Setting namevar for %s to %s" % [self,namevar]
|
68
|
+
unless namevar.is_a? Symbol
|
69
|
+
namevar = namevar.intern
|
70
|
+
end
|
71
|
+
@namevar = namevar
|
72
|
+
end
|
73
|
+
#---------------------------------------------------------------
|
74
|
+
|
75
|
+
#---------------------------------------------------------------
|
76
|
+
def TypeGenerator.newtype(arghash)
|
77
|
+
unless defined? @parameters
|
78
|
+
raise "Type %s is set up incorrectly" % self
|
79
|
+
end
|
80
|
+
|
81
|
+
arghash.each { |key,value|
|
82
|
+
if key.class != Symbol
|
83
|
+
# convert to a symbol
|
84
|
+
arghash[key.intern] = value
|
85
|
+
arghash.delete key
|
86
|
+
key = key.intern
|
87
|
+
end
|
88
|
+
unless @parameters.include?(key)
|
89
|
+
raise "Invalid argument %s on class %s" %
|
90
|
+
[key,self]
|
91
|
+
end
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
# turn off automatically checking all arguments
|
96
|
+
#@parameters.each { |option|
|
97
|
+
# unless arghash.include?(option)
|
98
|
+
# p arghash
|
99
|
+
# raise "Must pass %s to class %s" %
|
100
|
+
# [option,self]
|
101
|
+
# end
|
102
|
+
#}
|
103
|
+
|
104
|
+
if @subclasses.include?(arghash[:name])
|
105
|
+
raise "File type %s already exists" % arghash[:name]
|
106
|
+
end
|
107
|
+
|
108
|
+
klassname = arghash[:name].capitalize
|
109
|
+
|
110
|
+
# create the file type
|
111
|
+
Puppet::Type.module_eval "
|
112
|
+
class %s < %s
|
113
|
+
end" % [klassname,self]
|
114
|
+
klass = eval(klassname)
|
115
|
+
klass.name = arghash[:name]
|
116
|
+
|
117
|
+
@subclasses[arghash[:name]] = klass
|
118
|
+
|
119
|
+
arghash.each { |option,value|
|
120
|
+
method = option.id2name + "="
|
121
|
+
if klass.respond_to?(method)
|
122
|
+
#debug "Setting %s on %s to '%s'" % [option,klass,arghash[option]]
|
123
|
+
klass.send(method,arghash[option])
|
124
|
+
else
|
125
|
+
debug "%s does not respond to %s" % [klass,method]
|
126
|
+
end
|
127
|
+
}
|
128
|
+
|
129
|
+
# i couldn't get the method definition stuff to work
|
130
|
+
# oh well
|
131
|
+
# probably wouldn't want it in the end anyway
|
132
|
+
#@parameters.each { |option|
|
133
|
+
# writer = option.id2name + "="
|
134
|
+
# readproc = proc { eval("@" + option.id2name) }
|
135
|
+
# klass.send(:define_method,option,readproc)
|
136
|
+
# writeproc = proc { |value| module_eval("@" + option.id2name) = value }
|
137
|
+
# klass.send(:define_method,writer,writeproc)
|
138
|
+
# klass.send(writer,hash[option])
|
139
|
+
#}
|
140
|
+
|
141
|
+
#Puppet::Type.inherited(klass)
|
142
|
+
Puppet::Type.buildtypehash
|
143
|
+
return klass
|
144
|
+
end
|
145
|
+
#---------------------------------------------------------------
|
146
|
+
end
|
147
|
+
#---------------------------------------------------------------
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,243 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# $Id: filerecord.rb 576 2005-08-23 16:09:14Z luke $
|
4
|
+
|
5
|
+
# parse and write configuration files using objects with minimal parsing abilities
|
6
|
+
|
7
|
+
require 'etc'
|
8
|
+
require 'puppet/type'
|
9
|
+
require 'puppet/type/typegen'
|
10
|
+
|
11
|
+
#---------------------------------------------------------------
|
12
|
+
class Puppet::Type::FileRecord < Puppet::Type::TypeGenerator
|
13
|
+
attr_accessor :fields, :namevar, :splitchar, :object
|
14
|
+
|
15
|
+
@parameters = [:name, :splitchar, :fields, :namevar, :filetype, :regex, :joinchar]
|
16
|
+
@abstract = true
|
17
|
+
@metaclass = true
|
18
|
+
|
19
|
+
@namevar = :name
|
20
|
+
@name = :filerecord
|
21
|
+
|
22
|
+
#---------------------------------------------------------------
|
23
|
+
def FileRecord.newtype(hash)
|
24
|
+
#shortname = hash[:name]
|
25
|
+
#hash[:name] = hash[:filetype].name.capitalize + hash[:name].capitalize
|
26
|
+
klass = super(hash)
|
27
|
+
#klass.name = shortname
|
28
|
+
klass.parameters = hash[:fields]
|
29
|
+
#klass.namevar = hash[:namevar]
|
30
|
+
klass.filetype = hash[:filetype]
|
31
|
+
hash.delete(:fields)
|
32
|
+
hash.delete(:namevar)
|
33
|
+
return klass
|
34
|
+
end
|
35
|
+
#---------------------------------------------------------------
|
36
|
+
|
37
|
+
#---------------------------------------------------------------
|
38
|
+
def FileRecord.fields=(ary)
|
39
|
+
@fields = ary
|
40
|
+
end
|
41
|
+
#---------------------------------------------------------------
|
42
|
+
|
43
|
+
#---------------------------------------------------------------
|
44
|
+
def FileRecord.fields
|
45
|
+
return @fields
|
46
|
+
end
|
47
|
+
#---------------------------------------------------------------
|
48
|
+
|
49
|
+
#---------------------------------------------------------------
|
50
|
+
def FileRecord.filetype
|
51
|
+
@filetype
|
52
|
+
end
|
53
|
+
#---------------------------------------------------------------
|
54
|
+
|
55
|
+
#---------------------------------------------------------------
|
56
|
+
def FileRecord.filetype=(filetype)
|
57
|
+
if filetype.is_a?(String)
|
58
|
+
@filetype = Puppet::Type::FileType[filetype]
|
59
|
+
elsif filetype.is_a?(Puppet::Type::FileType)
|
60
|
+
@filetype = filetype
|
61
|
+
else
|
62
|
+
raise "Cannot use objects of type %s as filetypes" % filetype
|
63
|
+
end
|
64
|
+
end
|
65
|
+
#---------------------------------------------------------------
|
66
|
+
|
67
|
+
#---------------------------------------------------------------
|
68
|
+
def FileRecord.joinchar=(char)
|
69
|
+
@joinchar = char
|
70
|
+
end
|
71
|
+
#---------------------------------------------------------------
|
72
|
+
|
73
|
+
#---------------------------------------------------------------
|
74
|
+
def FileRecord.joinchar
|
75
|
+
unless defined? @joinchar
|
76
|
+
@joinchar = nil
|
77
|
+
end
|
78
|
+
@joinchar
|
79
|
+
end
|
80
|
+
#---------------------------------------------------------------
|
81
|
+
|
82
|
+
#---------------------------------------------------------------
|
83
|
+
def FileRecord.match(object,line)
|
84
|
+
matchobj = nil
|
85
|
+
begin
|
86
|
+
matchobj = self.regex.match(line)
|
87
|
+
rescue RegexpError => detail
|
88
|
+
raise
|
89
|
+
end
|
90
|
+
|
91
|
+
if matchobj.nil?
|
92
|
+
return nil
|
93
|
+
else
|
94
|
+
child = self.new(object)
|
95
|
+
child.match = matchobj
|
96
|
+
return child
|
97
|
+
end
|
98
|
+
end
|
99
|
+
#---------------------------------------------------------------
|
100
|
+
|
101
|
+
#---------------------------------------------------------------
|
102
|
+
def FileRecord.regex=(regex)
|
103
|
+
@regex = regex
|
104
|
+
end
|
105
|
+
#---------------------------------------------------------------
|
106
|
+
|
107
|
+
#---------------------------------------------------------------
|
108
|
+
def FileRecord.regex
|
109
|
+
# the only time @regex is allowed to be nil is if @splitchar is defined
|
110
|
+
if @regex.nil?
|
111
|
+
if @splitchar.nil?
|
112
|
+
raise "%s defined incorrectly -- splitchar or regex must be specified" %
|
113
|
+
self
|
114
|
+
else
|
115
|
+
ary = []
|
116
|
+
text = @fields.collect { |field|
|
117
|
+
"([^%s]*)" % @splitchar
|
118
|
+
}.join(@splitchar)
|
119
|
+
begin
|
120
|
+
@regex = Regexp.new(text)
|
121
|
+
rescue RegexpError => detail
|
122
|
+
raise "Could not create splitregex from %s" % @splitchar
|
123
|
+
end
|
124
|
+
debug("Created regexp %s" % @regex)
|
125
|
+
end
|
126
|
+
elsif @regex.is_a?(String)
|
127
|
+
begin
|
128
|
+
@regex = Regexp.new(@regex)
|
129
|
+
rescue RegexpError => detail
|
130
|
+
raise "Could not create splitregex from %s" % @regex
|
131
|
+
end
|
132
|
+
end
|
133
|
+
return @regex
|
134
|
+
end
|
135
|
+
#---------------------------------------------------------------
|
136
|
+
|
137
|
+
#---------------------------------------------------------------
|
138
|
+
def FileRecord.splitchar=(char)
|
139
|
+
@splitchar = char
|
140
|
+
#@regex = %r{#{char}}
|
141
|
+
end
|
142
|
+
#---------------------------------------------------------------
|
143
|
+
|
144
|
+
#---------------------------------------------------------------
|
145
|
+
def FileRecord.splitchar
|
146
|
+
return @splitchar
|
147
|
+
end
|
148
|
+
#---------------------------------------------------------------
|
149
|
+
|
150
|
+
#---------------------------------------------------------------
|
151
|
+
#def [](field)
|
152
|
+
# @parameters[field]
|
153
|
+
#end
|
154
|
+
#---------------------------------------------------------------
|
155
|
+
|
156
|
+
#---------------------------------------------------------------
|
157
|
+
#def []=(field,value)
|
158
|
+
# @parameters[field] = value
|
159
|
+
#end
|
160
|
+
#---------------------------------------------------------------
|
161
|
+
|
162
|
+
#---------------------------------------------------------------
|
163
|
+
def ==(other)
|
164
|
+
unless self.class == other.class
|
165
|
+
return false
|
166
|
+
end
|
167
|
+
|
168
|
+
unless self.name == other.name
|
169
|
+
return false
|
170
|
+
end
|
171
|
+
@parameters.keys { |field|
|
172
|
+
unless self[field] == other[field]
|
173
|
+
debug("%s -> %s has changed" % [self.name, field])
|
174
|
+
return false
|
175
|
+
end
|
176
|
+
}
|
177
|
+
return true
|
178
|
+
end
|
179
|
+
#---------------------------------------------------------------
|
180
|
+
|
181
|
+
#---------------------------------------------------------------
|
182
|
+
def initialize(hash)
|
183
|
+
if self.class == Puppet::Type::FileRecord
|
184
|
+
self.class.newtype(hash)
|
185
|
+
return
|
186
|
+
end
|
187
|
+
@parameters = {}
|
188
|
+
#if block_given?
|
189
|
+
# yield self
|
190
|
+
#end
|
191
|
+
super(hash)
|
192
|
+
end
|
193
|
+
#---------------------------------------------------------------
|
194
|
+
|
195
|
+
#---------------------------------------------------------------
|
196
|
+
def match=(matchobj)
|
197
|
+
@match = matchobj
|
198
|
+
#puts "captures are [%s]" % [matchobj.captures]
|
199
|
+
self.class.fields.zip(matchobj.captures) { |field,value|
|
200
|
+
@parameters[field] = value
|
201
|
+
#puts "%s => %s" % [field,@parameters[field]]
|
202
|
+
}
|
203
|
+
end
|
204
|
+
#---------------------------------------------------------------
|
205
|
+
|
206
|
+
#---------------------------------------------------------------
|
207
|
+
def record=(record)
|
208
|
+
begin
|
209
|
+
ary = record.split(self.class.regex)
|
210
|
+
rescue RegexpError=> detail
|
211
|
+
raise RegexpError.new(detail)
|
212
|
+
end
|
213
|
+
self.class.fields.each { |field|
|
214
|
+
@parameters[field] = ary.shift
|
215
|
+
#puts "%s => %s" % [field,@parameters[field]]
|
216
|
+
}
|
217
|
+
end
|
218
|
+
#---------------------------------------------------------------
|
219
|
+
|
220
|
+
#---------------------------------------------------------------
|
221
|
+
def name
|
222
|
+
if @parameters.include?(self.class.namevar)
|
223
|
+
return @parameters[self.class.namevar]
|
224
|
+
else
|
225
|
+
raise "No namevar '%s' for objects of type %s" %
|
226
|
+
[self.class.namevar,self.class.to_s]
|
227
|
+
end
|
228
|
+
end
|
229
|
+
#---------------------------------------------------------------
|
230
|
+
|
231
|
+
#---------------------------------------------------------------
|
232
|
+
def to_s
|
233
|
+
ary = self.class.fields.collect { |field|
|
234
|
+
if ! @parameters.include?(field)
|
235
|
+
raise "Object %s is missing field %s" % [self.name,field]
|
236
|
+
else
|
237
|
+
@parameters[field]
|
238
|
+
end
|
239
|
+
}.join(self.class.joinchar || self.class.splitchar)
|
240
|
+
end
|
241
|
+
#---------------------------------------------------------------
|
242
|
+
end
|
243
|
+
#---------------------------------------------------------------
|