chef 0.9.18 → 0.10.0.beta.0

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 (177) hide show
  1. data/README.rdoc +0 -3
  2. data/distro/arch/etc/rc.d/chef-server +0 -4
  3. data/distro/arch/etc/rc.d/chef-server-webui +0 -4
  4. data/distro/arch/etc/rc.d/chef-solr +0 -4
  5. data/distro/arch/etc/rc.d/chef-solr-indexer +0 -4
  6. data/lib/chef.rb +3 -3
  7. data/lib/chef/api_client.rb +1 -1
  8. data/lib/chef/application.rb +11 -1
  9. data/lib/chef/application/client.rb +18 -22
  10. data/lib/chef/application/knife.rb +28 -29
  11. data/lib/chef/application/solo.rb +14 -12
  12. data/lib/chef/client.rb +112 -54
  13. data/lib/chef/config.rb +4 -0
  14. data/lib/chef/cookbook/chefignore.rb +66 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +6 -5
  16. data/lib/chef/cookbook/cookbook_version_loader.rb +151 -0
  17. data/lib/chef/cookbook/file_system_file_vendor.rb +10 -8
  18. data/lib/chef/cookbook/metadata.rb +200 -108
  19. data/lib/chef/cookbook_loader.rb +39 -163
  20. data/lib/chef/cookbook_uploader.rb +100 -78
  21. data/lib/chef/cookbook_version.rb +92 -47
  22. data/lib/chef/cookbook_version_selector.rb +163 -0
  23. data/lib/chef/couchdb.rb +9 -1
  24. data/lib/chef/data_bag.rb +1 -1
  25. data/lib/chef/data_bag_item.rb +1 -1
  26. data/lib/chef/encrypted_data_bag_item.rb +126 -0
  27. data/lib/chef/environment.rb +386 -0
  28. data/lib/chef/exceptions.rb +82 -1
  29. data/lib/chef/index_queue/amqp_client.rb +15 -12
  30. data/lib/chef/index_queue/indexable.rb +38 -4
  31. data/lib/chef/json_compat.rb +3 -3
  32. data/lib/chef/knife.rb +97 -202
  33. data/lib/chef/knife/bootstrap.rb +27 -61
  34. data/lib/chef/knife/bootstrap/archlinux-gems.erb +4 -2
  35. data/lib/chef/knife/bootstrap/centos5-gems.erb +6 -15
  36. data/lib/chef/knife/bootstrap/fedora13-gems.erb +3 -4
  37. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  38. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -5
  39. data/lib/chef/knife/client_bulk_delete.rb +6 -3
  40. data/lib/chef/knife/client_create.rb +13 -10
  41. data/lib/chef/knife/client_delete.rb +10 -7
  42. data/lib/chef/knife/client_edit.rb +9 -6
  43. data/lib/chef/knife/client_list.rb +8 -5
  44. data/lib/chef/knife/client_reregister.rb +9 -6
  45. data/lib/chef/knife/client_show.rb +9 -6
  46. data/lib/chef/knife/configure.rb +15 -19
  47. data/lib/chef/knife/configure_client.rb +4 -4
  48. data/lib/chef/knife/cookbook_bulk_delete.rb +11 -8
  49. data/lib/chef/knife/cookbook_create.rb +120 -55
  50. data/lib/chef/knife/cookbook_delete.rb +18 -12
  51. data/lib/chef/knife/cookbook_download.rb +10 -6
  52. data/lib/chef/knife/cookbook_list.rb +15 -6
  53. data/lib/chef/knife/cookbook_metadata.rb +41 -21
  54. data/lib/chef/knife/cookbook_metadata_from_file.rb +4 -0
  55. data/lib/chef/knife/cookbook_show.rb +16 -5
  56. data/lib/chef/knife/cookbook_site_download.rb +2 -2
  57. data/lib/chef/knife/cookbook_site_share.rb +18 -13
  58. data/lib/chef/knife/cookbook_site_unshare.rb +7 -4
  59. data/lib/chef/knife/cookbook_site_vendor.rb +21 -18
  60. data/lib/chef/knife/cookbook_test.rb +14 -14
  61. data/lib/chef/knife/cookbook_upload.rb +91 -40
  62. data/lib/chef/knife/data_bag_create.rb +41 -6
  63. data/lib/chef/knife/data_bag_delete.rb +5 -3
  64. data/lib/chef/knife/data_bag_edit.rb +55 -11
  65. data/lib/chef/knife/data_bag_from_file.rb +47 -7
  66. data/lib/chef/knife/data_bag_list.rb +4 -1
  67. data/lib/chef/knife/data_bag_show.rb +44 -4
  68. data/lib/chef/knife/environment_create.rb +53 -0
  69. data/lib/chef/knife/environment_delete.rb +45 -0
  70. data/lib/chef/knife/environment_edit.rb +45 -0
  71. data/lib/chef/knife/environment_from_file.rb +39 -0
  72. data/lib/chef/knife/environment_list.rb +42 -0
  73. data/lib/chef/knife/environment_show.rb +46 -0
  74. data/lib/chef/knife/exec.rb +1 -1
  75. data/lib/chef/knife/index_rebuild.rb +8 -9
  76. data/lib/chef/knife/node_bulk_delete.rb +9 -6
  77. data/lib/chef/knife/node_create.rb +9 -6
  78. data/lib/chef/knife/node_delete.rb +10 -7
  79. data/lib/chef/knife/node_edit.rb +129 -10
  80. data/lib/chef/knife/node_from_file.rb +10 -7
  81. data/lib/chef/knife/node_list.rb +11 -6
  82. data/lib/chef/knife/node_run_list_add.rb +10 -7
  83. data/lib/chef/knife/node_run_list_remove.rb +9 -6
  84. data/lib/chef/knife/node_show.rb +15 -7
  85. data/lib/chef/knife/recipe_list.rb +4 -3
  86. data/lib/chef/knife/role_bulk_delete.rb +9 -6
  87. data/lib/chef/knife/role_create.rb +9 -6
  88. data/lib/chef/knife/role_delete.rb +10 -7
  89. data/lib/chef/knife/role_edit.rb +11 -8
  90. data/lib/chef/knife/role_from_file.rb +10 -7
  91. data/lib/chef/knife/role_list.rb +8 -5
  92. data/lib/chef/knife/role_show.rb +11 -8
  93. data/lib/chef/knife/search.rb +33 -10
  94. data/lib/chef/knife/ssh.rb +33 -61
  95. data/lib/chef/knife/status.rb +7 -4
  96. data/lib/chef/knife/subcommand_loader.rb +101 -0
  97. data/lib/chef/knife/tag_create.rb +31 -0
  98. data/lib/chef/knife/tag_delete.rb +31 -0
  99. data/lib/chef/knife/tag_list.rb +29 -0
  100. data/lib/chef/knife/ui.rb +229 -0
  101. data/lib/chef/knife/windows_bootstrap.rb +8 -5
  102. data/lib/chef/log.rb +5 -59
  103. data/lib/chef/mash.rb +211 -0
  104. data/lib/chef/mixins.rb +1 -2
  105. data/lib/chef/nil_argument.rb +3 -0
  106. data/lib/chef/node.rb +96 -34
  107. data/lib/chef/platform.rb +27 -0
  108. data/lib/chef/provider/cookbook_file.rb +21 -20
  109. data/lib/chef/provider/deploy/revision.rb +3 -0
  110. data/lib/chef/provider/file.rb +20 -11
  111. data/lib/chef/provider/git.rb +26 -26
  112. data/lib/chef/provider/group/aix.rb +70 -0
  113. data/lib/chef/provider/group/groupadd.rb +7 -4
  114. data/lib/chef/provider/group/usermod.rb +1 -1
  115. data/lib/chef/provider/package.rb +28 -28
  116. data/lib/chef/provider/package/dpkg.rb +1 -1
  117. data/lib/chef/provider/package/portage.rb +50 -39
  118. data/lib/chef/provider/package/rubygems.rb +1 -1
  119. data/lib/chef/provider/package/zypper.rb +3 -20
  120. data/lib/chef/provider/remote_directory.rb +0 -2
  121. data/lib/chef/provider/remote_file.rb +2 -3
  122. data/lib/chef/provider/service/arch.rb +28 -35
  123. data/lib/chef/provider/service/simple.rb +1 -1
  124. data/lib/chef/provider/subversion.rb +22 -22
  125. data/lib/chef/providers.rb +1 -0
  126. data/lib/chef/recipe.rb +10 -12
  127. data/lib/chef/resource.rb +49 -42
  128. data/lib/chef/resource/gem_package.rb +7 -3
  129. data/lib/chef/resource/git.rb +5 -5
  130. data/lib/chef/resource/package.rb +7 -7
  131. data/lib/chef/resource/scm.rb +2 -1
  132. data/lib/chef/resource/solaris_package.rb +0 -1
  133. data/lib/chef/resource/yum_package.rb +0 -1
  134. data/lib/chef/rest.rb +7 -16
  135. data/lib/chef/rest/rest_request.rb +0 -16
  136. data/lib/chef/role.rb +67 -13
  137. data/lib/chef/run_context.rb +37 -21
  138. data/lib/chef/run_list.rb +30 -15
  139. data/lib/chef/run_list/run_list_expansion.rb +41 -20
  140. data/lib/chef/run_list/run_list_item.rb +20 -6
  141. data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
  142. data/lib/chef/runner.rb +7 -15
  143. data/lib/chef/search/query.rb +12 -7
  144. data/lib/chef/shef.rb +6 -7
  145. data/lib/chef/shef/shef_session.rb +40 -35
  146. data/lib/chef/shell_out.rb +22 -201
  147. data/lib/chef/shell_out/unix.rb +224 -0
  148. data/lib/chef/shell_out/windows.rb +95 -0
  149. data/lib/chef/solr_query.rb +187 -0
  150. data/lib/chef/solr_query/lucene.treetop +145 -0
  151. data/lib/chef/solr_query/lucene_nodes.rb +285 -0
  152. data/lib/chef/solr_query/query_transform.rb +65 -0
  153. data/lib/chef/solr_query/solr_http_request.rb +118 -0
  154. data/lib/chef/version.rb +4 -2
  155. data/lib/chef/version_class.rb +70 -0
  156. data/lib/chef/version_constraint.rb +116 -0
  157. metadata +68 -37
  158. data/lib/chef/cookbook/metadata/version.rb +0 -87
  159. data/lib/chef/knife/bluebox_images_list.rb +0 -54
  160. data/lib/chef/knife/bluebox_server_create.rb +0 -157
  161. data/lib/chef/knife/bluebox_server_delete.rb +0 -63
  162. data/lib/chef/knife/bluebox_server_list.rb +0 -59
  163. data/lib/chef/knife/ec2_instance_data.rb +0 -46
  164. data/lib/chef/knife/ec2_server_create.rb +0 -218
  165. data/lib/chef/knife/ec2_server_delete.rb +0 -87
  166. data/lib/chef/knife/ec2_server_list.rb +0 -89
  167. data/lib/chef/knife/rackspace_server_create.rb +0 -184
  168. data/lib/chef/knife/rackspace_server_delete.rb +0 -57
  169. data/lib/chef/knife/rackspace_server_list.rb +0 -59
  170. data/lib/chef/knife/slicehost_images_list.rb +0 -53
  171. data/lib/chef/knife/slicehost_server_create.rb +0 -103
  172. data/lib/chef/knife/slicehost_server_delete.rb +0 -61
  173. data/lib/chef/knife/slicehost_server_list.rb +0 -64
  174. data/lib/chef/knife/terremark_server_create.rb +0 -152
  175. data/lib/chef/knife/terremark_server_delete.rb +0 -87
  176. data/lib/chef/knife/terremark_server_list.rb +0 -77
  177. data/lib/chef/mixin/find_preferred_file.rb +0 -92
