chef 0.8.10 → 0.8.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chef might be problematic. Click here for more details.

Files changed (105) hide show
  1. data/bin/chef-client +2 -2
  2. data/bin/chef-solo +1 -2
  3. data/bin/knife +1 -2
  4. data/bin/shef +2 -5
  5. data/lib/chef.rb +11 -7
  6. data/lib/chef/application.rb +25 -20
  7. data/lib/chef/application/client.rb +12 -7
  8. data/lib/chef/application/knife.rb +7 -1
  9. data/lib/chef/application/solo.rb +1 -1
  10. data/lib/chef/applications.rb +4 -0
  11. data/lib/chef/cache/checksum.rb +7 -6
  12. data/lib/chef/certificate.rb +2 -2
  13. data/lib/chef/client.rb +28 -4
  14. data/lib/chef/config.rb +4 -3
  15. data/lib/chef/cookbook_loader.rb +6 -1
  16. data/lib/chef/daemon.rb +2 -0
  17. data/lib/chef/data_bag_item.rb +2 -1
  18. data/lib/chef/exceptions.rb +5 -0
  19. data/lib/chef/file_cache.rb +18 -18
  20. data/lib/chef/index_queue/indexable.rb +5 -3
  21. data/lib/chef/knife.rb +45 -13
  22. data/lib/chef/knife/client_list.rb +1 -1
  23. data/lib/chef/knife/client_show.rb +1 -1
  24. data/lib/chef/knife/configure.rb +47 -36
  25. data/lib/chef/knife/cookbook_list.rb +1 -1
  26. data/lib/chef/knife/cookbook_metadata.rb +22 -27
  27. data/lib/chef/knife/cookbook_metadata_from_file.rb +40 -0
  28. data/lib/chef/knife/cookbook_show.rb +2 -2
  29. data/lib/chef/knife/cookbook_site_download.rb +57 -0
  30. data/lib/chef/knife/cookbook_site_list.rb +55 -0
  31. data/lib/chef/knife/cookbook_site_search.rb +50 -0
  32. data/lib/chef/knife/cookbook_site_show.rb +56 -0
  33. data/lib/chef/knife/cookbook_site_vendor.rb +114 -0
  34. data/lib/chef/knife/cookbook_test.rb +103 -0
  35. data/lib/chef/knife/cookbook_upload.rb +29 -38
  36. data/lib/chef/knife/data_bag_edit.rb +1 -1
  37. data/lib/chef/knife/data_bag_list.rb +2 -2
  38. data/lib/chef/knife/data_bag_show.rb +1 -1
  39. data/lib/chef/knife/ec2_instance_data.rb +1 -1
  40. data/lib/chef/knife/index_rebuild.rb +2 -2
  41. data/lib/chef/knife/node_from_file.rb +1 -1
  42. data/lib/chef/knife/node_list.rb +2 -2
  43. data/lib/chef/knife/node_run_list_add.rb +1 -1
  44. data/lib/chef/knife/node_run_list_remove.rb +1 -1
  45. data/lib/chef/knife/node_show.rb +1 -1
  46. data/lib/chef/knife/rackspace_server_create.rb +156 -0
  47. data/lib/chef/knife/rackspace_server_delete.rb +57 -0
  48. data/lib/chef/knife/rackspace_server_list.rb +59 -0
  49. data/lib/chef/knife/role_from_file.rb +1 -1
  50. data/lib/chef/knife/role_list.rb +1 -1
  51. data/lib/chef/knife/role_show.rb +1 -1
  52. data/lib/chef/knife/search.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +21 -4
  54. data/lib/chef/knife/terremark_server_create.rb +152 -0
  55. data/lib/chef/knife/terremark_server_delete.rb +87 -0
  56. data/lib/chef/knife/terremark_server_list.rb +77 -0
  57. data/lib/chef/mixin/command.rb +11 -9
  58. data/lib/chef/mixin/params_validate.rb +1 -1
  59. data/lib/chef/mixin/recipe_definition_dsl_core.rb +4 -1
  60. data/lib/chef/mixin/template.rb +6 -5
  61. data/lib/chef/mixin/xml_escape.rb +3 -3
  62. data/lib/chef/mixins.rb +16 -0
  63. data/lib/chef/node.rb +53 -52
  64. data/lib/chef/openid_registration.rb +0 -1
  65. data/lib/chef/platform.rb +171 -137
  66. data/lib/chef/provider.rb +2 -2
  67. data/lib/chef/provider/cron.rb +22 -22
  68. data/lib/chef/provider/deploy/revision.rb +5 -1
  69. data/lib/chef/provider/erl_call.rb +2 -2
  70. data/lib/chef/provider/file.rb +44 -23
  71. data/lib/chef/provider/group/dscl.rb +6 -4
  72. data/lib/chef/provider/mdadm.rb +0 -4
  73. data/lib/chef/provider/mount/mount.rb +20 -8
  74. data/lib/chef/provider/package.rb +1 -1
  75. data/lib/chef/provider/package/freebsd.rb +22 -18
  76. data/lib/chef/provider/package/rubygems.rb +7 -10
  77. data/lib/chef/provider/remote_directory.rb +15 -0
  78. data/lib/chef/provider/remote_file.rb +73 -50
  79. data/lib/chef/provider/script.rb +10 -8
  80. data/lib/chef/provider/service/windows.rb +129 -0
  81. data/lib/chef/provider/subversion.rb +1 -1
  82. data/lib/chef/provider/template.rb +51 -50
  83. data/lib/chef/providers.rb +80 -0
  84. data/lib/chef/recipe.rb +2 -4
  85. data/lib/chef/resource.rb +21 -7
  86. data/lib/chef/resource/cron.rb +14 -5
  87. data/lib/chef/resource/deploy.rb +52 -45
  88. data/lib/chef/resource/execute.rb +1 -1
  89. data/lib/chef/resource/file.rb +16 -8
  90. data/lib/chef/resource/mount.rb +1 -1
  91. data/lib/chef/resource/remote_directory.rb +19 -10
  92. data/lib/chef/resource/scm.rb +23 -16
  93. data/lib/chef/resource/service.rb +10 -1
  94. data/lib/chef/resources.rb +60 -0
  95. data/lib/chef/rest.rb +234 -189
  96. data/lib/chef/rest/auth_credentials.rb +78 -0
  97. data/lib/chef/{application/server.rb → rest/cookie_jar.rb} +18 -6
  98. data/lib/chef/rest/rest_request.rb +151 -0
  99. data/lib/chef/role.rb +38 -46
  100. data/lib/chef/streaming_cookbook_uploader.rb +8 -2
  101. data/lib/chef/tasks/chef_repo.rake +14 -4
  102. data/lib/chef/util/file_edit.rb +0 -1
  103. data/lib/chef/webui_user.rb +0 -1
  104. metadata +46 -9
  105. data/distro/suse/etc/init.d/chef-client +0 -121
