chef 0.8.16 → 0.9.0.a3

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.
Files changed (185) hide show
  1. data/bin/shef +1 -0
  2. data/distro/common/man/man1/chef-server-webui.1 +106 -0
  3. data/distro/common/man/man1/chef-server.1 +0 -1
  4. data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
  5. data/distro/common/man/man1/chef-solr.1 +55 -0
  6. data/distro/common/man/man8/chef-client.8 +4 -2
  7. data/distro/common/man/man8/chef-solo.8 +1 -2
  8. data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
  9. data/distro/common/man/man8/knife.8 +668 -266
  10. data/distro/common/man/man8/shef.8 +45 -0
  11. data/distro/common/markdown/README +3 -0
  12. data/distro/common/markdown/knife.mkd +520 -0
  13. data/distro/debian/etc/default/chef-client +4 -0
  14. data/distro/debian/etc/default/chef-server +6 -0
  15. data/distro/debian/etc/default/chef-server-webui +6 -0
  16. data/distro/debian/etc/default/chef-solr +4 -0
  17. data/distro/debian/etc/default/chef-solr-indexer +4 -0
  18. data/distro/debian/etc/init.d/chef-client +41 -41
  19. data/distro/debian/etc/init.d/chef-server +10 -10
  20. data/distro/debian/etc/init.d/chef-server-webui +121 -0
  21. data/distro/debian/etc/init.d/chef-solr +177 -0
  22. data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
  23. data/distro/redhat/etc/init.d/chef-client +76 -48
  24. data/distro/redhat/etc/init.d/chef-server +85 -51
  25. data/distro/redhat/etc/init.d/chef-server-webui +85 -51
  26. data/distro/redhat/etc/init.d/chef-solr +77 -49
  27. data/distro/redhat/etc/init.d/chef-solr-indexer +77 -48
  28. data/distro/redhat/etc/logrotate.d/chef-client +8 -0
  29. data/distro/redhat/etc/logrotate.d/chef-server +8 -0
  30. data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
  31. data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
  32. data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
  33. data/distro/redhat/etc/sysconfig/chef-client +9 -4
  34. data/distro/redhat/etc/sysconfig/chef-server +10 -6
  35. data/distro/redhat/etc/sysconfig/chef-server-webui +10 -6
  36. data/distro/redhat/etc/sysconfig/chef-solr +3 -4
  37. data/distro/redhat/etc/sysconfig/chef-solr-indexer +3 -3
  38. data/lib/chef.rb +16 -5
  39. data/lib/chef/application/knife.rb +2 -2
  40. data/lib/chef/application/solo.rb +1 -7
  41. data/lib/chef/cache/checksum.rb +12 -5
  42. data/lib/chef/cache/file_cache_by_checksum.rb +52 -0
  43. data/lib/chef/checksum.rb +115 -0
  44. data/lib/chef/client.rb +193 -185
  45. data/lib/chef/config.rb +9 -1
  46. data/lib/chef/cookbook/cookbook_collection.rb +43 -0
  47. data/lib/chef/cookbook/file_system_file_vendor.rb +53 -0
  48. data/lib/chef/cookbook/file_vendor.rb +47 -0
  49. data/lib/chef/cookbook/metadata.rb +34 -35
  50. data/lib/chef/cookbook/metadata/version.rb +1 -1
  51. data/lib/chef/cookbook_loader.rb +70 -45
  52. data/lib/chef/cookbook_version.rb +760 -0
  53. data/lib/chef/couchdb.rb +8 -5
  54. data/lib/chef/data_bag_item.rb +5 -5
  55. data/lib/chef/exceptions.rb +10 -0
  56. data/lib/chef/file_access_control.rb +134 -0
  57. data/lib/chef/handler.rb +62 -0
  58. data/lib/chef/handler/json_file.rb +47 -0
  59. data/lib/chef/knife.rb +14 -2
  60. data/lib/chef/knife/bootstrap.rb +126 -0
  61. data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
  62. data/lib/chef/knife/cookbook_delete.rb +4 -4
  63. data/lib/chef/knife/cookbook_download.rb +57 -26
  64. data/lib/chef/knife/cookbook_metadata.rb +2 -2
  65. data/lib/chef/knife/cookbook_show.rb +30 -11
  66. data/lib/chef/knife/cookbook_upload.rb +113 -86
  67. data/lib/chef/knife/ec2_server_create.rb +146 -0
  68. data/lib/chef/knife/ec2_server_delete.rb +84 -0
  69. data/lib/chef/knife/ec2_server_list.rb +82 -0
  70. data/lib/chef/knife/status.rb +51 -0
  71. data/lib/chef/mixin/language_include_attribute.rb +16 -11
  72. data/lib/chef/mixin/language_include_recipe.rb +15 -16
  73. data/lib/chef/mixin/recipe_definition_dsl_core.rb +17 -20
  74. data/lib/chef/mixin/shell_out.rb +38 -0
  75. data/lib/chef/mixins.rb +1 -1
  76. data/lib/chef/node.rb +190 -63
  77. data/lib/chef/node/attribute.rb +92 -78
  78. data/lib/chef/platform.rb +24 -4
  79. data/lib/chef/provider.rb +28 -10
  80. data/lib/chef/provider/breakpoint.rb +2 -2
  81. data/lib/chef/provider/cookbook_file.rb +96 -0
  82. data/lib/chef/provider/cron.rb +2 -2
  83. data/lib/chef/provider/deploy.rb +12 -10
  84. data/lib/chef/provider/env.rb +152 -0
  85. data/lib/chef/provider/env/windows.rb +75 -0
  86. data/lib/chef/provider/file.rb +10 -14
  87. data/lib/chef/provider/group.rb +15 -2
  88. data/lib/chef/provider/group/dscl.rb +17 -25
  89. data/lib/chef/provider/group/gpasswd.rb +6 -3
  90. data/lib/chef/provider/group/pw.rb +3 -7
  91. data/lib/chef/provider/group/windows.rb +79 -0
  92. data/lib/chef/provider/link.rb +4 -5
  93. data/lib/chef/provider/mdadm.rb +25 -18
  94. data/lib/chef/provider/mount/mount.rb +28 -27
  95. data/lib/chef/provider/package.rb +35 -35
  96. data/lib/chef/provider/package/dpkg.rb +13 -10
  97. data/lib/chef/provider/package/easy_install.rb +6 -6
  98. data/lib/chef/provider/package/freebsd.rb +17 -51
  99. data/lib/chef/provider/package/rpm.rb +1 -1
  100. data/lib/chef/provider/package/rubygems.rb +391 -74
  101. data/lib/chef/provider/package/yum.rb +2 -2
  102. data/lib/chef/provider/package/zypper.rb +2 -1
  103. data/lib/chef/provider/remote_directory.rb +60 -83
  104. data/lib/chef/provider/remote_file.rb +17 -66
  105. data/lib/chef/provider/script.rb +20 -9
  106. data/lib/chef/provider/service.rb +23 -30
  107. data/lib/chef/provider/service/arch.rb +3 -3
  108. data/lib/chef/provider/service/debian.rb +22 -17
  109. data/lib/chef/provider/service/freebsd.rb +4 -4
  110. data/lib/chef/provider/service/init.rb +2 -2
  111. data/lib/chef/provider/service/redhat.rb +14 -16
  112. data/lib/chef/provider/service/simple.rb +7 -3
  113. data/lib/chef/provider/service/solaris.rb +85 -0
  114. data/lib/chef/provider/service/upstart.rb +12 -7
  115. data/lib/chef/provider/service/windows.rb +2 -2
  116. data/lib/chef/provider/template.rb +133 -118
  117. data/lib/chef/provider/user.rb +34 -17
  118. data/lib/chef/provider/user/dscl.rb +117 -114
  119. data/lib/chef/provider/user/windows.rb +124 -0
  120. data/lib/chef/providers.rb +7 -0
  121. data/lib/chef/recipe.rb +39 -20
  122. data/lib/chef/resource.rb +47 -52
  123. data/lib/chef/resource/apt_package.rb +4 -4
  124. data/lib/chef/resource/bash.rb +4 -4
  125. data/lib/chef/resource/cookbook_file.rb +45 -0
  126. data/lib/chef/resource/cron.rb +3 -3
  127. data/lib/chef/resource/csh.rb +4 -4
  128. data/lib/chef/resource/deploy.rb +3 -3
  129. data/lib/chef/resource/directory.rb +4 -4
  130. data/lib/chef/resource/dpkg_package.rb +4 -4
  131. data/lib/chef/resource/easy_install_package.rb +3 -3
  132. data/lib/chef/resource/env.rb +58 -0
  133. data/lib/chef/resource/erl_call.rb +3 -3
  134. data/lib/chef/resource/execute.rb +3 -3
  135. data/lib/chef/resource/file.rb +3 -3
  136. data/lib/chef/resource/freebsd_package.rb +3 -3
  137. data/lib/chef/resource/gem_package.rb +17 -9
  138. data/lib/chef/resource/git.rb +3 -3
  139. data/lib/chef/resource/group.rb +3 -3
  140. data/lib/chef/resource/http_request.rb +4 -4
  141. data/lib/chef/resource/ifconfig.rb +3 -3
  142. data/lib/chef/resource/link.rb +3 -3
  143. data/lib/chef/resource/log.rb +2 -2
  144. data/lib/chef/resource/macports_package.rb +2 -2
  145. data/lib/chef/resource/mdadm.rb +3 -3
  146. data/lib/chef/resource/mount.rb +2 -2
  147. data/lib/chef/resource/package.rb +4 -4
  148. data/lib/chef/resource/pacman_package.rb +4 -4
  149. data/lib/chef/resource/perl.rb +4 -4
  150. data/lib/chef/resource/portage_package.rb +4 -4
  151. data/lib/chef/resource/python.rb +4 -4
  152. data/lib/chef/resource/remote_directory.rb +3 -3
  153. data/lib/chef/resource/remote_file.rb +26 -3
  154. data/lib/chef/resource/route.rb +3 -3
  155. data/lib/chef/resource/ruby.rb +3 -3
  156. data/lib/chef/resource/ruby_block.rb +3 -2
  157. data/lib/chef/resource/scm.rb +7 -5
  158. data/lib/chef/resource/script.rb +4 -4
  159. data/lib/chef/resource/service.rb +3 -3
  160. data/lib/chef/resource/subversion.rb +4 -2
  161. data/lib/chef/resource/template.rb +3 -3
  162. data/lib/chef/resource/user.rb +3 -3
  163. data/lib/chef/resource/yum_package.rb +3 -3
  164. data/lib/chef/resource_collection.rb +9 -5
  165. data/lib/chef/resources.rb +2 -0
  166. data/lib/chef/rest.rb +4 -0
  167. data/lib/chef/role.rb +2 -0
  168. data/lib/chef/run_context.rb +108 -0
  169. data/lib/chef/run_list.rb +75 -98
  170. data/lib/chef/run_list/run_list_expansion.rb +156 -0
  171. data/lib/chef/run_list/run_list_item.rb +71 -0
  172. data/lib/chef/runner.rb +58 -61
  173. data/lib/chef/sandbox.rb +147 -0
  174. data/lib/chef/shef.rb +4 -3
  175. data/lib/chef/shef/ext.rb +12 -4
  176. data/lib/chef/shef/shef_session.rb +27 -23
  177. data/lib/chef/shell_out.rb +375 -0
  178. data/lib/chef/util/windows.rb +56 -0
  179. data/lib/chef/util/windows/net_group.rb +101 -0
  180. data/lib/chef/util/windows/net_user.rb +198 -0
  181. data/lib/chef/version.rb +20 -0
  182. metadata +112 -22
  183. data/lib/chef/compile.rb +0 -158
  184. data/lib/chef/cookbook.rb +0 -201
  185. data/lib/chef/mixin/generate_url.rb +0 -58