@@ -3,7 +3,8 @@
3
3
  # Author:: Nuo Yan (<nuoyan@opscode.com>)
4
4
  # Author:: Tim Hinderliter (<tim@opscode.com>)
5
5
  # Author:: Christopher Walters (<cw@opscode.com>)
6
- # Copyright:: Copyright (c) 2008-2010 Opscode, Inc.
6
+ # Author:: Seth Falcon (<seth@opscode.com>)
7
+ # Copyright:: Copyright (c) 2008-2011 Opscode, Inc.
7
8
  # License:: Apache License, Version 2.0
8
9
  #
9
10
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,10 +21,13 @@
20
21
 
21
22
  require 'chef/run_list/run_list_item'
22
23
  require 'chef/run_list/run_list_expansion'
24
+ require 'chef/run_list/versioned_recipe_list'
25
+ require 'chef/mixin/params_validate'
23
26
 
24
27
  class Chef
25
28
  class RunList
26
29
  include Enumerable
30
+ include Chef::Mixin::ParamsValidate
27
31
 
28
32
  # @run_list_items is an array of RunListItems that describe the items to
29
33
  # execute in order. RunListItems can load from and convert to the string
@@ -38,8 +42,8 @@ class Chef
38
42
  # For backwards compat
39
43
  alias :run_list :run_list_items
