chef 0.9.8.rc.0 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +80 -44
- data/lib/chef/checksum.rb +7 -4
- data/lib/chef/client.rb +4 -0
- data/lib/chef/cookbook/cookbook_collection.rb +10 -9
- data/lib/chef/cookbook/file_system_file_vendor.rb +9 -8
- data/lib/chef/cookbook/file_vendor.rb +2 -1
- data/lib/chef/cookbook/metadata.rb +3 -0
- data/lib/chef/cookbook/remote_file_vendor.rb +3 -2
- data/lib/chef/cookbook/syntax_check.rb +8 -0
- data/lib/chef/cookbook_site_streaming_uploader.rb +5 -1
- data/lib/chef/cookbook_version.rb +25 -19
- data/lib/chef/exceptions.rb +3 -0
- data/lib/chef/file_access_control.rb +1 -0
- data/lib/chef/handler.rb +37 -1
- data/lib/chef/mixin/deep_merge.rb +6 -5
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +2 -1
- data/lib/chef/mixin/shell_out.rb +1 -1
- data/lib/chef/mixin/template.rb +1 -1
- data/lib/chef/mixin/xml_escape.rb +2 -2
- data/lib/chef/monkey_patches/dir.rb +1 -1
- data/lib/chef/monkey_patches/string.rb +2 -1
- data/lib/chef/monkey_patches/tempfile.rb +5 -1
- data/lib/chef/provider/package/easy_install.rb +29 -22
- data/lib/chef/provider/template.rb +1 -94
- data/lib/chef/recipe.rb +16 -12
- data/lib/chef/rest.rb +17 -5
- data/lib/chef/run_context.rb +2 -1
- data/lib/chef/run_status.rb +27 -0
- data/lib/chef/runner.rb +5 -3
- data/lib/chef/shef.rb +3 -1
- data/lib/chef/shef/ext.rb +1 -0
- data/lib/chef/shef/model_wrapper.rb +1 -1
- data/lib/chef/shef/shef_rest.rb +1 -1
- data/lib/chef/shef/shef_session.rb +1 -0
- data/lib/chef/shell_out.rb +47 -19
- data/lib/chef/version.rb +1 -1
- metadata +6 -27
data/lib/chef/run_context.rb
CHANGED
@@ -23,8 +23,9 @@ require 'chef/role'
|
|
23
23
|
require 'chef/log'
|
24
24
|
require 'chef/mixin/language_include_recipe'
|
25
25
|
|
26
|
-
# Value object that loads and tracks the context of a Chef run
|
27
26
|
class Chef
|
27
|
+
# == Chef::RunContext
|
28
|
+
# Value object that loads and tracks the context of a Chef run
|
28
29
|
class RunContext
|
29
30
|
|
30
31
|
# Used to load the node's recipes after expanding its run list
|
data/lib/chef/run_status.rb
CHANGED
@@ -16,6 +16,11 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
+
# == Chef::RunStatus
|
20
|
+
# Tracks various aspects of a Chef run, including the Node and RunContext,
|
21
|
+
# start and end time, and any Exception that stops the run. RunStatus objects
|
22
|
+
# are passed to any notification or exception handlers at the completion of a
|
23
|
+
# Chef run.
|
19
24
|
class Chef::RunStatus
|
20
25
|
|
21
26
|
attr_reader :run_context
|
@@ -38,14 +43,18 @@ class Chef::RunStatus
|
|
38
43
|
@node
|
39
44
|
end
|
40
45
|
|
46
|
+
# sets +start_time+ to the current time.
|
41
47
|
def start_clock
|
42
48
|
@start_time = Time.now
|
43
49
|
end
|
44
50
|
|
51
|
+
# sets +end_time+ to the current time
|
45
52
|
def stop_clock
|
46
53
|
@end_time = Time.now
|
47
54
|
end
|
48
55
|
|
56
|
+
# The elapsed time between +start_time+ and +end_time+. Returns +nil+ if
|
57
|
+
# either value is not set.
|
49
58
|
def elapsed_time
|
50
59
|
if @start_time && @end_time
|
51
60
|
@end_time - @start_time
|
@@ -54,26 +63,42 @@ class Chef::RunStatus
|
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
66
|
+
# The list of all resources in the current run context's +resource_collection+
|
57
67
|
def all_resources
|
58
68
|
@run_context && @run_context.resource_collection.all_resources
|
59
69
|
end
|
60
70
|
|
71
|
+
# The list of all resources in the current run context's +resource_collection+
|
72
|
+
# that are marked as updated
|
61
73
|
def updated_resources
|
62
74
|
@run_context && @run_context.resource_collection.select { |r| r.updated }
|
63
75
|
end
|
64
76
|
|
77
|
+
# The backtrace from +exception+, if any
|
65
78
|
def backtrace
|
66
79
|
@exception && @exception.backtrace
|
67
80
|
end
|
68
81
|
|
82
|
+
# Did the Chef run fail?
|
69
83
|
def failed?
|
70
84
|
!success?
|
71
85
|
end
|
72
86
|
|
87
|
+
# Did the chef run succeed? returns +true+ if no exception has been set.
|
73
88
|
def success?
|
74
89
|
@exception.nil?
|
75
90
|
end
|
76
91
|
|
92
|
+
# A Hash representation of the RunStatus, with the following (Symbol) keys:
|
93
|
+
# * :node
|
94
|
+
# * :success
|
95
|
+
# * :start_time
|
96
|
+
# * :end_time
|
97
|
+
# * :elapsed_time
|
98
|
+
# * :all_resources
|
99
|
+
# * :updated_resources
|
100
|
+
# * :exception
|
101
|
+
# * :backtrace
|
77
102
|
def to_hash
|
78
103
|
# use a flat hash here so we can't errors from intermediate values being nil
|
79
104
|
{ :node => node,
|
@@ -87,6 +112,8 @@ class Chef::RunStatus
|
|
87
112
|
:backtrace => backtrace}
|
88
113
|
end
|
89
114
|
|
115
|
+
# Returns a string of the format "ExceptionClass: message" or +nil+ if no
|
116
|
+
# +exception+ is set.
|
90
117
|
def formatted_exception
|
91
118
|
@exception && "#{@exception.class.name}: #{@exception.message}"
|
92
119
|
end
|
data/lib/chef/runner.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
3
|
# Author:: Christopher Walters (<cw@opscode.com>)
|
4
4
|
# Author:: Tim Hinderliter (<tim@opscode.com>)
|
@@ -23,8 +23,9 @@ require 'chef/node'
|
|
23
23
|
require 'chef/resource_collection'
|
24
24
|
require 'chef/platform'
|
25
25
|
|
26
|
-
# This class is responsible for executing the steps in a Chef run.
|
27
26
|
class Chef
|
27
|
+
# == Chef::Runner
|
28
|
+
# This class is responsible for executing the steps in a Chef run.
|
28
29
|
class Runner
|
29
30
|
|
30
31
|
attr_reader :run_context
|
@@ -72,7 +73,8 @@ class Chef
|
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
|
-
#
|
76
|
+
# Iterates over the +resource_collection+ in the +run_context+ calling
|
77
|
+
# +run_action+ for each resource in turn.
|
76
78
|
def converge
|
77
79
|
delayed_actions = Array.new
|
78
80
|
|
data/lib/chef/shef.rb
CHANGED
@@ -27,7 +27,9 @@ require "chef/config"
|
|
27
27
|
require "chef/shef/shef_session"
|
28
28
|
require "chef/shef/ext"
|
29
29
|
|
30
|
-
|
30
|
+
# = Shef
|
31
|
+
# Shef is Chef in an IRB session. Shef can interact with a Chef server via the
|
32
|
+
# REST API, and run and debug recipes interactively.
|
31
33
|
module Shef
|
32
34
|
LEADERS = Hash.new("")
|
33
35
|
LEADERS[Chef::Recipe] = ":recipe"
|
data/lib/chef/shef/ext.rb
CHANGED
data/lib/chef/shef/shef_rest.rb
CHANGED
data/lib/chef/shell_out.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
3
3
|
# Copyright:: Copyright (c) 2010 Opscode, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
@@ -23,16 +23,17 @@ require 'fcntl'
|
|
23
23
|
require 'chef/exceptions'
|
24
24
|
|
25
25
|
class Chef
|
26
|
-
|
26
|
+
|
27
|
+
# == Chef::ShellOut
|
27
28
|
# Provides a simplified interface to shelling out yet still collecting both
|
28
29
|
# standard out and standard error and providing full control over environment,
|
29
30
|
# working directory, uid, gid, etc.
|
30
31
|
#
|
31
32
|
# No means for passing input to the subprocess is provided, nor is there any
|
32
33
|
# way to inspect the output of the command as it is being read. If you need
|
33
|
-
# to do that, you have to use Chef::Mixin::Command
|
34
|
+
# to do that, you have to use popen4 (in Chef::Mixin::Command)
|
34
35
|
#
|
35
|
-
#
|
36
|
+
# === Platform Support
|
36
37
|
# Chef::ShellOut uses Kernel.fork() and is therefore unsuitable for Windows
|
37
38
|
# or jruby.
|
38
39
|
class ShellOut
|
@@ -58,23 +59,41 @@ class Chef
|
|
58
59
|
# === Options:
|
59
60
|
# If the last argument is a Hash, it is removed from the list of args passed
|
60
61
|
# to exec and used as an options hash. The following options are available:
|
61
|
-
# * user
|
62
|
+
# * +user+: the user the commmand should run as. if an integer is given, it is
|
62
63
|
# used as a uid. A string is treated as a username and resolved to a uid
|
63
64
|
# with Etc.getpwnam
|
64
|
-
# * group
|
65
|
-
# * cwd
|
66
|
-
# * umask
|
65
|
+
# * +group+: the group the command should run as. works similarly to +user+
|
66
|
+
# * +cwd+: the directory to chdir to before running the command
|
67
|
+
# * +umask+: a umask to set before running the command. If given as an Integer,
|
67
68
|
# be sure to use two leading zeros so it's parsed as Octal. A string will
|
68
69
|
# be treated as an octal integer
|
69
|
-
# * returns
|
70
|
+
# * +returns+: one or more Integer values to use as valid exit codes for the
|
70
71
|
# subprocess. This only has an effect if you call +error!+ after
|
71
72
|
# +run_command+.
|
72
|
-
# * environment
|
73
|
+
# * +environment+: a Hash of environment variables to set before the command
|
73
74
|
# is run. By default, the environment will *always* be set to 'LC_ALL' => 'C'
|
74
75
|
# to prevent issues with multibyte characters in Ruby 1.8. To avoid this,
|
75
76
|
# use :environment => nil for *no* extra environment settings, or
|
76
77
|
# :environment => {'LC_ALL'=>nil, ...} to set other environment settings
|
77
78
|
# without changing the locale.
|
79
|
+
# * +timeout+: a Numeric value for the number of seconds to wait on the
|
80
|
+
# child process before raising an Exception. This is calculated as the
|
81
|
+
# total amount of time that ShellOut waited on the child process without
|
82
|
+
# receiving any output (i.e., IO.select returned nil). Default is 60
|
83
|
+
# seconds. Note: the stdlib Timeout library is not used.
|
84
|
+
# === Examples:
|
85
|
+
# Invoke find(1) to search for .rb files:
|
86
|
+
# find = Chef::ShellOut.new("find . -name '*.rb'")
|
87
|
+
# find.run_command
|
88
|
+
# # If all went well, the results are on +stdout+
|
89
|
+
# puts find.stdout
|
90
|
+
# # find(1) prints diagnostic info to STDERR:
|
91
|
+
# puts "error messages" + find.stderr
|
92
|
+
# # Raise an exception if it didn't exit with 0
|
93
|
+
# find.error!
|
94
|
+
# Run a command as the +www+ user with no extra ENV settings from +/tmp+
|
95
|
+
# cmd = Chef::ShellOut.new("apachectl", "start", :user => 'www', :env => nil, :cwd => '/tmp')
|
96
|
+
# cmd.run_command # etc.
|
78
97
|
def initialize(*command_args)
|
79
98
|
@stdout, @stderr = '', ''
|
80
99
|
@environment = DEFAULT_ENVIRONMENT
|
@@ -106,6 +125,9 @@ class Chef
|
|
106
125
|
@timeout || DEFAULT_READ_TIMEOUT
|
107
126
|
end
|
108
127
|
|
128
|
+
# Creates a String showing the output of the command, including a banner
|
129
|
+
# showing the exact command executed. Used by +invalid!+ to show command
|
130
|
+
# results when the command exited with an unexpected status.
|
109
131
|
def format_for_exception
|
110
132
|
msg = ""
|
111
133
|
msg << "---- Begin output of #{command} ----\n"
|
@@ -126,11 +148,11 @@ class Chef
|
|
126
148
|
# returns +self+; +stdout+, +stderr+, +status+, and +exitstatus+ will be
|
127
149
|
# populated with results of the command
|
128
150
|
# === Raises
|
129
|
-
# * Errno::EACCES
|
130
|
-
# * Errno::ENOENT
|
151
|
+
# * Errno::EACCES when you are not privileged to execute the command
|
152
|
+
# * Errno::ENOENT when the command is not available on the system (or not
|
131
153
|
# in the current $PATH)
|
132
|
-
# * Chef::Exceptions::CommandTimeout
|
133
|
-
#
|
154
|
+
# * Chef::Exceptions::CommandTimeout when the command does not complete
|
155
|
+
# within +timeout+ seconds (default: 60s)
|
134
156
|
def run_command
|
135
157
|
Chef::Log.debug("sh(#{@command})")
|
136
158
|
@child_pid = fork_subprocess
|
@@ -184,6 +206,13 @@ class Chef
|
|
184
206
|
close_all_pipes
|
185
207
|
end
|
186
208
|
|
209
|
+
# Checks the +exitstatus+ against the set of +valid_exit_codes+. If
|
210
|
+
# +exitstatus+ is not in the list of +valid_exit_codes+, calls +invalid!+,
|
211
|
+
# which raises an Exception.
|
212
|
+
# === Returns
|
213
|
+
# nil::: always returns nil when it does not raise
|
214
|
+
# === Raises
|
215
|
+
# Chef::Exceptions::ShellCommandFailed::: via +invalid!+
|
187
216
|
def error!
|
188
217
|
unless Array(valid_exit_codes).include?(exitstatus)
|
189
218
|
invalid!("Expected process to exit 0, but it exited with #{exitstatus}")
|
@@ -193,9 +222,9 @@ class Chef
|
|
193
222
|
# Raises a Chef::Exceptions::ShellCommandFailed exception, appending the
|
194
223
|
# command's stdout, stderr, and exitstatus to the exception message.
|
195
224
|
# === Arguments
|
196
|
-
# +msg
|
197
|
-
#
|
198
|
-
#
|
225
|
+
# +msg+: A String to use as the basis of the exception message. The
|
226
|
+
# default explanation is very generic, providing a more informative message
|
227
|
+
# is highly encouraged.
|
199
228
|
# === Raises
|
200
229
|
# Chef::Exceptions::ShellCommandFailed always
|
201
230
|
def invalid!(msg=nil)
|
@@ -280,12 +309,11 @@ class Chef
|
|
280
309
|
child_stdout.close unless child_stdout.closed?
|
281
310
|
child_stderr.close unless child_stderr.closed?
|
282
311
|
child_process_status.close unless child_process_status.closed?
|
283
|
-
#rescue NoMethodError # we blew up before IPC was setup
|
284
312
|
end
|
285
313
|
|
286
314
|
# replace stdout, and stderr with pipes to the parent, and close the
|
287
315
|
# reader side of the error marshaling side channel. Close STDIN so when we
|
288
|
-
# exec, the new program will
|
316
|
+
# exec, the new program will know it's never getting input ever.
|
289
317
|
def configure_subprocess_file_descriptors
|
290
318
|
process_status_pipe.first.close
|
291
319
|
|
data/lib/chef/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: true
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 9
|
9
8
|
- 8
|
10
|
-
|
11
|
-
- 0
|
12
|
-
version: 0.9.8.rc.0
|
9
|
+
version: 0.9.8
|
13
10
|
platform: ruby
|
14
11
|
authors:
|
15
12
|
- Adam Jacob
|
@@ -17,7 +14,7 @@ autorequire:
|
|
17
14
|
bindir: bin
|
18
15
|
cert_chain: []
|
19
16
|
|
20
|
-
date: 2010-
|
17
|
+
date: 2010-08-05 00:00:00 -07:00
|
21
18
|
default_executable:
|
22
19
|
dependencies:
|
23
20
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +25,6 @@ dependencies:
|
|
28
25
|
requirements:
|
29
26
|
- - ">="
|
30
27
|
- !ruby/object:Gem::Version
|
31
|
-
hash: 19
|
32
28
|
segments:
|
33
29
|
- 1
|
34
30
|
- 1
|
@@ -44,7 +40,6 @@ dependencies:
|
|
44
40
|
requirements:
|
45
41
|
- - ">="
|
46
42
|
- !ruby/object:Gem::Version
|
47
|
-
hash: 19
|
48
43
|
segments:
|
49
44
|
- 1
|
50
45
|
- 1
|
@@ -60,7 +55,6 @@ dependencies:
|
|
60
55
|
requirements:
|
61
56
|
- - ">="
|
62
57
|
- !ruby/object:Gem::Version
|
63
|
-
hash: 19
|
64
58
|
segments:
|
65
59
|
- 1
|
66
60
|
- 1
|
@@ -76,7 +70,6 @@ dependencies:
|
|
76
70
|
requirements:
|
77
71
|
- - ">="
|
78
72
|
- !ruby/object:Gem::Version
|
79
|
-
hash: 19
|
80
73
|
segments:
|
81
74
|
- 1
|
82
75
|
- 1
|
@@ -92,7 +85,6 @@ dependencies:
|
|
92
85
|
requirements:
|
93
86
|
- - ">="
|
94
87
|
- !ruby/object:Gem::Version
|
95
|
-
hash: 7
|
96
88
|
segments:
|
97
89
|
- 0
|
98
90
|
- 5
|
@@ -108,7 +100,6 @@ dependencies:
|
|
108
100
|
requirements:
|
109
101
|
- - ">="
|
110
102
|
- !ruby/object:Gem::Version
|
111
|
-
hash: 31
|
112
103
|
segments:
|
113
104
|
- 1
|
114
105
|
- 0
|
@@ -116,7 +107,6 @@ dependencies:
|
|
116
107
|
version: 1.0.4
|
117
108
|
- - <=
|
118
109
|
- !ruby/object:Gem::Version
|
119
|
-
hash: 1
|
120
110
|
segments:
|
121
111
|
- 1
|
122
112
|
- 5
|
@@ -132,7 +122,6 @@ dependencies:
|
|
132
122
|
requirements:
|
133
123
|
- - ">="
|
134
124
|
- !ruby/object:Gem::Version
|
135
|
-
hash: 7
|
136
125
|
segments:
|
137
126
|
- 0
|
138
127
|
- 6
|
@@ -148,7 +137,6 @@ dependencies:
|
|
148
137
|
requirements:
|
149
138
|
- - <=
|
150
139
|
- !ruby/object:Gem::Version
|
151
|
-
hash: 3
|
152
140
|
segments:
|
153
141
|
- 1
|
154
142
|
- 4
|
@@ -164,7 +152,6 @@ dependencies:
|
|
164
152
|
requirements:
|
165
153
|
- - ">="
|
166
154
|
- !ruby/object:Gem::Version
|
167
|
-
hash: 3
|
168
155
|
segments:
|
169
156
|
- 0
|
170
157
|
version: "0"
|
@@ -178,7 +165,6 @@ dependencies:
|
|
178
165
|
requirements:
|
179
166
|
- - ">="
|
180
167
|
- !ruby/object:Gem::Version
|
181
|
-
hash: 3
|
182
168
|
segments:
|
183
169
|
- 0
|
184
170
|
version: "0"
|
@@ -192,7 +178,6 @@ dependencies:
|
|
192
178
|
requirements:
|
193
179
|
- - ">="
|
194
180
|
- !ruby/object:Gem::Version
|
195
|
-
hash: 3
|
196
181
|
segments:
|
197
182
|
- 0
|
198
183
|
version: "0"
|
@@ -206,7 +191,6 @@ dependencies:
|
|
206
191
|
requirements:
|
207
192
|
- - ">="
|
208
193
|
- !ruby/object:Gem::Version
|
209
|
-
hash: 3
|
210
194
|
segments:
|
211
195
|
- 0
|
212
196
|
version: "0"
|
@@ -220,7 +204,6 @@ dependencies:
|
|
220
204
|
requirements:
|
221
205
|
- - ">="
|
222
206
|
- !ruby/object:Gem::Version
|
223
|
-
hash: 3
|
224
207
|
segments:
|
225
208
|
- 0
|
226
209
|
version: "0"
|
@@ -589,21 +572,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
589
572
|
requirements:
|
590
573
|
- - ">="
|
591
574
|
- !ruby/object:Gem::Version
|
592
|
-
hash: 3
|
593
575
|
segments:
|
594
576
|
- 0
|
595
577
|
version: "0"
|
596
578
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
597
579
|
none: false
|
598
580
|
requirements:
|
599
|
-
- - "
|
581
|
+
- - ">="
|
600
582
|
- !ruby/object:Gem::Version
|
601
|
-
hash: 25
|
602
583
|
segments:
|
603
|
-
-
|
604
|
-
|
605
|
-
- 1
|
606
|
-
version: 1.3.1
|
584
|
+
- 0
|
585
|
+
version: "0"
|
607
586
|
requirements: []
|
608
587
|
|
609
588
|
rubyforge_project:
|