@@ -0,0 +1,78 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Thom May (<thom@clearairturbulence.org>)
4
+ # Author:: Nuo Yan (<nuo@opscode.com>)
5
+ # Author:: Christopher Brown (<cb@opscode.com>)
6
+ # Author:: Christopher Walters (<cw@opscode.com>)
7
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
8
+ # Copyright:: Copyright (c) 2009, 2010 Opscode, Inc.
9
+ # License:: Apache License, Version 2.0
10
+ #
11
+ # Licensed under the Apache License, Version 2.0 (the "License");
12
+ # you may not use this file except in compliance with the License.
13
+ # You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ #
23
+ require 'chef/exceptions'
24
+ require 'mixlib/authentication/signedheaderauth'
25
+
26
+ class Chef
27
+ class REST
28
+ class AuthCredentials
29
+ attr_reader :key_file, :client_name, :key, :raw_key
30
+
31
+ def initialize(client_name=nil, key_file=nil)
32
+ @client_name, @key_file = client_name, key_file
33
+ load_signing_key if sign_requests?
34
+ end
35
+
36
+ def sign_requests?
37
+ !!key_file
38
+ end
39
+
40
+ def signature_headers(request_params={})
41
+ raise ArgumentError, "Cannot sign the request without a client name, check that :node_name is assigned" if client_name.nil?
42
+ Chef::Log.debug("Signing the request as #{client_name}")
43
+
44
+ # params_in = {:http_method => :GET, :path => "/clients", :body => "", :host => "localhost"}
45
+ request_params = request_params.dup
46
+ request_params[:timestamp] = Time.now.utc.iso8601
47
+ request_params[:user_id] = client_name
48
+ host = request_params.delete(:host) || "localhost"
49
+
50
+ sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params)
51
+ signed = sign_obj.sign(key).merge({:host => host})
52
+ signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo}
53
+ end
54
+
55
+ private
56
+
57
+ def load_signing_key
58
+ begin
59
+ @raw_key = IO.read(key_file)
60
+ rescue SystemCallError, IOError => e
61
+ Chef::Log.fatal "Failed to read the private key #{key_file}: #{e.inspect}, #{e.backtrace}"
62
+ raise Chef::Exceptions::PrivateKeyMissing, "I cannot read #{key_file}, which you told me to use to sign requests!"
63
+ end
64
+ assert_valid_key_format!(@raw_key)
65
+ @key = OpenSSL::PKey::RSA.new(@raw_key)
66
+ end
67
+
68
+ def assert_valid_key_format!(raw_key)
69
+ unless (raw_key =~ /\A-----BEGIN RSA PRIVATE KEY-----$/) && (raw_key =~ /^-----END RSA PRIVATE KEY-----\Z/)
70
+ msg = "The file #{key_file} does not contain a correctly formatted private key.\n"
71
+ msg << "The key file should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
72
+ raise Chef::Exceptions::InvalidPrivateKey, msg
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -1,19 +1,31 @@
1
1
  #