40
44
 
41
- def initialize
42
- @run_list_items = Array.new
45
+ def initialize(*run_list_items)
46
+ @run_list_items = run_list_items.map { |i| coerce_to_run_list_item(i) }
43
47
  end
44
48
 
45
49
  def role_names
@@ -57,11 +61,13 @@ class Chef
57
61
  # Add an item of the form "recipe[foo::bar]" or "role[webserver]";
58
62
  # takes a String or a RunListItem
59
63
  def <<(run_list_item)
60
- run_list_item = run_list_item.kind_of?(RunListItem) ? run_list_item : parse_entry(run_list_item)
64
+ run_list_item = coerce_to_run_list_item(run_list_item)
61
65
  @run_list_items << run_list_item unless @run_list_items.include?(run_list_item)
62
66
  self
63
67
  end
64
68
 
69
+ alias :push :<<
70
+
65
71
  def ==(other)
66
72
  if other.kind_of?(Chef::RunList)
67
73
  other.run_list_items == @run_list_items
@@ -69,7 +75,7 @@ class Chef
69
75
  return false unless other.respond_to?(:size) && (other.size == @run_list_items.size)
70
76
  other_run_list_items = other.dup
71
77
 
72
- other_run_list_items.map! { |item| item.kind_of?(RunListItem) ? item : RunListItem.new(item) }
78
+ other_run_list_items.map! { |item| coerce_to_run_list_item(item) }
73
79
  other_run_list_items == @run_list_items