@@ -0,0 +1,156 @@
1
+ #
2
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
3
+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'extlib'
19
+
20
+ require 'chef/mixin/deep_merge'
21
+
22
+ require 'chef/role'
23
+ require 'chef/couchdb'
24
+ require 'chef/rest'
25
+
26
+ class Chef
27
+ class RunList
28
+ # Abstract Base class for expanding a run list. Subclasses must handle
29
+ # fetching roles from a data source by defining +fetch_role+
30
+ class RunListExpansion
31
+
32
+ attr_reader :run_list_items
33
+
34
+ attr_reader :recipes
35
+
36
+ attr_reader :default_attrs
37
+
38
+ attr_reader :override_attrs
39
+
40
+ # The data source passed to the constructor. Not used in this class.
41
+ # In subclasses, this is a couchdb or Chef::REST object pre-configured
42
+ # to fetch roles from their correct location.
43
+ attr_reader :source
44
+
45
+ def initialize(run_list_items, source=nil)
46
+ @run_list_items = run_list_items.dup
47
+ @source = source
48
+
49
+ @default_attrs = Mash.new
50
+ @override_attrs = Mash.new
51
+
52
+ @recipes = []
53
+
54
+ @applied_roles = {}
55
+ end
56
+
57
+ # Iterates over the run list items, expanding roles. After this,
58
+ # +recipes+ will the fully expanded recipe list
59
+ def expand
60
+ @run_list_items.each_with_index do |entry, index|
61
+ case entry.type
62
+ when :recipe
63
+ recipes << entry.name unless recipes.include?(entry.name)
64
+ when :role
65
+ if role = inflate_role(entry.name)
66
+ apply_role_attributes(role)
67
+ @run_list_items.insert(index + 1, *role.run_list.run_list_items)
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ # Fetches and inflates a role
74
+ # === Returns
75
+ # Chef::Role in most cases
76
+ # false if the role has already been applied
77
+ # nil if the role does not exist
78
+ def inflate_role(role_name)
79
+ return false if applied_role?(role_name) # Prevent infinite loops
80
+ applied_role(role_name)
81
+ fetch_role(role_name)
82
+ end
83
+
84
+ def apply_role_attributes(role)
85
+ @default_attrs = Chef::Mixin::DeepMerge.merge(@default_attrs, role.default_attributes)
86
+ @override_attrs = Chef::Mixin::DeepMerge.merge(@override_attrs, role.override_attributes)
87
+ end
88
+
89
+ def applied_role?(role_name)
90
+ @applied_roles.has_key?(role_name)
91
+ end
92
+
93
+ def applied_role(role_name)
94
+ @applied_roles[role_name] = true
95
+ end
96
+
97
+ # In subclasses, this method will fetch the role from the data source.
98
+ def fetch_role(name)
99
+ raise NotImplementedError
100
+ end
101
+
102
+ # When a role is not found, an error message should be logged, but no
103
+ # exception should be raised
104
+ # === Returns
105
+ # nil
106
+ def role_not_found(name)
107
+ Chef::Log.error("Role #{name} is in the runlist but does not exist. Skipping expand.")
108
+ nil
109
+ end
110
+ end
111
+
112
+ # Expand a run list from disk. Suitable for chef-solo
113
+ class RunListExpansionFromDisk < RunListExpansion
114
+
115
+ def fetch_role(name)
116
+ Chef::Role.from_disk(name)
117
+ rescue Chef::Exceptions::RoleNotFound
118
+ role_not_found(name)
119
+ end
120
+
121
+ end
122
+
123
+ # Expand a run list from the chef-server API.
124
+ class RunListExpansionFromAPI < RunListExpansion
125
+
126
+ def rest
127
+ @rest ||= (source || Chef::REST.new(Chef::Config[:role_url]))
128
+ end
129
+
130
+ def fetch_role(name)
131
+ rest.get_rest("roles/#{name}")
132
+ rescue Net::HTTPServerException => e
133
+ if e.message == '404 "Not Found"'
134
+ role_not_found(name)
135
+ else
136
+ raise
137
+ end
138
+ end
139
+ end
140
+
141
+ # Expand a run list from couchdb. Used in chef-server-api
142
+ class RunListExpansionFromCouchDB < RunListExpansion
143
+
144
+ def couchdb
145
+ source
146
+ end
147
+
148
+ def fetch_role(name)
149
+ Chef::Role.cdb_load(name, couchdb)
150
+ rescue Chef::Exceptions::CouchDBNotFound
151
+ role_not_found(name)
152
+ end
153
+
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,71 @@
1
+ #
2
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
3
+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ class Chef
19
+ class RunList
20
+ class RunListItem
21
+ QUALIFIED_RECIPE = %r{^recipe\[([^\]]+)\]$}
22
+ QUALIFIED_ROLE = %r{^role\[([^\]]+)\]$}
23
+
24
+ attr_reader :name
25
+
26
+ attr_reader :type
27
+
28
+ def initialize(item)
29
+ case item
30
+ when Hash
31
+ raise ArgumentError, "Initializing a #{self.class} from a hash requires that it have a 'type' and 'name' key" unless (item.has_key?('type')||item.has_key?(:type)) && (item.has_key?('name')||item.has_key?(:name))
32
+ @type = (item['type'] || item[:type]).to_sym
33
+ @name = item['name'] || item[:name]
34
+ when String
35
+ if match = QUALIFIED_RECIPE.match(item)
36
+ @type = :recipe
37
+ @name = match[1]
38
+ elsif match = QUALIFIED_ROLE.match(item)
39
+ @type = :role
40
+ @name = match[1]
41
+ else
42
+ @type = :recipe
43
+ @name = item
44
+ end
45
+ else
46
+ raise ArgumentError, "Unable to create #{self.class} from #{item.class}:#{item.inspect}: must be a Hash or String"
47
+ end
48
+ end
49
+
50
+ def to_s
51
+ "#{@type}[#{@name}]"
52
+ end
53
+
54
+ def role?
55
+ @type == :role
56
+ end
57
+
58
+ def recipe?
59
+ @type == :recipe
60
+ end
61
+
62
+ def ==(other)
63
+ if other.kind_of?(String)
64
+ self.to_s == other.to_s
65
+ else
66
+ other.respond_to?(:type) && other.respond_to?(:name) && other.type == @type && other.name == @name
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,6 +1,8 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Author:: Christopher Walters (<cw@opscode.com>)
4
+ # Author:: Tim Hinderliter (<tim@opscode.com>)
5
+ # Copyright:: Copyright (c) 2008, 2010 Opscode, Inc.
4
6
  # License:: Apache License, Version 2.0
