puppet 0.13.0 → 0.13.1

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.

@@ -21,10 +21,10 @@ class Puppet::Parser::AST
21
21
  when Puppet::Type:
22
22
  raise Puppet::Error,
23
23
  "Built-in types must be provided with a name"
24
- when HostClass:
24
+ when Node:
25
25
  return type
26
26
  else
27
- Puppet.info "Autogenerating name for object of type %s" %
27
+ Puppet.debug "Autogenerating name for object of type %s" %
28
28
  type
29
29
  return [type, "-", self.object_id].join("")
30
30
  end
@@ -564,6 +564,9 @@ module Puppet
564
564
  # in the scope tree, which is what provides some minimal closure-like
565
565
  # behaviour.
566
566
  def setobject(type, name, params, file, line)
567
+ # FIXME This objectlookup stuff should be looking up using both
568
+ # the name and the namevar.
569
+
567
570
  # First see if we can look the object up using normal scope
568
571
  # rules, i.e., one of our parent classes has defined the
569
572
  # object or something
@@ -727,6 +730,7 @@ module Puppet
727
730
  if defined? @name
728
731
  bucket = TransBucket.new
729
732
  bucket.name = @name
733
+ bucket.autoname = self.autoname
730
734
 
731
735
  # it'd be nice not to have to do this...