2
- # Author:: AJ Christensen (<aj@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Thom May (<thom@clearairturbulence.org>)
4
+ # Author:: Nuo Yan (<nuo@opscode.com>)
5
+ # Author:: Christopher Brown (<cb@opscode.com>)
6
+ # Author:: Christopher Walters (<cw@opscode.com>)
7
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
8
+ # Copyright:: Copyright (c) 2009, 2010 Opscode, Inc.
4
9
  # License:: Apache License, Version 2.0
5
10
  #
6
11
  # Licensed under the Apache License, Version 2.0 (the "License");
7
12
  # you may not use this file except in compliance with the License.
8
13
  # You may obtain a copy of the License at
9
- #
14
+ #
10
15
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
16
+ #
12
17
  # Unless required by applicable law or agreed to in writing, software
13
18
  # distributed under the License is distributed on an "AS IS" BASIS,
14
19
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
20
  # See the License for the specific language governing permissions and
16
21
  # limitations under the License.
22
+ #
23
+ require 'singleton'
17
24
 
18
- require 'chef/application'
19
-
25
+ class Chef
26
+ class REST
27
+ class CookieJar < Hash
28
+ include Singleton
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,151 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Thom May (<thom@clearairturbulence.org>)
4
+ # Author:: Nuo Yan (<nuo@opscode.com>)
5
+ # Author:: Christopher Brown (<cb@opscode.com>)
6
+ # Author:: Christopher Walters (<cw@opscode.com>)
7
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
8
+ # Copyright:: Copyright (c) 2009, 2010 Opscode, Inc.
9
+ # License:: Apache License, Version 2.0
10
+ #
11
+ # Licensed under the Apache License, Version 2.0 (the "License");
12
+ # you may not use this file except in compliance with the License.
13
+ # You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ #
23
+ require 'uri'
24
+ require 'net/http'
25
+ require 'chef/rest/cookie_jar'
26
+
27
+ class Chef
28
+ class REST
29
+ class RESTRequest
30
+ attr_reader :method, :url, :headers, :http_client, :http_request
31
+
32
+ def initialize(method, url, req_body, base_headers={})
33
+ @method, @url = method, url
34
+ @request_body = nil
35
+ @cookies = CookieJar.instance
36
+ configure_http_client
37
+ build_headers(base_headers)
38
+ configure_http_request(req_body)
39
+ end
40
+
41
+ def host
42
+ @url.host
43
+ end
44
+
45
+ def port
46
+ @url.port
47
+ end
48
+
49
+ def query
50
+ @url.query
51
+ end
52
+
53
+ def path
54
+ @url.path.empty? ? "/" : @url.path
55
+ end
56
+
57
+ def call
58
+ http_client.request(http_request) do |response|
59
+ store_cookie(response)
60
+ yield response if block_given?
61
+ response
62
+ end
63
+ end
64
+
65
+ def config
66
+ Chef::Config
67
+ end
68
+
69
+ private
70
+
71
+ def store_cookie(response)
72
+ if response['set-cookie']
73
+ @cookies["#{host}:#{port}"] = response['set-cookie']
74
+ end
75
+ end
76
+
77
+ def build_headers(headers)
78
+ @headers = headers.dup
79
+ # TODO: need to set accept somewhere else
80
+ # headers.merge!('Accept' => "application/json") unless raw
81
+ @headers['X-Chef-Version'] = ::Chef::VERSION
82
+
83
+ if @cookies.has_key?("#{host}:#{port}")
84
+ @headers['Cookie'] = @cookies["#{host}:#{port}"]
85
+ end
86
+ end
87
+
88
+ def configure_http_client
89
+ @http_client = Net::HTTP.new(host, port)
90
+ if url.scheme == "https"
91
+ @http_client.use_ssl = true
92
+ if config[:ssl_verify_mode] == :verify_none
93
+ @http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE
94
+ elsif config[:ssl_verify_mode] == :verify_peer
95
+ @http_client.verify_mode = OpenSSL::SSL::VERIFY_PEER
96
+ end
97
+ if config[:ssl_ca_path]
98
+ unless ::File.exist?(config[:ssl_ca_path])
99
+ raise Chef::Exceptions::ConfigurationError, "The configured ssl_ca_path #{config[:ssl_ca_path]} does not exist"
100
+ end
101
+ @http_client.ca_path = config[:ssl_ca_path]
102
+ elsif config[:ssl_ca_file]
103
+ unless ::File.exist?(config[:ssl_ca_file])
104
+ raise Chef::Exceptions::ConfigurationError, "The configured ssl_ca_file #{config[:ssl_ca_file]} does not exist"
105
+ end
106
+ @http_client.ca_file = config[:ssl_ca_file]
107
+ end
108
+ if (config[:ssl_client_cert] || config[:ssl_client_key])
109
+ unless (config[:ssl_client_cert] && config[:ssl_client_key])
110
+ raise Chef::Exceptions::ConfigurationError, "You must configure ssl_client_cert and ssl_client_key together"
111
+ end
112
+ unless ::File.exists?(config[:ssl_client_cert])
113
+ raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_cert #{config[:ssl_client_cert]} does not exist"
114
+ end
115
+ unless ::File.exists?(config[:ssl_client_key])
116
+ raise Chef::Exceptions::ConfigurationError, "The configured ssl_client_key #{config[:ssl_client_key]} does not exist"
117
+ end
118
+ @http_client.cert = OpenSSL::X509::Certificate.new(::File.read(config[:ssl_client_cert]))
119
+ @http_client.key = OpenSSL::PKey::RSA.new(::File.read(config[:ssl_client_key]))
120
+ end
121
+ end
122
+
123
+ @http_client.read_timeout = config[:rest_timeout]
124
+ end
125
+
126
+
127
+ def configure_http_request(request_body=nil)
128
+ req_path = "#{path}"
129
+ req_path << "?#{query}" if query
130
+
131
+ @http_request = case method.to_s.downcase
132
+ when "get"
133
+ Net::HTTP::Get.new(req_path, headers)
134
+ when "post"
135
+ Net::HTTP::Post.new(req_path, headers)
136
+ when "put"
137
+ Net::HTTP::Put.new(req_path, headers)
138
+ when "delete"
139
+ Net::HTTP::Delete.new(req_path, headers)
140
+ else
141
+ raise ArgumentError, "You must provide :GET, :PUT, :POST or :DELETE as the method"
142
+ end
143
+
144
+ @http_request.body = request_body if (request_body && @http_request.request_body_permitted?)
145
+ # Optionally handle HTTP Basic Authentication
146
+ @http_request.basic_auth(url.user, url.password) if url.user
147
+ end
148
+
149
+ end
150
+ end
151
+ 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.
@@ -28,19 +28,19 @@ require 'extlib'
28
28
  require 'json'