5
7
  #
6
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,78 +23,67 @@ require 'chef/node'
21
23
  require 'chef/resource_collection'
22
24
  require 'chef/platform'
23
25
 
26
+ # This class is responsible for executing the steps in a Chef run.
24
27
  class Chef
25
28
  class Runner
26
29
 
27
- include Chef::Mixin::ParamsValidate
30
+ attr_reader :run_context
28
31
 
29
- def initialize(node, collection, definitions={}, cookbook_loader=nil)
30
- validate(
31
- {
32
- :node => node,
33
- :collection => collection,
34
- },
35
- {
36
- :node => {
37
- :kind_of => Chef::Node,
38
- },
39
- :collection => {
40
- :kind_of => Chef::ResourceCollection,
41
- },
42
- }
43
- )
44
- @node = node
45
- @collection = collection
46
- @definitions = definitions
47
- @cookbook_loader = cookbook_loader
32
+ include Chef::Mixin::ParamsValidate
33
+
34
+ def initialize(run_context)
35
+ @run_context = run_context
48
36
  end
49
37
 
50
38
  def build_provider(resource)
51
- provider_klass = Chef::Platform.find_provider_for_node(@node, resource)
52
- Chef::Log.debug("#{resource} using #{provider_klass.to_s}")
53
- provider = provider_klass.new(@node, resource, @collection, @definitions, @cookbook_loader)
39
+ provider_class = Chef::Platform.find_provider_for_node(run_context.node, resource)
40
+ Chef::Log.debug("#{resource} using #{provider_class.to_s}")
41
+ provider = provider_class.new(resource, run_context)
54
42
  provider.load_current_resource