732
736
  results.each { |result|
@@ -769,4 +773,4 @@ module Puppet
769
773
  end
770
774
  end
771
775
 
772
- # $Id: scope.rb 871 2006-02-07 05:58:00Z luke $
776
+ # $Id: scope.rb 898 2006-02-13 17:13:09Z luke $
@@ -69,12 +69,10 @@ class Puppet::SSLCertificates::CA
69
69
  #puts "Reading %s" % Puppet[:capass]
70
70
  #system "ls -al %s" % Puppet[:capass]
71
71
  #File.read Puppet[:capass]
72
- Puppet.info "Getting pass"
73
72
  @config[:password] = self.getpass
74
73
  else
75
74
  # Don't create a password if the cert already exists
76
75
  unless FileTest.exists?(@config[:cacert])
77
- Puppet.info "Genning pass"
78
76
  @config[:password] = self.genpass
79
77
  end
80
78
  end
@@ -288,4 +286,4 @@ class Puppet::SSLCertificates::CA
288
286
  end
289
287
  end
290
288
 
291
- # $Id: ca.rb 873 2006-02-07 23:12:33Z luke $
289
+ # $Id: ca.rb 896 2006-02-10 22:00:30Z luke $
@@ -12,7 +12,7 @@ module Puppet
12
12
  @path = [state.path,"change"].flatten
13
13
  @is = state.is
14
14
 
15
- if state.is == state.should
15
+ if state.insync?
16
16
  raise Puppet::Error.new(
17
17
  "Tried to create a change for in-sync state %s" % state.name
18
18
  )
@@ -25,8 +25,8 @@ module Puppet
25
25
 
26
26
  #---------------------------------------------------------------
27
27
  def go
28
- if @state.is == @state.should
29
- @state.info "already in sync"
28
+ if @state.insync?
29
+ @state.info "Already in sync"
30
30
  return nil
31
31
  end
32
32
 
@@ -37,7 +37,8 @@ module Puppet
37
37
  return nil
38
38
  end
39
39
 
40
- #@state.info "Is: %s, Should: %s" % [@state.is.inspect, @state.should.inspect]
40
+ #@state.info "Is: %s, Should: %s" %
41
+ # [@state.is.inspect, @state.should.inspect]
41
42
 
42
43
  begin
43
44
  events = @state.sync
@@ -152,4 +153,4 @@ module Puppet
152
153
  end
153
154
  end
154
155
 
155
- # $Id: statechange.rb 831 2006-01-16 20:01:20Z luke $
156
+ # $Id: statechange.rb 899 2006-02-13 17:48:33Z luke $
@@ -1,10 +1,12 @@
1
1
  require 'yaml'
2
+ require 'sync'
3
+ #require 'puppet/lockfile'
2
4
 
3
5
  module Puppet
4
6
  # a class for storing state
5
7
  class Storage
6
8
  include Singleton
7
-
9
+
8
10
  def initialize
9
11
  self.class.load
10
12
  end
@@ -46,9 +48,7 @@ module Puppet
46
48
  end
47
49
  return
48
50
  end
49
- #Puppet.debug "Loading statefile %s" % Puppet[:statefile]
50
- Puppet::Util.lock(Puppet[:statefile]) { |file|
51
- #@@state = Marshal.load(file)
51
+ Puppet::Util.readlock(Puppet[:statefile]) do |file|
52
52
  begin
53
53
  @@state = YAML.load(file)
54
54
  rescue => detail
@@ -63,7 +63,7 @@ module Puppet
63
63
  Puppet[:statefile]
64
64
  end
65
65
  end
66
- }
66
+ end
67
67
 
68
68
  unless @@state.is_a?(Hash)
69
69
  Puppet.err "State got corrupted"
@@ -78,7 +78,7 @@ module Puppet
78
78
  end
79
79
 
80
80
  def self.store
81
- Puppet.debug "Storing state"
81
+ #Puppet.debug "Storing state"
82
82
  unless FileTest.directory?(File.dirname(Puppet[:statefile]))
83
83
  begin
84
84
  Puppet.recmkdir(File.dirname(Puppet[:statefile]))
@@ -94,13 +94,11 @@ module Puppet
94
94
  Puppet.info "Creating state file %s" % Puppet[:statefile]
95
95
  end
96
96
 
97
- Puppet::Util.lock(
98
- Puppet[:statefile], "w", 0600
99
- ) { |file|
97
+ Puppet::Util.writelock(Puppet[:statefile], 0600) do |file|
100
98
  file.print YAML.dump(@@state)
101
- }
99
+ end
102
100
  end
103
101
  end
104
102
  end
105
103
 
106
- # $Id: storage.rb 848 2006-01-24 06:01:58Z luke $
104
+ # $Id: storage.rb 897 2006-02-12 18:08:39Z luke $
@@ -25,13 +25,13 @@ module Puppet
25
25
  def initialize(name,type)
26
26
  @type = type
27
27
  @name = name
28
- @params = {"name" => name}
28
+ @params = {}
29
29
  #self.class.add(self)
30
30
  @tags = []
31
31
  end
32
32
 
33
33
  def longname
34
- return [self.type,self[:name]].join('--')
34
+ return [@type,@name].join('--')
35
35
  end
36
36
 
37
37
  def tags
@@ -43,7 +43,7 @@ module Puppet
43
43
  end
44
44
 
45
45
  def to_s
46
- return "%s(%s) => %s" % [@type,self[:name],super]
46
+ return "%s(%s) => %s" % [@type,@name,super]
47
47
  end
48
48
 
49
49
  def to_manifest
@@ -164,24 +164,51 @@ module Puppet
164
164
  unless defined? @type
165
165
  Puppet.debug "TransBucket '%s' has no type" % @name
166
166
  end
167
- hash = {
168
- :name => @name,
169
- :type => @type
170
- }
171
- if defined? @parameters
172
- @parameters.each { |param,value|
173
- Puppet.debug "Defining %s on %s of type %s" %
174
- [param,@name,@type]
175
- hash[param] = value
176
- }
167
+ usetrans = true
168
+
169
+ if usetrans
170
+ name = nil
171
+ #if self.autoname or @name =~ /-\d+$/
172
+ if self.autoname
173
+ name = @type
174
+ else
175
+ name = "%s[%s]" % [@type, @name]
176
+ end
177
+ trans = TransObject.new(name, :component)
178
+ if defined? @parameters
179
+ @parameters.each { |param,value|
180
+ Puppet.debug "Defining %s on %s of type %s" %
181
+ [param,@name,@type]
182
+ trans[param] = value
183
+ }
184
+ else
185
+ #Puppet.debug "%s[%s] has no parameters" % [@type, @name]
186
+ end
187
+
188
+ if parent
189
+ trans[:parent] = parent
190
+ end
191
+ container = Puppet.type(:component).create(trans)
177
192
  else
178
- #Puppet.debug "%s[%s] has no parameters" % [@type, @name]
179
- end
193
+ hash = {
194
+ :name => @name,
195
+ :type => @type
196
+ }
197
+ if defined? @parameters
198
+ @parameters.each { |param,value|
199
+ Puppet.debug "Defining %s on %s of type %s" %
200
+ [param,@name,@type]
201
+ hash[param] = value
202
+ }
203
+ else
204
+ #Puppet.debug "%s[%s] has no parameters" % [@type, @name]
205
+ end
180
206
 
181
- if parent
182
- hash[:parent] = parent
207
+ if parent
208
+ hash[:parent] = parent
209
+ end
210
+ container = Puppet.type(:component).create(hash)
183
211
  end
184
- container = Puppet.type(:component).create(hash)
185
212
  #Puppet.info container.inspect
186
213
 
187
214
  if parent
@@ -228,4 +255,4 @@ module Puppet
228
255
  #------------------------------------------------------------
229
256
  end
230
257
 
231
- # $Id: transportable.rb 873 2006-02-07 23:12:33Z luke $
258
+ # $Id: transportable.rb 896 2006-02-10 22:00:30Z luke $
data/lib/puppet/type.rb CHANGED
@@ -1081,11 +1081,13 @@ class Type < Puppet::Element
1081
1081
  end
1082
1082
 
1083
1083
  name = nil
1084
- unless name = hash["name"] || hash[:name] ||
1085
- hash[self.namevar] || hash[self.namevar.to_s]
1086
- raise Puppet::Error, "You must specify a name for objects of type %s" %
1087
- self.to_s
1084
+ unless hash.is_a? TransObject
1085
+ # if it's not a transobject, then make it one, just to make people's
1086
+ # lives easier
1087
+ hash = self.hash2trans(hash)
1088
1088
  end
1089
+ name = hash.name
1090
+
1089
1091
  # if the object already exists
1090
1092
  if self.isomorphic? and retobj = self[name]
1091
1093
  # if only one of our objects is implicit, then it's easy to see
@@ -1132,9 +1134,51 @@ class Type < Puppet::Element
1132
1134
  obj.implicit = true
1133
1135
  end
1134
1136
 
1137
+ # Store the object by name
1138
+ self[obj.name] = obj
1139
+
1140
+ if name != obj[self.namevar]
1141
+ self.alias(obj[self.namevar], obj)
1142
+ end
1143
+
1135
1144
  return obj
1136
1145
  end
1137
1146
 
1147
+ # Convert a hash to a TransObject.
1148
+ def self.hash2trans(hash)
1149
+ name = nil
1150
+ ["name", :name, self.namevar, self.namevar.to_s].each { |param|
1151
+ if hash.include? param
1152
+ name = hash[param]
1153
+ hash.delete(param)
1154
+ end
1155
+ }
1156
+ unless name
1157
+ raise Puppet::Error,
1158
+ "You must specify a name for objects of type %s" % self.to_s
1159
+ end
1160
+
1161
+ [:type, "type"].each do |type|
1162
+ if hash.include? type
1163
+ unless self.validattr? :type
1164
+ hash.delete type
1165
+ end
1166
+ end
1167
+ end
1168
+ # okay, now make a transobject out of hash
1169
+ begin
1170
+ trans = TransObject.new(name, self.name.to_s)
1171
+ hash.each { |param, value|
1172
+ trans[param] = value
1173
+ }
1174
+ rescue => detail
1175
+ raise Puppet::Error, "Could not create %s: %s" %
1176
+ [name, detail]
1177
+ end
1178
+
1179
+ return trans
1180
+ end
1181
+
1138
1182
  def self.implicitcreate(hash)
1139
1183
  unless hash.include?(:implicit)
1140
1184
  hash[:implicit] = true
@@ -1206,9 +1250,10 @@ class Type < Puppet::Element
1206
1250
  unless defined? @inited
1207
1251
  self.initvars
1208
1252
  end
1253
+ namevar = self.class.namevar
1209
1254
 
1210
1255
  # If we got passed a transportable object, we just pull a bunch of info
1211
- # directly from it.
1256
+ # directly from it. This is the main object instantiation mechanism.
1212
1257
  if hash.is_a?(Puppet::TransObject)
1213
1258
  #self[:name] = hash[:name]
1214
1259
  [:file, :line, :tags].each { |getter|
@@ -1219,6 +1264,15 @@ class Type < Puppet::Element
1219
1264
  end
1220
1265
  end
1221
1266
  }
1267
+
1268
+ @name = hash.name
1269
+
1270
+ # If they did not provide a namevar,
1271
+ if hash.include? namevar
1272
+ self[:alias] = hash.name
1273
+ else
1274
+ hash[namevar] = hash.name
1275
+ end
1222
1276
  hash = hash.to_hash
1223
1277
  end
1224
1278
 
@@ -1235,7 +1289,6 @@ class Type < Puppet::Element
1235
1289
  # we have the name but before anything else
1236
1290
 
1237
1291
  attrs = self.class.allattrs
1238
- namevar = self.class.namevar
1239
1292
 
1240
1293
  if hash.include?(namevar)
1241
1294
  #self.send(namevar.to_s + "=", hash[namevar])
@@ -1281,10 +1334,6 @@ class Type < Puppet::Element
1281
1334
  [self.class.name, hash.keys.join(" ")])