74
80
  end
75
81
  end
@@ -78,6 +84,10 @@ class Chef
78
84
  @run_list_items.join(", ")
79
85
  end
80
86
 
87
+ def to_json(*args)
88
+ to_a.to_json(*args)
89
+ end
90
+
81
91
  def empty?
82
92
  @run_list_items.length == 0 ? true : false
83
93
  end
@@ -118,33 +128,38 @@ class Chef
118
128
  @run_list_items.delete_if{|i| i == item}
119
129
  self
120
130
  end
131
+ alias :delete :remove
121
132
 
122
- def expand(data_source='server', couchdb=nil, rest=nil)
123
- couchdb = couchdb ? couchdb : Chef::CouchDB.new
124
-
125
- expansion = expansion_for_data_source(data_source, :couchdb => couchdb, :rest => rest)
133
+ # Expands this run_list: recursively expand roles into their included
134
+ # recipes.
135
+ # Returns a RunListExpansion object.
136
+ def expand(environment, data_source='server', expansion_opts={})
137
+ expansion = expansion_for_data_source(environment, data_source, expansion_opts)
126
138
  expansion.expand
127
139
  expansion
128
140
  end
129
141
 
130
142
  # Converts a string run list entry to a RunListItem object.
131
- # TODO: 5/27/2010 cw: this method has become nothing more than a proxy, revisit its necessity
132
143
  def parse_entry(entry)
133
144
  RunListItem.new(entry)
134
145
  end
135
146
 
136
- def expansion_for_data_source(data_source, opts={})
137
- data_source = 'disk' if Chef::Config[:solo]
147
+ def coerce_to_run_list_item(item)
148
+ item.kind_of?(RunListItem) ? item : parse_entry(item)
149
+ end
150
+
151
+ def expansion_for_data_source(environment, data_source, opts={})
138
152
  case data_source.to_s
139
153
  when 'disk'
140
- RunListExpansionFromDisk.new(@run_list_items)
154
+ RunListExpansionFromDisk.new(environment, @run_list_items)
141
155
  when 'server'
142
- RunListExpansionFromAPI.new(@run_list_items, opts[:rest])
156
+ RunListExpansionFromAPI.new(environment, @run_list_items, opts[:rest])
143
157
  when 'couchdb'
144
- RunListExpansionFromCouchDB.new(@run_list_items, opts[:couchdb])
158
+ RunListExpansionFromCouchDB.new(environment, @run_list_items, opts[:couchdb])
145
159
  end