55
43
  provider
56
44
  end
57
-
58
- def run_action(resource, ra)
45
+
46
+ # Determine the appropriate provider for the given resource, then
47
+ # execute it.
48
+ def run_action(resource, action, delayed_actions)
59
49
  provider = build_provider(resource)
60
- provider.send("action_#{ra}")
61
-
50
+ provider.send("action_#{action}")
51
+
52
+ # Execute any immediate and queue up any delayed notifications
53
+ # associated with the resource.
62
54
  if resource.updated
63
- resource.actions.each_key do |action|
64
- if resource.actions[action].has_key?(:immediate)
65
- resource.actions[action][:immediate].each do |r|
66
- Chef::Log.info("#{resource} sending #{action} action to #{r} (immediate)")
67
- run_action(r, action)
68
- end
69
- end
70
- if resource.actions[action].has_key?(:delayed)
71
- resource.actions[action][:delayed].each do |r|
72
- @delayed_actions[r] = Hash.new unless @delayed_actions.has_key?(r)
73
- unless @delayed_actions[r].has_key?(action)
74
- @ordered_delayed_actions << [r, action]
75
- @delayed_actions[r][action] = Array.new
76
- end
77
- @delayed_actions[r][action] << lambda {
78
- Chef::Log.info("#{resource} sending #{action} action to #{r} (delayed)")
79
- }
80
- end
55
+ resource.notifies_immediate.each do |notify|
56
+ Chef::Log.info("#{resource} sending #{notify.action} action to #{notify.resource} (immediate)")
57
+ run_action(notify.resource, notify.action, delayed_actions)
58
+ end
59
+
60
+ resource.notifies_delayed.each do |notify|
61
+ unless delayed_actions.include?(notify)
62
+ delayed_actions << notify
63
+ delayed_actions << lambda {
64
+ Chef::Log.info("#{resource} sending #{notify.action} action to #{notify.resource} (delayed)")
65
+ }
66
+ else
67
+ delayed_actions << lambda {
68
+ Chef::Log.info("#{resource} not sending #{notify.action} action to #{notify.resource} (delayed), as it's already been queued")
69
+ }
81
70
  end
