puppet 0.9.2 → 0.13.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 +58 -0
- data/README +21 -18
- data/Rakefile +176 -36
- data/bin/puppet +34 -48
- data/bin/puppetca +41 -28
- data/bin/puppetd +87 -65
- data/bin/puppetdoc +99 -23
- data/bin/puppetmasterd +72 -91
- data/conf/redhat/client.init +80 -0
- data/conf/redhat/client.sysconfig +11 -0
- data/conf/redhat/fileserver.conf +12 -0
- data/conf/redhat/puppet.spec +130 -0
- data/conf/redhat/server.init +89 -0
- data/conf/redhat/server.sysconfig +9 -0
- data/examples/code/allatonce +2 -2
- data/examples/code/assignments +1 -1
- data/examples/code/classing +2 -2
- data/examples/code/components +2 -2
- data/examples/code/file.bl +5 -5
- data/examples/code/filedefaults +2 -2
- data/examples/code/fileparsing +1 -1
- data/examples/code/filerecursion +1 -1
- data/examples/code/functions +1 -1
- data/examples/code/groups +1 -1
- data/examples/code/importing +1 -1
- data/examples/code/nodes +1 -1
- data/examples/code/one +1 -1
- data/examples/code/relationships +2 -2
- data/examples/code/simpletests +5 -5
- data/examples/code/snippets/argumentdefaults +2 -2
- data/examples/code/snippets/casestatement +16 -8
- data/examples/code/snippets/classheirarchy.pp +4 -4
- data/examples/code/snippets/classincludes.pp +4 -4
- data/examples/code/snippets/classpathtest +2 -2
- data/examples/code/snippets/componentmetaparams.pp +11 -0
- data/examples/code/snippets/dirchmod +5 -5
- data/examples/code/snippets/emptyclass.pp +9 -0
- data/examples/code/snippets/failmissingexecpath.pp +1 -1
- data/examples/code/snippets/falsevalues.pp +1 -1
- data/examples/code/snippets/filecreate +5 -5
- data/examples/code/snippets/implicititeration +5 -5
- data/examples/code/snippets/multipleinstances +4 -4
- data/examples/code/snippets/namevartest +3 -3
- data/examples/code/snippets/scopetest +1 -1
- data/examples/code/snippets/selectorvalues.pp +3 -3
- data/examples/code/snippets/simpledefaults +2 -2
- data/examples/code/snippets/simpleselector +5 -5
- data/examples/code/snippets/singleary.pp +19 -0
- data/examples/root/etc/init.d/sleeper +3 -2
- data/ext/emacs/puppet-mode-init.el +6 -0
- data/ext/emacs/puppet-mode.el +189 -0
- data/ext/ldap/puppet.schema +17 -0
- data/ext/{module:puppet → module_puppet} +30 -31
- data/ext/vim/filetype.vim +9 -0
- data/ext/vim/puppet.vim +87 -0
- data/install.rb +63 -30
- data/lib/puppet.rb +216 -122
- data/lib/puppet/client.rb +51 -416
- data/lib/puppet/client/ca.rb +17 -0
- data/lib/puppet/client/dipper.rb +78 -0
- data/lib/puppet/client/file.rb +20 -0
- data/lib/puppet/client/log.rb +17 -0
- data/lib/puppet/client/master.rb +246 -0
- data/lib/puppet/client/proxy.rb +27 -0
- data/lib/puppet/client/status.rb +7 -0
- data/lib/puppet/config.rb +563 -13
- data/lib/puppet/daemon.rb +50 -22
- data/lib/puppet/element.rb +4 -4
- data/lib/puppet/event-loop.rb +1 -0
- data/lib/puppet/event-loop/better-definers.rb +367 -0
- data/lib/puppet/event-loop/event-loop.rb +355 -0
- data/lib/puppet/event-loop/signal-system.rb +220 -0
- data/lib/puppet/event.rb +9 -11
- data/lib/puppet/filetype.rb +195 -0
- data/lib/puppet/log.rb +35 -12
- data/lib/puppet/metric.rb +2 -2
- data/lib/puppet/networkclient.rb +145 -0
- data/lib/puppet/parameter.rb +335 -0
- data/lib/puppet/parser/ast.rb +42 -1453
- data/lib/puppet/parser/ast/astarray.rb +88 -0
- data/lib/puppet/parser/ast/branch.rb +47 -0
- data/lib/puppet/parser/ast/caseopt.rb +66 -0
- data/lib/puppet/parser/ast/casestatement.rb +78 -0
- data/lib/puppet/parser/ast/classdef.rb +78 -0
- data/lib/puppet/parser/ast/compdef.rb +111 -0
- data/lib/puppet/parser/ast/component.rb +105 -0
- data/lib/puppet/parser/ast/hostclass.rb +82 -0
- data/lib/puppet/parser/ast/leaf.rb +86 -0
- data/lib/puppet/parser/ast/node.rb +103 -0
- data/lib/puppet/parser/ast/nodedef.rb +68 -0
- data/lib/puppet/parser/ast/objectdef.rb +336 -0
- data/lib/puppet/parser/ast/objectparam.rb +30 -0
- data/lib/puppet/parser/ast/objectref.rb +76 -0
- data/lib/puppet/parser/ast/selector.rb +60 -0
- data/lib/puppet/parser/ast/typedefaults.rb +45 -0
- data/lib/puppet/parser/ast/vardef.rb +44 -0
- data/lib/puppet/parser/interpreter.rb +31 -14
- data/lib/puppet/parser/lexer.rb +2 -4
- data/lib/puppet/parser/parser.rb +332 -242
- data/lib/puppet/parser/scope.rb +55 -38
- data/lib/puppet/server.rb +43 -44
- data/lib/puppet/server/authstore.rb +3 -6
- data/lib/puppet/server/ca.rb +5 -2
- data/lib/puppet/server/filebucket.rb +2 -4
- data/lib/puppet/server/fileserver.rb +28 -12
- data/lib/puppet/server/logger.rb +15 -4
- data/lib/puppet/server/master.rb +62 -7
- data/lib/puppet/sslcertificates.rb +41 -607
- data/lib/puppet/sslcertificates/ca.rb +291 -0
- data/lib/puppet/sslcertificates/certificate.rb +283 -0
- data/lib/puppet/statechange.rb +6 -1
- data/lib/puppet/storage.rb +67 -56
- data/lib/puppet/transaction.rb +25 -9
- data/lib/puppet/transportable.rb +102 -22
- data/lib/puppet/type.rb +1096 -315
- data/lib/puppet/type/component.rb +30 -21
- data/lib/puppet/type/cron.rb +409 -448
- data/lib/puppet/type/exec.rb +234 -174
- data/lib/puppet/type/group.rb +65 -82
- data/lib/puppet/type/nameservice.rb +247 -3
- data/lib/puppet/type/nameservice/netinfo.rb +29 -40
- data/lib/puppet/type/nameservice/objectadd.rb +52 -66
- data/lib/puppet/type/nameservice/posix.rb +6 -194
- data/lib/puppet/type/package.rb +447 -295
- data/lib/puppet/type/package/apt.rb +51 -50
- data/lib/puppet/type/package/bsd.rb +82 -0
- data/lib/puppet/type/package/dpkg.rb +85 -88
- data/lib/puppet/type/package/rpm.rb +67 -63
- data/lib/puppet/type/package/sun.rb +119 -98
- data/lib/puppet/type/package/yum.rb +41 -37
- data/lib/puppet/type/parsedtype.rb +295 -0
- data/lib/puppet/type/parsedtype/host.rb +143 -0
- data/lib/puppet/type/parsedtype/port.rb +232 -0
- data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
- data/lib/puppet/type/pfile.rb +484 -460
- data/lib/puppet/type/pfile/checksum.rb +237 -181
- data/lib/puppet/type/pfile/content.rb +67 -0
- data/lib/puppet/type/pfile/ensure.rb +212 -0
- data/lib/puppet/type/pfile/group.rb +106 -105
- data/lib/puppet/type/pfile/mode.rb +98 -101
- data/lib/puppet/type/pfile/source.rb +228 -209
- data/lib/puppet/type/pfile/type.rb +18 -21
- data/lib/puppet/type/pfile/uid.rb +127 -130
- data/lib/puppet/type/pfilebucket.rb +68 -63
- data/lib/puppet/type/schedule.rb +341 -0
- data/lib/puppet/type/service.rb +351 -255
- data/lib/puppet/type/service/base.rb +9 -14
- data/lib/puppet/type/service/debian.rb +32 -38
- data/lib/puppet/type/service/init.rb +130 -130
- data/lib/puppet/type/service/smf.rb +48 -20
- data/lib/puppet/type/state.rb +229 -16
- data/lib/puppet/type/symlink.rb +51 -63
- data/lib/puppet/type/tidy.rb +105 -102
- data/lib/puppet/type/user.rb +118 -180
- data/lib/puppet/util.rb +100 -6
- data/test/certmgr/certmgr.rb +0 -1
- data/test/client/client.rb +4 -4
- data/test/executables/puppetbin.rb +7 -14
- data/test/executables/puppetca.rb +18 -24
- data/test/executables/puppetd.rb +7 -16
- data/test/executables/puppetmasterd.rb +7 -9
- data/test/executables/puppetmodule.rb +11 -16
- data/test/language/ast.rb +11 -7
- data/test/language/interpreter.rb +1 -1
- data/test/language/scope.rb +2 -0
- data/test/language/snippets.rb +30 -5
- data/test/language/transportable.rb +77 -0
- data/test/other/config.rb +316 -0
- data/test/other/events.rb +22 -21
- data/test/other/log.rb +14 -14
- data/test/other/metrics.rb +4 -8
- data/test/other/overrides.rb +5 -5
- data/test/other/relationships.rb +4 -2
- data/test/other/storage.rb +64 -3
- data/test/other/transactions.rb +20 -20
- data/test/parser/parser.rb +7 -4
- data/test/puppet/conffiles.rb +12 -12
- data/test/puppet/defaults.rb +13 -11
- data/test/puppet/utiltest.rb +14 -11
- data/test/puppettest.rb +156 -48
- data/test/server/bucket.rb +2 -2
- data/test/server/fileserver.rb +6 -6
- data/test/server/logger.rb +19 -11
- data/test/server/master.rb +33 -4
- data/test/server/server.rb +2 -7
- data/test/types/basic.rb +5 -7
- data/test/types/component.rb +22 -18
- data/test/types/cron.rb +111 -44
- data/test/types/exec.rb +116 -59
- data/test/types/file.rb +262 -137
- data/test/types/filebucket.rb +13 -15
- data/test/types/fileignoresource.rb +12 -16
- data/test/types/filesources.rb +73 -48
- data/test/types/filetype.rb +13 -15
- data/test/types/group.rb +15 -13
- data/test/types/host.rb +146 -0
- data/test/types/package.rb +74 -63
- data/test/types/port.rb +139 -0
- data/test/types/query.rb +8 -8
- data/test/types/schedule.rb +335 -0
- data/test/types/service.rb +137 -21
- data/test/types/sshkey.rb +140 -0
- data/test/types/symlink.rb +3 -5
- data/test/types/tidy.rb +5 -14
- data/test/types/type.rb +67 -11
- data/test/types/user.rb +25 -23
- metadata +186 -122
- data/lib/puppet/type/pfile/create.rb +0 -108
- data/lib/puppet/type/pprocess.rb +0 -97
- data/lib/puppet/type/typegen.rb +0 -149
- data/lib/puppet/type/typegen/filerecord.rb +0 -243
- data/lib/puppet/type/typegen/filetype.rb +0 -316
- data/test/other/state.rb +0 -106
@@ -1,108 +0,0 @@
|
|
1
|
-
module Puppet
|
2
|
-
class State
|
3
|
-
class PFileCreate < Puppet::State
|
4
|
-
require 'etc'
|
5
|
-
@doc = "Whether to create files that don't currently exist.
|
6
|
-
**false**/*true*/*file*/*directory*"
|
7
|
-
@name = :create
|
8
|
-
@event = :file_created
|
9
|
-
|
10
|
-
def shouldprocess(value)
|
11
|
-
# default to just about anything meaning 'true'
|
12
|
-
case value
|
13
|
-
when "false", false, nil:
|
14
|
-
return false
|
15
|
-
when "true", true, "file", "plain", /^f/:
|
16
|
-
return "file"
|
17
|
-
when "directory", /^d/:
|
18
|
-
return "directory"
|
19
|
-
when :notfound:
|
20
|
-
# this is where a creation is being rolled back
|
21
|
-
return :notfound
|
22
|
-
else
|
23
|
-
raise Puppet::Error, "Cannot create files of type %s" % value
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def retrieve
|
28
|
-
if stat = @parent.stat(true)
|
29
|
-
@is = stat.ftype
|
30
|
-
else
|
31
|
-
@is = :notfound
|
32
|
-
end
|
33
|
-
|
34
|
-
#self.debug "'exists' state is %s" % self.is
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
def sync
|
39
|
-
event = nil
|
40
|
-
mode = @parent.should(:mode)
|
41
|
-
|
42
|
-
# First, determine if a user has been specified and if so if
|
43
|
-
# that user has write access to the parent dir
|
44
|
-
asuser = nil
|
45
|
-
if @parent.should(:owner) and ! @parent.should(:owner).is_a?(Symbol)
|
46
|
-
writeable = Puppet::Util.asuser(@parent.should(:owner)) {
|
47
|
-
FileTest.writable?(File.dirname(@parent[:path]))
|
48
|
-
}
|
49
|
-
|
50
|
-
# If the parent directory is writeable, then we execute
|
51
|
-
# as the user in question. Otherwise we'll rely on
|
52
|
-
# the 'owner' state to do things.
|
53
|
-
if writeable
|
54
|
-
asuser = @parent.should(:owner)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
begin
|
58
|
-
case self.should
|
59
|
-
when "file":
|
60
|
-
# just create an empty file
|
61
|
-
Puppet::Util.asuser(asuser, @parent.should(:group)) {
|
62
|
-
if mode
|
63
|
-
File.open(@parent[:path],"w", mode) {
|
64
|
-
}
|
65
|
-
else
|
66
|
-
File.open(@parent[:path],"w") {
|
67
|
-
}
|
68
|
-
end
|
69
|
-
}
|
70
|
-
event = :file_created
|
71
|
-
when "directory":
|
72
|
-
Puppet::Util.asuser(asuser) {
|
73
|
-
if mode
|
74
|
-
Dir.mkdir(@parent.name,mode)
|
75
|
-
else
|
76
|
-
Dir.mkdir(@parent.name)
|
77
|
-
end
|
78
|
-
}
|
79
|
-
event = :directory_created
|
80
|
-
when :notfound:
|
81
|
-
# this is where the file should be deleted...
|
82
|
-
|
83
|
-
# This value is only valid when we're rolling back a creation,
|
84
|
-
# so we verify that the file has not been modified since then.
|
85
|
-
unless FileTest.size(@parent.name) == 0
|
86
|
-
raise Puppet::Error.new(
|
87
|
-
"Created file %s has since been modified; cannot roll back."
|
88
|
-
)
|
89
|
-
end
|
90
|
-
|
91
|
-
File.unlink(@parent.name)
|
92
|
-
else
|
93
|
-
error = Puppet::Error.new(
|
94
|
-
"Somehow got told to create a %s file" % self.should)
|
95
|
-
raise error
|
96
|
-
end
|
97
|
-
rescue => detail
|
98
|
-
raise Puppet::Error.new("Could not create %s: %s" %
|
99
|
-
[self.should, detail]
|
100
|
-
)
|
101
|
-
end
|
102
|
-
return event
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# $Id: create.rb 731 2005-10-26 04:44:25Z luke $
|
data/lib/puppet/type/pprocess.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
2
|
-
|
3
|
-
# DISABLED
|
4
|
-
# I'm only working on services, not processes, right now
|
5
|
-
|
6
|
-
module Puppet
|
7
|
-
class State
|
8
|
-
class PProcessRunning < State
|
9
|
-
@doc = "Whether a process should be running. **true**/*false*"
|
10
|
-
def retrieve
|
11
|
-
running = 0
|
12
|
-
regex = Regexp.new(@params[:pattern])
|
13
|
-
begin
|
14
|
-
# this ps is only tested on Solaris
|
15
|
-
# XXX yeah, this definitely needs to be fixed...
|
16
|
-
%x{ps -ef -U #{@params[:user]}}.split("\n").each { |process|
|
17
|
-
if regex.match(process)
|
18
|
-
running += 1
|
19
|
-
end
|
20
|
-
}
|
21
|
-
rescue
|
22
|
-
# this isn't correct, but what the hell
|
23
|
-
Puppet::Message.new(
|
24
|
-
:level => :error,
|
25
|
-
:source => self.parent,
|
26
|
-
:message => "Failed to run ps"
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
self.state = running
|
31
|
-
debug "there are #{running} #{self.parent} processes for start"
|
32
|
-
end
|
33
|
-
|
34
|
-
def <=>(other)
|
35
|
-
self.state < 1
|
36
|
-
end
|
37
|
-
|
38
|
-
def fix
|
39
|
-
require 'etc'
|
40
|
-
# ruby is really cool
|
41
|
-
uid = 0
|
42
|
-
if @params[:user].is_a? Integer
|
43
|
-
uid = @params[:user]
|
44
|
-
else
|
45
|
-
uid = Etc.getpwnam(@params[:user]).uid
|
46
|
-
end
|
47
|
-
Kernel.fork {
|
48
|
-
PProcess.uid = uid
|
49
|
-
PProcess.euid = uid
|
50
|
-
string = @params[:binary] + (@params[:arguments] || "")
|
51
|
-
Puppet::Message.new(
|
52
|
-
:level => :notice,
|
53
|
-
:source => self.parent,
|
54
|
-
:message => "starting"
|
55
|
-
)
|
56
|
-
Kernel.exec(string)
|
57
|
-
}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
class Type
|
62
|
-
class PProcess < Type
|
63
|
-
attr_reader :stat, :path
|
64
|
-
@parameters = [:start, :stop, :user, :pattern, :binary, :arguments]
|
65
|
-
@name = :process
|
66
|
-
|
67
|
-
@paramdoc[:start] = "How to start the process. Must be a fully
|
68
|
-
qualified path."
|
69
|
-
@paramdoc[:stop] = "How to stop the process. Must be a fully
|
70
|
-
qualified path."
|
71
|
-
@paramdoc[:user] = "Which user to run the proces as."
|
72
|
-
@paramdoc[:pattern] = "The search pattern to use to determine
|
73
|
-
whether the process is currently running."
|
74
|
-
@paramdoc[:binary] = "The binary to actually execute."
|
75
|
-
@paramdoc[:arguments] = "The arguments to pass the binary."
|
76
|
-
|
77
|
-
@doc = "**Disabled. Use `service` instead.** Manage running
|
78
|
-
processes."
|
79
|
-
|
80
|
-
@namevar = :pattern
|
81
|
-
|
82
|
-
Puppet::Relation.new(self, Puppet::Operation::Start, {
|
83
|
-
:user => :user,
|
84
|
-
:pattern => :pattern,
|
85
|
-
:binary => :binary,
|
86
|
-
:arguments => :arguments
|
87
|
-
})
|
88
|
-
|
89
|
-
Puppet::Relation.new(self, Puppet::Operation::Stop, {
|
90
|
-
:user => :user,
|
91
|
-
:pattern => :pattern
|
92
|
-
})
|
93
|
-
|
94
|
-
end # Puppet::Type::PProcess
|
95
|
-
end # Puppet::Type
|
96
|
-
|
97
|
-
end
|
data/lib/puppet/type/typegen.rb
DELETED
@@ -1,149 +0,0 @@
|
|
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
|
@@ -1,243 +0,0 @@
|
|
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
|
-
#---------------------------------------------------------------
|