146
160
  end
147
161
 
162
+
148
163
  end
149
164
  end
150
165
 
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Daniel DeLeo (<dan@opscode.com>)
3
- # Copyright:: Copyright (c) 2010 Opscode, Inc.
3
+ # Author:: Tim Hinderliter (<tim@opscode.com>)
4
+ # Copyright:: Copyright (c) 2010, 2011 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +16,7 @@
15
16
  # See the License for the specific language governing permissions and
16
17
  # limitations under the License.
17
18
 
18
- require 'extlib'
19
+ require 'chef/mash'
19
20
 
20
21
  require 'chef/mixin/deep_merge'
21
22
 
@@ -31,6 +32,8 @@ class Chef
31
32
 
32
33
  attr_reader :run_list_items
33
34
 
35
+ # A VersionedRecipeList of recipes. Populated only after #expand
36
+ # is called.
34
37
  attr_reader :recipes
35
38
 
36
39
  attr_reader :default_attrs
@@ -39,12 +42,15 @@ class Chef
39
42
 
40
43
  attr_reader :errors
41
44
 
45
+ attr_reader :environment
46
+
42
47
  # The data source passed to the constructor. Not used in this class.
43
48
  # In subclasses, this is a couchdb or Chef::REST object pre-configured
44
49
  # to fetch roles from their correct location.
45
50
  attr_reader :source
46
51
 
47
- def initialize(run_list_items, source=nil)
52
+ def initialize(environment, run_list_items, source=nil)
53
+ @environment = environment
48
54
  @errors = Array.new
49
55
 
50
56
  @run_list_items = run_list_items.dup
@@ -53,7 +59,7 @@ class Chef
53
59
  @default_attrs = Mash.new
54
60
  @override_attrs = Mash.new
55
61
 
56
- @recipes = []
62
+ @recipes = Chef::RunList::VersionedRecipeList.new
57
63
 
58
64
  @applied_roles = {}
59
65
  end
@@ -65,20 +71,11 @@ class Chef
65
71
 
66
72
  alias :invalid? :errors?
67
73
 
68
- # Iterates over the run list items, expanding roles. After this,
74
+ # Recurses over the run list items, expanding roles. After this,
69
75
  # +recipes+ will contain the fully expanded recipe list
70
76
  def expand
71
- @run_list_items.each_with_index do |entry, index|
72
- case entry.type
73
- when :recipe
74
- recipes << entry.name unless recipes.include?(entry.name)
75
- when :role
76
- if role = inflate_role(entry.name)
77
- apply_role_attributes(role)
78
- @run_list_items.insert(index + 1, *role.run_list.run_list_items)
79
- end
80
- end
81
- end
77
+ # Sure do miss function arity when being recursive
78
+ expand_run_list_items(@run_list_items)
82
79
  end
83
80
 
84
81
  # Fetches and inflates a role
@@ -101,10 +98,10 @@ class Chef
101
98
  @applied_roles.has_key?(role_name)
102
99
  end
103
100
 
104
- def applied_role(role_name)
105
- @applied_roles[role_name] = true
106
- end
107
-
101
+ # Returns an array of role names that were expanded; this
102
+ # includes any roles that were in the original, pre-expansion
103
+ # run_list as well as roles processed during
104
+ # expansion. Populated only after #expand is called.
108
105
  def roles
109
106
  @applied_roles.keys
110
107
  end
@@ -123,6 +120,30 @@ class Chef
123
120
  @errors << name
124
121
  nil
125
122
  end
123
+
124
+ private
125
+
126
+ # these methods modifies internal state based on arguments, so hide it.
127
+
128
+ def applied_role(role_name)
129
+ @applied_roles[role_name] = true
130
+ end
131
+
132
+ def expand_run_list_items(items)
133
+ if entry = items.shift
134
+ case entry.type
135
+ when :recipe
136
+ recipes.add_recipe(entry.name, entry.version)
137
+ when :role
138
+ if role = inflate_role(entry.name)
139
+ expand_run_list_items(role.run_list_for(@environment).run_list_items)
140
+ apply_role_attributes(role)
141
+ end
142
+ end
143
+ expand_run_list_items(items)
144
+ end
145
+ end
146
+
126
147
  end
127
148
 
128
149
  # Expand a run list from disk. Suitable for chef-solo