82
71
  end
83
72
  end
84
73
  end
85
-
74
+
75
+ # Executes a Chef run.
86
76
  def converge
87
-
88
- @delayed_actions = Hash.new
89
- @ordered_delayed_actions = []
77
+ delayed_actions = Array.new
90
78
 
91
- @collection.execute_each_resource do |resource|
79
+ # Execute each resource.
80
+ run_context.resource_collection.execute_each_resource do |resource|
92
81
  begin
93
- Chef::Log.debug("Processing #{resource}")
82
+ Chef::Log.debug("Processing #{resource} on #{run_context.node.name}")
94
83
 
95
- # Check if this resource has an only_if block - if it does, skip it.
84
+ # Check if this resource has an only_if block -- if it does,
85
+ # evaluate the only_if block and skip the resource if
86
+ # appropriate.
96
87
  if resource.only_if
97
88
  unless Chef::Mixin::Command.only_if(resource.only_if, resource.only_if_args)
98
89
  Chef::Log.debug("Skipping #{resource} due to only_if")
@@ -100,7 +91,9 @@ class Chef
100
91
  end
101
92
  end
102
93
 
103
- # Check if this resource has a not_if block - if it does, skip it.
94
+ # Check if this resource has a not_if block -- if it does,
95
+ # evaluate the not_if block and skip the resource if
96
+ # appropriate.
104
97
  if resource.not_if