29
29
 
30
30
  class Chef
31
- class Role
32
-
31
+ class Role
32
+
33
33
  include Chef::Mixin::FromFile
34
34
  include Chef::Mixin::ParamsValidate
35
35
  include Chef::IndexQueue::Indexable
36
-
36
+
37
37
  DESIGN_DOCUMENT = {
38
38
  "version" => 6,
39
39
  "language" => "javascript",
40
40
  "views" => {
41
41
  "all" => {
42
42
  "map" => <<-EOJS
43
- function(doc) {
43
+ function(doc) {
44
44
  if (doc.chef_type == "role") {
45
45
  emit(doc.name, doc);
46
46
  }
@@ -49,7 +49,7 @@ class Chef
49
49
  },
50
50
  "all_id" => {
51
51
  "map" => <<-EOJS
52
- function(doc) {
52
+ function(doc) {
53
53
  if (doc.chef_type == "role") {
54
54
  emit(doc.name, doc.name);
55
55
  }
@@ -61,14 +61,14 @@ class Chef
61
61
 
62
62
  attr_accessor :couchdb_rev, :couchdb
63
63
  attr_reader :couchdb_id
64
-
64
+
65
65
  # Create a new Chef::Role object.
66
66
  def initialize(couchdb=nil)
67
- @name = ''
68
- @description = ''
67
+ @name = ''
68
+ @description = ''
69
69
  @default_attributes = Mash.new
70
70
  @override_attributes = Mash.new
71
- @run_list = Chef::RunList.new
71
+ @run_list = Chef::RunList.new
72
72
  @couchdb_rev = nil
73
73
  @couchdb_id = nil
74
74
  @couchdb = couchdb || Chef::CouchDB.new
@@ -87,7 +87,7 @@ class Chef
87
87
  Chef::REST.new(Chef::Config[:chef_server_url])
88
88
  end
89
89
 
90
- def name(arg=nil)
90
+ def name(arg=nil)
91
91
  set_or_return(
92
92
  :name,
93
93
  arg,
@@ -95,7 +95,7 @@ class Chef
95
95
  )
96
96
  end
97
97
 
98
- def description(arg=nil)
98
+ def description(arg=nil)
99
99
  set_or_return(
100
100
  :description,
101
101
  arg,
@@ -113,7 +113,7 @@ class Chef
113
113
  # Chef::Log.warn "Chef::Role#recipes method is deprecated. Please use Chef::Role#run_list"
114
114
  # run_list(*args)
115
115
  # end
116
-
116
+
117
117
  def default_attributes(arg=nil)
118
118
  set_or_return(
119
119
  :default_attributes,
@@ -144,11 +144,11 @@ class Chef
144
144
  result
145
145
  end
146
146
 
147
- # Serialize this object as a hash
147
+ # Serialize this object as a hash
148
148
  def to_json(*a)
149
149
  to_hash.to_json(*a)
150
150
  end
151
-
151
+
152
152
  # Create a Chef::Role from JSON
153
153
  def self.json_create(o)
154
154
  role = new
@@ -164,15 +164,15 @@ class Chef
164
164
  role.couchdb_rev = o["_rev"] if o.has_key?("_rev")
165
165
  role.index_id = role.couchdb_id
166
166
  role.couchdb_id = o["_id"] if o.has_key?("_id")
167
- role
167
+ role
168
168
  end
169
-
169
+
170
170
  # List all the Chef::Role objects in the CouchDB. If inflate is set to true, you will get
171
171
  # the full list of all Roles, fully inflated.
172
172
  def self.cdb_list(inflate=false, couchdb=nil)
173
173
  rs = (couchdb || Chef::CouchDB.new).list("roles", inflate)
174
174
  lookup = (inflate ? "value" : "key")
175
- rs["rows"].collect { |r| r[lookup] }
175
+ rs["rows"].collect { |r| r[lookup] }
176
176
  end
177
177
 
178
178
  # Get the list of all roles from the API.
@@ -187,12 +187,12 @@ class Chef
187
187
  chef_server_rest.get_rest("roles")
188
188
  end
189
189
  end
190
-
190
+
191
191
  # Load a role by name from CouchDB
192
192
  def self.cdb_load(name, couchdb=nil)
193
193
  (couchdb || Chef::CouchDB.new).load("role", name)
194
194
  end
195
-
195
+
196
196
  # Load a role by name from the API
197
197
  def self.load(name)
198
198
  chef_server_rest.get_rest("roles/#{name}")
@@ -205,44 +205,36 @@ class Chef
205
205
  nil
206
206
  end
207
207
  end
208
-
208
+
209
209
  # Remove this role from the CouchDB
210
210
  def cdb_destroy
211
211
  couchdb.delete("role", @name, couchdb_rev)
212
212
 
213
- if Chef::Config[:couchdb_version] == 0.9
214
- rs = couchdb.get_view("nodes", "by_run_list", :startkey => "role[#{@name}]", :endkey => "role[#{@name}]", :include_docs => true)
215
- rs["rows"].each do |row|
216
- node = row["doc"]
217
- node.run_list.remove("role[#{@name}]")
218
- node.cdb_save
219
- end
220
- else
221
- Chef::Node.cdb_list.each do |node|
222
- n = Chef::Node.cdb_load(node)
223
- n.run_list.remove("role[#{@name}]")
224
- n.cdb_save
225
- end
213
+ rs = couchdb.get_view("nodes", "by_run_list", :startkey => "role[#{@name}]", :endkey => "role[#{@name}]", :include_docs => true)
214
+ rs["rows"].each do |row|
215
+ node = row["doc"]
216
+ node.run_list.remove("role[#{@name}]")
217
+ node.cdb_save
226
218
  end
227
219
  end
228
-
220
+
229
221
  # Remove this role via the REST API
230
222
  def destroy
231
223
  chef_server_rest.delete_rest("roles/#{@name}")
232
-
224
+
233
225
  Chef::Node.list.each do |node|
234
226
  n = Chef::Node.load(node[0])
235
227
  n.run_list.remove("role[#{@name}]")
236
228
  n.save
237
229
  end
238
-
230
+
239
231
  end
240
-
232
+
241
233
  # Save this role to the CouchDB
242
234
  def cdb_save
243
235
  self.couchdb_rev = couchdb.store("role", @name, self)["rev"]
244
236
  end
245
-
237
+
246
238
  # Save this role via the REST API
247
239
  def save
248
240
  begin
@@ -253,18 +245,18 @@ class Chef
253
245
  end
254
246
  self
255
247
  end
256
-
248
+
257
249
  # Create the role via the REST API
258
250
  def create
259
251
  chef_server_rest.post_rest("roles", self)
260
252
  self
261
- end
262
-
253
+ end
254
+
263
255
  # Set up our CouchDB design document
264
256
  def self.create_design_document(couchdb=nil)
265
257
  (couchdb || Chef::CouchDB.new).create_design_document("roles", DESIGN_DOCUMENT)
266
258
  end
267
-
259
+
268
260
  # As a string
269
261
  def to_s
270
262
  "role[#{@name}]"
@@ -289,14 +281,14 @@ class Chef
289
281
  # Sync all the json roles with couchdb from disk
290
282
  def self.sync_from_disk_to_couchdb
291
283
  Dir[File.join(Chef::Config[:role_path], "*.json")].each do |role_file|
292
- short_name = File.basename(role_file, ".json")
284
+ short_name = File.basename(role_file, ".json")
293
285
  Chef::Log.warn("Loading #{short_name}")
294
286
  r = Chef::Role.from_disk(short_name, "json")
295
287
  begin
296
288
  couch_role = Chef::Role.cdb_load(short_name)
297
289
  r.couchdb_rev = couch_role.couchdb_rev
298
290
  Chef::Log.debug("Replacing role #{short_name} with data from #{role_file}")
299
- rescue Chef::Exceptions::CouchDBNotFound
291
+ rescue Chef::Exceptions::CouchDBNotFound
300
292
  Chef::Log.debug("Creating role #{short_name} with data from #{role_file}")
301
293
  end
302
294
  r.cdb_save