@@ -18,27 +18,41 @@
18
18
  class Chef
19
19
  class RunList
20
20
  class RunListItem
21
- QUALIFIED_RECIPE = %r{^recipe\[([^\]]+)\]$}
22
- QUALIFIED_ROLE = %r{^role\[([^\]]+)\]$}
21
+ QUALIFIED_RECIPE = %r{^recipe\[([^\]@]+)(@([0-9]+(\.[0-9]+){1,2}))?\]$}
22
+ QUALIFIED_ROLE = %r{^role\[([^\]]+)\]$}
23
+ VERSIONED_UNQUALIFIED_RECIPE = %r{^([^@]+)(@([0-9]+(\.[0-9]+){1,2}))$}
23
24
 
24
- attr_reader :name
25
+ attr_reader :name, :type, :version
25
26
 
26
- attr_reader :type
27
27
 
28
28
  def initialize(item)
29
+ @version = nil
29
30
  case item
30
31
  when Hash
31
32
  assert_hash_is_valid_run_list_item!(item)
32
33
  @type = (item['type'] || item[:type]).to_sym
33
34
  @name = item['name'] || item[:name]
35
+ if (item.has_key?('version') || item.has_key?(:version))
36
+ @version = item['version'] || item[:version]
37
+ end
34
38
  when String
35
39
  if match = QUALIFIED_RECIPE.match(item)
40
+ # recipe[recipe_name]
41
+ # recipe[recipe_name@1.0.0]
36
42
  @type = :recipe
37
43
  @name = match[1]
44
+ @version = match[3] if match[3]
38
45
  elsif match = QUALIFIED_ROLE.match(item)
46
+ # role[role_name]
39
47
  @type = :role
40
48
  @name = match[1]
49
+ elsif match = VERSIONED_UNQUALIFIED_RECIPE.match(item)
50
+ # recipe_name@1.0.0
51
+ @type = :recipe
52
+ @name = match[1]
53
+ @version = match[3] if match[3]
41
54
  else
55
+ # recipe_name
42
56
  @type = :recipe
43
57
  @name = item
44
58
  end
@@ -48,7 +62,7 @@ class Chef
48
62
  end
49
63
 
50
64
  def to_s
51
- "#{@type}[#{@name}]"
65
+ "#{@type}[#{@name}#{@version ? "@#{@version}" :""}]"
52
66
  end
53
67
 
54
68
  def role?
@@ -63,7 +77,7 @@ class Chef
63
77
  if other.kind_of?(String)
64
78
  self.to_s == other.to_s
65
79
  else
66
- other.respond_to?(:type) && other.respond_to?(:name) && other.type == @type && other.name == @name
80
+ other.respond_to?(:type) && other.respond_to?(:name) && other.respond_to?(:version) && other.type == @type && other.name == @name && other.version == @version
67
81
  end
68
82
  end
69
83
 
@@ -0,0 +1,68 @@
1
+ #
2
+ # Author:: Stephen Delano (<stephen@opscode.com>)
3
+ # Author:: Seth Falcon (<seth@opscode.com>)
4
+ # Copyright:: Copyright 2010 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ require 'chef/version_class'
19
+ require 'chef/version_constraint'
20
+
21
+ # Why does this class exist?
22
+ # Why did we not just modify RunList/RunListItem?
23
+ class Chef
24
+ class RunList
25
+ class VersionedRecipeList < Array
26
+
27
+ def initialize
28
+ super
29
+ @versions = Hash.new
30
+ end
31
+
32
+ def add_recipe(name, version=nil)
33
+ if version && @versions.has_key?(name)
34
+ unless Chef::Version.new(@versions[name]) == Chef::Version.new(version)
35
+ raise Chef::Exceptions::CookbookVersionConflict, "Run list requires #{name} at versions #{@versions[name]} and #{version}"
36
+ end
37
+ end
38
+ @versions[name] = version if version
39
+ self << name unless self.include?(name)
40
+ end
41
+
42
+ def with_versions
43
+ self.map {|recipe_name| {:name => recipe_name, :version => @versions[recipe_name]}}
44
+ end
45
+
46
+ # Return an Array of Hashes, each of the form:
47
+ # {:name => RECIPE_NAME, :version_constraint => Chef::VersionConstraint }
48
+ def with_version_constraints
49
+ self.map do |recipe_name|
50
+ constraint = Chef::VersionConstraint.new(@versions[recipe_name])
51
+ { :name => recipe_name, :version_constraint => constraint }
52
+ end
53
+ end
54
+
55
+ # Return an Array of Strings, each of the form:
56
+ # "NAME@VERSION"
57
+ def with_version_constraints_strings
58
+ self.map do |recipe_name|
59
+ if @versions[recipe_name]
60
+ "#{recipe_name}@#{@versions[recipe_name]}"
61
+ else
62
+ recipe_name
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -8,9 +8,9 @@
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
10
10
  # You may obtain a copy of the License at