105
98
  unless Chef::Mixin::Command.not_if(resource.not_if, resource.not_if_args)
106
99
  Chef::Log.debug("Skipping #{resource} due to not_if")
@@ -108,10 +101,10 @@ class Chef
108
101
  end
109
102
  end
110
103
 
111
- # Walk the actions for this resource, building the provider and running each.
104
+ # Execute each of this resource's actions.
112
105
  action_list = resource.action.kind_of?(Array) ? resource.action : [ resource.action ]
113
- action_list.each do |ra|
114
- run_action(resource, ra)
106
+ action_list.each do |action|
107
+ run_action(resource, action, delayed_actions)
115
108
  end
116
109
  rescue => e
117
110
  Chef::Log.error("#{resource} (#{resource.source_line}) had an error:\n#{e}\n#{e.backtrace.join("\n")}")
@@ -120,10 +113,14 @@ class Chef
120
113
  end
121
114
 
122
115
  # Run all our :delayed actions
123
- @ordered_delayed_actions.each do |resource, action|
124
- log_array = @delayed_actions[resource][action]
125
- log_array.each { |l| l.call } # Call each log message
126
- run_action(resource, action)
116
+ delayed_actions.each do |notify_or_lambda|
117
+ if notify_or_lambda.is_a?(Proc)
118
+ # log message
119
+ notify_or_lambda.call
120
+ else
121
+ # OpenStruct of resource/action to call
122
+ run_action(notify_or_lambda.resource, notify_or_lambda.action, delayed_actions)
123
+ end
127
124
  end
128
125
 
129
126
  true