1282
1335
  end
1283
1336
 
1284
- # add this object to the specific class's list of objects
1285
- #puts caller
1286
- self.class[self.name] = self
1287
-
1288
1337
  if self.respond_to?(:validate)
1289
1338
  self.validate
1290
1339
  end
@@ -1518,18 +1567,18 @@ class Type < Puppet::Element
1518
1567
 
1519
1568
  # if they're not using :name for the namevar but we got :name (probably
1520
1569
  # from the parser)
1521
- if namevar != :name and hash.include?(:name) and ! hash[:name].nil?
1522
- #self[namevar] = hash[:name]
1523
- hash[namevar] = hash[:name]
1524
- hash.delete(:name)
1525
- # else if we got the namevar
1526
- elsif hash.has_key?(namevar) and ! hash[namevar].nil?
1527
- #self[namevar] = hash[namevar]
1528
- #hash.delete(namevar)
1529
- # else something's screwy
1530
- else
1531
- # they didn't specify anything related to names
1532
- end
1570
+ # if namevar != :name and hash.include?(:name) and ! hash[:name].nil?
1571
+ # #self[namevar] = hash[:name]
1572
+ # hash[namevar] = hash[:name]
1573
+ # hash.delete(:name)
1574
+ # # else if we got the namevar
1575
+ # elsif hash.has_key?(namevar) and ! hash[namevar].nil?
1576
+ # #self[namevar] = hash[namevar]
1577
+ # #hash.delete(namevar)
1578
+ # # else something's screwy
1579
+ # else
1580
+ # # they didn't specify anything related to names
1581
+ # end
1533
1582
 