11
- #
11
+ #
12
12
  # http://www.apache.org/licenses/LICENSE-2.0
13
- #
13
+ #
14
14
  # Unless required by applicable law or agreed to in writing, software
15
15
  # distributed under the License is distributed on an "AS IS" BASIS,
16
16
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,7 +27,7 @@ class Chef
27
27
  # == Chef::Runner
28
28
  # This class is responsible for executing the steps in a Chef run.
29
29
  class Runner
30
-
30
+
31
31
  attr_reader :run_context
32
32
 
33
33
  attr_reader :delayed_actions
@@ -38,15 +38,7 @@ class Chef
38
38
  @run_context = run_context
39
39
  @delayed_actions = []
40
40
  end
41
-
42
- def build_provider(resource)
43
- provider_class = Chef::Platform.find_provider_for_node(run_context.node, resource)
44
- Chef::Log.debug("#{resource} using #{provider_class.to_s}")
45
- provider = provider_class.new(resource, run_context)
46
- provider.load_current_resource
47
- provider
48
- end
49
-
41
+
50
42
  # Determine the appropriate provider for the given resource, then
51
43
  # execute it.
52
44
  def run_action(resource, action)
@@ -71,7 +63,7 @@ class Chef
71
63
  end
72
64
  end
73
65
  end
74
-
66
+
75
67
  # Iterates over the +resource_collection+ in the +run_context+ calling
76
68
  # +run_action+ for each resource in turn.
77
69
  def converge
@@ -84,7 +76,7 @@ class Chef
84
76
  run_context.resource_collection.execute_each_resource do |resource|
85
77
  begin
86
78
  Chef::Log.debug("Processing #{resource} on #{run_context.node.name}")
87
-
79
+
88
80
  # Execute each of this resource's actions.
89
81
  Array(resource.action).each {|action| run_action(resource, action)}
90
82
  rescue => e
@@ -92,7 +84,7 @@ class Chef
92
84
  raise e unless resource.ignore_failure
93
85
  end
94
86
  end
95
-
87
+
96
88
  # Run all our :delayed actions
97
89
  delayed_actions.each do |notification|
98
90
  Chef::Log.info( "#{notification.notifying_resource} sending #{notification.action}"\
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,10 +18,15 @@
18
18
 
19
19
  require 'chef/config'
20
20
  require 'uri'
21
+ require 'chef/rest'
22
+ require 'chef/node'
23
+ require 'chef/role'
24
+ require 'chef/data_bag'
25
+ require 'chef/data_bag_item'
21
26
 
22
27
  class Chef
23
28
  class Search
24
- class Query
29
+ class Query
25
30
 
26
31
  attr_accessor :rest
27
32
 
@@ -33,7 +38,7 @@ class Chef
33
38
  # it a block, it will handle the paging for you dynamically.
34
39
  def search(type, query="*:*", sort='X_CHEF_id_CHEF_X asc', start=0, rows=1000, &block)
35
40
  raise ArgumentError, "Type must be a string or a symbol!" unless (type.kind_of?(String) || type.kind_of?(Symbol))
36
-
41
+
37
42
  response = @rest.get_rest("search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}")
38
43
  if block
39
44
  response["rows"].each { |o| block.call(o) unless o.nil?}
@@ -46,14 +51,14 @@ class Chef
46
51
  [ response["rows"], response["start"], response["total"] ]
47
52
  end
48
53
  end
49
-
54
+
50
55
  def list_indexes
51
56
  response = @rest.get_rest("search")
52
- end
57
+ end
53
58
 
54
59
  private
55
60
  def escape(s)
56
- s && URI.escape(s.to_s)
61
+ s && URI.escape(s.to_s)
57
62
  end
58
63
  end
59
64
  end