@@ -0,0 +1,147 @@
1
+ #
2
+ # Author:: Tim Hinderliter (<tim@opscode.com>)
3
+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'chef/log'
19
+ require 'uuidtools'
20
+
21
+ class Chef
22
+ class Sandbox
23
+ attr_accessor :is_completed, :create_time
24
+ alias_method :is_completed?, :is_completed
25
+ attr_reader :guid
26
+
27
+ alias :name :guid
28
+
29
+ attr_accessor :couchdb, :couchdb_id, :couchdb_rev
30
+
31
+ # list of checksum ids
32
+ attr_accessor :checksums
33
+
34
+ DESIGN_DOCUMENT = {
35
+ "version" => 1,
36
+ "language" => "javascript",
37
+ "views" => {
38
+ "all" => {
39
+ "map" => <<-EOJS
40
+ function(doc) {
41
+ if (doc.chef_type == "sandbox") {
42
+ emit(doc.guid, doc);
43
+ }
44
+ }
45
+ EOJS
46
+ },
47
+ "all_id" => {
48
+ "map" => <<-EOJS
49
+ function(doc) {
50
+ if (doc.chef_type == "sandbox") {
51
+ emit(doc.guid, doc.guid);
52
+ }
53
+ }
54
+ EOJS
55
+ },
56
+ "all_incomplete" => {
57
+ "map" => <<-EOJS
58
+ function(doc) {
59
+ if (doc.chef_type == "sandbox" && !doc.is_completed) {
60
+ emit(doc.guid, doc.guid);
61
+ }
62
+ }
63
+ EOJS
64
+ },
65
+ "all_completed" => {
66
+ "map" => <<-EOJS
67
+ function(doc) {
68
+ if (doc.chef_type == "sandbox" && doc.is_completed) {
69
+ emit(doc.guid, doc.guid);
70
+ }
71
+ }
72
+ EOJS
73
+ },
74
+ }
75
+ }
76
+
77
+ # Creates a new Chef::Sandbox object.
78
+ #
79
+ # === Returns
80
+ # object<Chef::Sandbox>:: Duh. :)
81
+ def initialize(guid=nil, couchdb=nil)
82
+ @guid = guid || UUIDTools::UUID.random_create.to_s.gsub(/\-/,'').downcase
83
+ @is_completed = false
84
+ @create_time = Time.now.iso8601
85
+ @checksums = Array.new
86
+ end
87
+
88
+ def to_json(*a)
89
+ result = {
90
+ :guid => guid,
91
+ :name => name, # same as guid, used for id_map
92
+ :checksums => checksums,
93
+ :create_time => create_time,
94
+ :is_completed => is_completed,
95
+ :json_class => self.class.name,
96
+ :chef_type => 'sandbox'
97
+ }
98
+ result["_rev"] = @couchdb_rev if @couchdb_rev
99
+ result.to_json(*a)
100
+ end
101
+
102
+ def self.json_create(o)
103
+ sandbox = new(o['guid'])
104
+ sandbox.checksums = o['checksums']
105
+ sandbox.create_time = o['create_time']
106
+ sandbox.is_completed = o['is_completed']
107
+ if o.has_key?('_rev')
108
+ sandbox.couchdb_rev = o["_rev"]
109
+ o.delete("_rev")
110
+ end
111
+ if o.has_key?("_id")
112
+ sandbox.couchdb_id = o["_id"]
113
+ #sandbox.index_id = sandbox.couchdb_id
114
+ o.delete("_id")
115
+ end
116
+ sandbox
117
+ end
118
+
119
+ ##
120
+ # Couchdb
121
+ ##
122
+
123
+ def self.create_design_document(couchdb=nil)
124
+ (couchdb || Chef::CouchDB.new).create_design_document("sandboxes", DESIGN_DOCUMENT)
125
+ end
126
+
127
+ def self.cdb_list(inflate=false, couchdb=nil)
128
+ rs = (couchdb || Chef::CouchDB.new).list("sandboxes", inflate)
129
+ lookup = (inflate ? "value" : "key")
130
+ rs["rows"].collect { |r| r[lookup] }
131
+ end
132
+
133
+ def self.cdb_load(guid, couchdb=nil)
134
+ # Probably want to look for a view here at some point
135
+ (couchdb || Chef::CouchDB.new).load("sandbox", guid)
136
+ end
137
+
138
+ def cdb_destroy
139
+ (couchdb || Chef::CouchDB.new).delete("sandbox", guid, @couchdb_rev)
140
+ end
141
+
142
+ def cdb_save(couchdb=nil)
143
+ @couchdb_rev = (couchdb || Chef::CouchDB.new).store("sandbox", guid, self)["rev"]
144
+ end
145
+
146
+ end
147
+ end