1534
1583
  return hash
1535
1584
  end
@@ -2048,9 +2097,10 @@ class Type < Puppet::Element
2048
2097
 
2049
2098
  newmetaparam(:loglevel) do
2050
2099
  desc "Sets the level that information will be logged:
2051
- debug, info, verbose, notice, warning, err, alert, emerg or crit.
2052
- The log levels have the biggest impact when logs are sent to
2053
- syslog (which is currently the default)."
2100
+ ``debug``, ``info``, ``verbose``, ``notice``, ``warning``,
2101
+ ``err``, ``alert``, ``emerg`` or ``crit``. The log levels have
2102
+ the biggest impact when logs are sent to syslog (which is
2103
+ currently the default)."
2054
2104
  defaultto :notice
2055
2105
 
2056
2106
  validate do |loglevel|
@@ -2074,26 +2124,43 @@ class Type < Puppet::Element
2074
2124
  end
2075
2125
 
2076
2126
  newmetaparam(:alias) do
2077
- desc "Creates an alias for the object. This simplifies lookup of the
2078
- object so is useful in the language. It is especially useful when
2079
- you are creating long commands using exec or when many different
2080
- systems call a given package_ different names::
2081
-
2127
+ desc "Creates an alias for the object. Puppet uses this internally when you
2128
+ provide a symbolic name::
2082
2129
 
2083
- file { \"/usr/local/scripts/myscript\":
2084
- source => \"puppet://server/module/myscript\",
2085
- mode => 755,
2086
- alias => myscript
2130
+ file { sshdconfig:
2131
+ path => $operatingsystem ? {
2132
+ solaris => \"/usr/local/etc/ssh/sshd_config\",
2133
+ default => \"/etc/ssh/sshd_config\"
2134
+ },
2135
+ source => \"...\"
2136
+ }
2137
+
2138
+ service { sshd:
2139
+ subscribe => file[sshdconfig]
2140
+ }
2141
+
2142
+ When you use this feature, the parser sets ``sshdconfig`` as the name,
2143
+ and the library sets that as an alias for the file so the dependency
2144
+ lookup for ``sshd`` works. You can use this parameter yourself,
2145
+ but note that only the library can use these aliases; for instance,
2146
+ the following code will not work::
2147
+
2148
+ file { \"/etc/ssh/sshd_config\":
2149
+ owner => root,
2150
+ group => root,
2151
+ alias => sshdconfig
2087
2152
  }
2088
2153
 
2089
- exec { \"/usr/local/scripts/myscript\":
2090
- require => file[myscript]
2154
+ file { sshdconfig:
2155
+ mode => 644
2091
2156
  }
2157
+
2158
+ There's no way here for the Puppet parser to know that these two stanzas
2159
+ should be affecting the same file.
2160
+
2161
+ See the `language tutorial <http://reductivelabs.com/projects/puppet/documentation/languagetutorial>`__ for more information.
2092
2162
 
2093
- Again, this is somewhat redundant, since any sane person would
2094
- just use a variable (unless the two statements were in different
2095
- scopes), and Puppet will autorequire the script anyway, but it
2096
- gets the point across."
2163
+ "
2097
2164
 
2098
2165
  munge do |aliases|
2099
2166
  unless aliases.is_a?(Array)
@@ -2132,4 +2199,4 @@ require 'puppet/type/user'
2132
2199
  require 'puppet/type/tidy'
2133
2200
  require 'puppet/type/parsedtype'
2134
2201
 
2135
- # $Id: type.rb 886 2006-02-08 17:45:26Z luke $
2202
+ # $Id: type.rb 900 2006-02-13 18:00:17Z luke $