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
@@ -49,10 +49,10 @@ class Chef
49
49
 
50
50
  protected
51
51
 
52
- def recipe_eval(*args, &block)
52
+ def recipe_eval(&block)
53
53
  provider_collection, @collection = @collection, Chef::ResourceCollection.new
54
54
 
55
- instance_eval(*args, &block)
55
+ instance_eval(&block)
56
56
  Chef::Runner.new(@node, @collection).converge
57
57
 
58
58
  @collection = provider_collection
@@ -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.
@@ -35,19 +35,19 @@ class Chef
35
35
  attr_accessor :cron_exists, :cron_empty
36
36
 
37
37
  def load_current_resource
38
- crontab = String.new
38
+ crontab_lines = []
39
39
  @current_resource = Chef::Resource::Cron.new(@new_resource.name)
40
40
  @current_resource.user(@new_resource.user)
41
41
  status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
42
- stdout.each { |line| crontab << line }
42
+ stdout.each_line { |line| crontab_lines << line }
43
43
  end
44
44
  if status.exitstatus > 1
45
45
  raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
46
46
  elsif status.exitstatus == 0
47
47
  cron_found = false
48
- crontab.each do |line|
49
- case line
50
- when /^# Chef Name: #{@new_resource.name}/
48
+ crontab_lines.each do |line|
49
+ case line.chomp
50
+ when "# Chef Name: #{@new_resource.name}"
51
51
  Chef::Log.debug("Found cron '#{@new_resource.name}'")
52
52
  cron_found = true
53
53
  @cron_exists = true
@@ -66,11 +66,11 @@ class Chef
66
66
  next
67
67
  when CRON_PATTERN
68
68
  if cron_found
69
- @current_resource.minute($1)
70
- @current_resource.hour($2)
69
+ @current_resource.minute($1)
70
+ @current_resource.hour($2)
71
71
  @current_resource.day($3)
72
- @current_resource.month($4)
73
- @current_resource.weekday($5)
72
+ @current_resource.month($4)
73
+ @current_resource.weekday($5)
74
74
  @current_resource.command($6)
75
75
  cron_found=false
76
76
  end
@@ -84,7 +84,7 @@ class Chef
84
84
  Chef::Log.debug("Cron empty for '#{@new_resource.user}'")
85
85
  @cron_empty = true
86
86
  end
87
-
87
+
88
88
  @current_resource
89
89
  end
90
90
 
@@ -112,8 +112,8 @@ class Chef
112
112
  end
113
113
  status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
114
114
  stdout.each_line do |line|
115
- case line
116
- when /^# Chef Name: #{@new_resource.name}\n/
115
+ case line.chomp
116
+ when "# Chef Name: #{@new_resource.name}"
117
117
  cron_found = true
118
118
  next
119
119
  when CRON_PATTERN
@@ -125,12 +125,12 @@ class Chef
125
125
  else
126
126
  next if cron_found
127
127
  end
128
- crontab << line
128
+ crontab << line
129
129
  end
130
130
  end
131
131
 
132
132
  status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
133
- crontab.each { |line| stdin.puts "#{line}" }
133
+ crontab.each_line { |line| stdin.puts "#{line}" }
134
134
  end
135
135
  Chef::Log.info("Updated cron '#{@new_resource.name}'")
136
136
  @new_resource.updated = true
@@ -140,11 +140,11 @@ class Chef
140
140
  stdout.each { |line| crontab << line }
141
141
  end
142
142
  end
143
-
143
+
144
144
  crontab << newcron
145
145
 
146
146
  status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
147
- crontab.each { |line| stdin.puts "#{line}" }
147
+ crontab.each_line { |line| stdin.puts "#{line}" }
148
148
  end
149
149
  Chef::Log.info("Added cron '#{@new_resource.name}'")
150
150
  @new_resource.updated = true
@@ -157,8 +157,8 @@ class Chef
157
157
  cron_found = false
158
158
  status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
159
159
  stdout.each_line do |line|
160
- case line
161
- when /^# Chef Name: #{@new_resource.name}\n/
160
+ case line.chomp
161
+ when "# Chef Name: #{@new_resource.name}"
162
162
  cron_found = true
163
163
  next
164
164
  when CRON_PATTERN
@@ -169,12 +169,12 @@ class Chef
169
169
  else
170
170
  next if cron_found
171
171
  end
172
- crontab << line
172
+ crontab << line
173
173
  end
174
174
  end
175
175
 
176
176
  status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
177
- crontab.each { |line| stdin.puts "#{line}" }
177
+ crontab.each_line { |line| stdin.puts "#{line}" }
178
178
  end
179
179
  Chef::Log.debug("Deleted cron '#{@new_resource.name}'")
180
180
  @new_resource.updated = true
@@ -50,11 +50,15 @@ class Chef
50
50
  cache
51
51
  end
52
52
 
53
+ def sorted_releases_from_filesystem
54
+ Dir.glob(new_resource.deploy_to + "/releases/*").sort_by { |d| ::File.ctime(d) }
55
+ end
56
+
53
57
  def load_cache
54
58
  begin
55
59
  JSON.parse(Chef::FileCache.load("revision-deploys/#{new_resource.name}"))
56
60
  rescue Chef::Exceptions::FileNotFound
57
- save_cache([])
61
+ sorted_releases_from_filesystem
58
62
  end
59
63
  end
60
64
 
@@ -59,11 +59,11 @@ class Chef
59
59
  Chef::Log.debug("Running erl_call[#{@new_resource.name}]")
60
60
  Chef::Log.debug("erl_call[#{@new_resource.name}] command: #{command}")
61
61
  Chef::Log.debug("erl_call[#{@new_resource.name}] code: #{@new_resource.code}")
62
- @new_resource.code.each { |line| stdin.puts "#{line.chomp!}" }
62
+ @new_resource.code.each_line { |line| stdin.puts "#{line.chomp!}" }
63
63
  stdin.close
64
64
  Chef::Log.info("Ran erl_call[#{@new_resource.name}] successfully")
65
65
  Chef::Log.debug("erl_call[#{@new_resource.name}] output: ")
66
- stdout.each { |line| Chef::Log.debug("#{line}")}
66
+ stdout.each_line { |line| Chef::Log.debug("#{line}")}
67
67
  end
68
68
  end
69
69
 
@@ -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.
@@ -37,15 +37,16 @@ class Chef
37
37
  end
38
38
  big
39
39
  end
40
-
40
+
41
41
  def octal_mode(mode)
42
42
  ((mode.respond_to?(:oct) ? mode.oct : mode.to_i) & 007777)
43
43
  end
44
44
 
45
45
  private :negative_complement, :octal_mode
46
-
46
+
47
47
  def load_current_resource
48
48
  @current_resource = Chef::Resource::File.new(@new_resource.name)
49
+ @new_resource.path.gsub!(/\\/, "/") # for Windows
49
50
  @current_resource.path(@new_resource.path)
50
51
  if ::File.exist?(@current_resource.path) && ::File.readable?(@current_resource.path)
51
52
  cstats = ::File.stat(@current_resource.path)
@@ -56,22 +57,36 @@ class Chef
56
57
  end
57
58
  @current_resource
58
59
  end
59
-
60
+
61
+ # Compare the content of a file. Returns true if they are the same, false if they are not.
62
+ def compare_content
63
+ @current_resource.checksum == new_resource_content_checksum
64
+ end
65
+
66
+ # Set the content of the file, assuming it is not set correctly already.
67
+ def set_content
68
+ unless compare_content
69
+ Chef::Log.info("Setting content for #{@new_resource}")
70
+ ::File.open(@new_resource.path, "w") {|f| f.write @new_resource.content }
71
+ @new_resource.updated = true
72
+ end
73
+ end
74
+
60
75
  # Compare the ownership of a file. Returns true if they are the same, false if they are not.
61
76
  def compare_owner
62
77
  return false if @new_resource.owner.nil?
63
-
78
+
64
79
  @set_user_id = case @new_resource.owner
65
80
  when /^\d+$/, Integer
66
81
  @new_resource.owner.to_i
67
82
  else
68
- # This raises an ArgumentError if you can't find the user
83
+ # This raises an ArgumentError if you can't find the user
69
84
  Etc.getpwnam(@new_resource.owner).uid
70
85
  end
71
-
86
+
72
87
  @set_user_id == @current_resource.owner
73
88
  end
74
-
89
+
75
90
  # Set the ownership on the file, assuming it is not set correctly already.
76
91
  def set_owner
77
92
  unless compare_owner
@@ -81,21 +96,21 @@ class Chef
81
96
  @new_resource.updated = true
82
97
  end
83
98
  end
84
-
99
+
85
100
  # Compares the group of a file. Returns true if they are the same, false if they are not.
86
101
  def compare_group
87
102
  return false if @new_resource.group.nil?
88
-
103
+
89
104
  @set_group_id = case @new_resource.group
90
105
  when /^\d+$/, Integer
91
106
  @new_resource.group.to_i
92
107
  else
93
108
  Etc.getgrnam(@new_resource.group).gid
94
109
  end
95
-
110
+
96
111
  @set_group_id == @current_resource.group
97
112
  end
98
-
113
+
99
114
  def set_group
100
115
  unless compare_group
101
116
  Chef::Log.info("Setting group to #{@set_group_id} for #{@new_resource}")
@@ -104,7 +119,7 @@ class Chef
104
119
  @new_resource.updated = true
105
120
  end
106
121
  end
107
-
122
+
108
123
  def compare_mode
109
124
  case @new_resource.mode
110
125
  when /^\d+$/, Integer
@@ -113,7 +128,7 @@ class Chef
113
128
  false
114
129
  end
115
130
  end
116
-
131
+
117
132
  def set_mode
118
133
  unless compare_mode && @new_resource.mode != nil
119
134
  Chef::Log.info("Setting mode to #{sprintf("%o" % octal_mode(@new_resource.mode))} for #{@new_resource}")
@@ -122,22 +137,23 @@ class Chef
122
137
  @new_resource.updated = true
123
138
  end
124
139
  end
125
-
140
+
126
141
  def action_create
127
142
  unless ::File.exists?(@new_resource.path)
128
143
  Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
129
144
  ::File.open(@new_resource.path, "w+") { |f| }
130
145
  @new_resource.updated = true
131
146
  end
147
+ set_content unless @new_resource.content.nil?
132
148
  set_owner unless @new_resource.owner.nil?
133
149
  set_group unless @new_resource.group.nil?
134
150
  set_mode unless @new_resource.mode.nil?
135
151
  end
136
-
152
+
137
153
  def action_create_if_missing
138
154
  action_create
139
155
  end
140
-
156
+
141
157
  def action_delete
142
158
  if ::File.exists?(@new_resource.path)
143
159
  if ::File.writable?(@new_resource.path)
@@ -150,7 +166,7 @@ class Chef
150
166
  end
151
167
  end
152
168
  end
153
-
169
+
154
170
  def action_touch
155
171
  action_create
156
172
  time = Time.now
@@ -158,7 +174,7 @@ class Chef
158
174
  ::File.utime(time, time, @new_resource.path)
159
175
  @new_resource.updated = true
160
176
  end
161
-
177
+
162
178
  def backup(file=nil)
163
179
  file ||= @new_resource.path
164
180
  if @new_resource.backup != false && @new_resource.backup > 0 && ::File.exist?(file)
@@ -171,7 +187,7 @@ class Chef
171
187
  end
172
188
  Chef::Log.info("Backing up #{@new_resource} to #{prefix + backup_filename}")
173
189
  FileUtils.cp(file, prefix + backup_filename, :preserve => true)
174
-
190
+
175
191
  # Clean up after the number of backups
176
192
  slice_number = @new_resource.backup
177
193
  backup_files = Dir[prefix + "#{@new_resource.path}.chef-*"].sort { |a,b| b <=> a }
@@ -184,12 +200,17 @@ class Chef
184
200
  end
185
201
  end
186
202
  end
187
-
203
+
188
204
  def generate_url(url, type, args=nil)
189
205
  cookbook_name = (@new_resource.respond_to?(:cookbook) && @new_resource.cookbook) ? @new_resource.cookbook : @new_resource.cookbook_name
190
206
  generate_cookbook_url(url, cookbook_name, type, @node, args)
191
207
  end
192
-
208
+
209
+ private
210
+
211
+ def new_resource_content_checksum
212
+ @new_resource.content && Digest::SHA2.hexdigest(@new_resource.content)
213
+ end
193
214
  end
194
215
  end
195
216
  end
@@ -75,11 +75,13 @@ class Chef
75
75
  def set_members
76
76
  unless @new_resource.append
77
77
  Chef::Log.debug("#{@new_resource}: removing group members #{@current_resource.members.join(' ')}") unless @current_resource.members.empty?
78
- safe_dscl("create /Groups/#{@new_resource.group_name} GroupMembers") # clear guid list
79
- safe_dscl("create /Groups/#{@new_resource.group_name} GroupMembership") # clear user list
78
+ safe_dscl("create /Groups/#{@new_resource.group_name} GroupMembers ''") # clear guid list
79
+ safe_dscl("create /Groups/#{@new_resource.group_name} GroupMembership ''") # clear user list
80
+ end
81
+ unless @new_resource.members.empty?
82
+ Chef::Log.debug("#{@new_resource}: setting group members #{@new_resource.members.join(', ')}")
83
+ safe_dscl("append /Groups/#{@new_resource.group_name} GroupMembership #{@new_resource.members.join(' ')}")
80
84
  end
81
- Chef::Log.debug("#{@new_resource}: setting group members #{@new_resource.members.join(', ')}") unless @new_resource.members.empty?
82
- safe_dscl("append /Groups/#{@new_resource.group_name} GroupMembership #{@new_resource.members.join(' ')}")
83
85
  end
84
86
 
85
87
  def load_current_resource
@@ -26,10 +26,6 @@ class Chef
26
26
 
27
27
  include Chef::Mixin::Command
28
28
 
29
- def initialize(node, new_resource)
30
- super(node, new_resource)
31
- end
32
-
33
29
  def load_current_resource
34
30
  @current_resource = Chef::Resource::Mdadm.new(@new_resource.name)
35
31
  @current_resource.raid_device(@new_resource.raid_device)
@@ -64,12 +64,16 @@ class Chef
64
64
 
65
65
  # Check to see if there is a entry in /etc/fstab. Last entry for a volume wins.
66
66
  enabled = false
67
- ::File.read("/etc/fstab").each do |line|
67
+ ::File.foreach("/etc/fstab") do |line|
68
68
  case line
69
69
  when /^[#\s]/
70
70
  next
71
- when /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
71
+ when /^#{device_fstab_regex}\s+#{@new_resource.mount_point}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/
72
72
  enabled = true
73
+ @current_resource.fstype($1)
74
+ @current_resource.options($2)
75
+ @current_resource.dump($3.to_i)
76
+ @current_resource.pass($4.to_i)
73
77
  Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab")
74
78
  when /^[\/\w]+\s+#{@new_resource.mount_point}/
75
79
  enabled = false
@@ -119,13 +123,21 @@ class Chef
119
123
  end
120
124
 
121
125
  def enable_fs
122
- unless @current_resource.enabled
123
- ::File.open("/etc/fstab", "a") do |fstab|
124
- fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "defaults" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}")
125
- Chef::Log.info("Enabled #{@new_resource.mount_point}")
126
+ if @current_resource.enabled
127
+ if @current_resource.fstype == @new_resource.fstype and
128
+ @current_resource.options == @new_resource.options and
129
+ @current_resource.dump == @new_resource.dump and
130
+ @current_resource.pass == @new_resource.pass
131
+ Chef::Log.debug("#{@new_resource.mount_point} is already enabled.")
132
+ return
126
133
  end
127
- else
128
- Chef::Log.debug("#{@new_resource.mount_point} is already enabled.")
134
+ # The current options don't match what we have, so
135
+ # disable, then enable.
136
+ disable_fs
137
+ end
138
+ ::File.open("/etc/fstab", "a") do |fstab|
139
+ fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "defaults" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}")
140
+ Chef::Log.info("Enabled #{@new_resource.mount_point}")
129
141
  end
130
142
  end
131
143
 
@@ -120,7 +120,7 @@ class Chef
120
120
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :purge"
121
121
  end
122
122
 
123
- def preseed_package(name, version, preseed)
123
+ def preseed_package(name, version)
124
124
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
125
125
  end
126
126
 
@@ -7,9 +7,9 @@
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
9
9
  # You may obtain a copy of the License at
10
- #
10
+ #
11
11
  # http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
  # Unless required by applicable law or agreed to in writing, software
14
14
  # distributed under the License is distributed on an "AS IS" BASIS,
15
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,8 +24,13 @@ require 'chef/resource/package'
24
24
  class Chef
25
25
  class Provider
26
26
  class Package
27
- class Freebsd < Chef::Provider::Package
28
-
27
+ class Freebsd < Chef::Provider::Package
28
+
29
+ def initialize(*args)
30
+ super
31
+ @current_resource = Chef::Resource::Package.new(@new_resource.name)
32
+ end
33
+
29
34
  def current_installed_version
30
35
  command = "pkg_info -E \"#{package_name}*\""
31
36
  status = popen4(command) do |pid, stdin, stdout, stderr|
@@ -41,7 +46,7 @@ class Chef
41
46
  end
42
47
  nil
43
48
  end
44
-
49
+
45
50
  def port_path
46
51
  case @new_resource.package_name
47
52
  # When the package name starts with a '/' treat it as the full path to the ports directory
@@ -61,10 +66,10 @@ class Chef
61
66
  end
62
67
  end
63
68
  end
64
- raise Chef::Exception::Package, "Could not find port with the name #{@new_resource.package_name}"
65
- end
69
+ raise Chef::Exceptions::Package, "Could not find port with the name #{@new_resource.package_name}"
70
+ end
66
71
  end
67
-
72
+
68
73
  def ports_makefile_variable_value(variable)
69
74
  command = "cd #{port_path}; make -V #{variable}"
70
75
  status = popen4(command) do |pid, stdin, stdout, stderr|
@@ -75,34 +80,33 @@ class Chef
75
80
  end
76
81
  nil
77
82
  end
78
-
83
+
79
84
  def ports_candidate_version
80
85
  ports_makefile_variable_value("PORTVERSION")
81
86
  end
82
-
87
+
83
88
  def load_current_resource
84
- @current_resource = Chef::Resource::Package.new(@new_resource.name)
85
89
  @current_resource.package_name(@new_resource.package_name)
86
-
90
+
87
91
  @current_resource.version(current_installed_version)
88
92
  Chef::Log.debug("Current version is #{@current_resource.version}") if @current_resource.version
89
-
93
+
90
94
  @candidate_version = ports_candidate_version
91
95
  Chef::Log.debug("Ports candidate version is #{@candidate_version}") if @candidate_version
92
-
96
+
93
97
  @current_resource
94
98
  end
95
-
99
+
96
100
  def latest_link_name
97
101
  ports_makefile_variable_value("LATEST_LINK")
98
102
  end
99
-
103
+
100
104
  # The name of the package (without the version number) as understood by pkg_add and pkg_info
101
105
  def package_name
102
106
  if ports_makefile_variable_value("PKGNAME") =~ /^(.+)-[^-]+$/
103
107
  $1
104
108
  else
105
- raise Chef::Exception::Package, "Unexpected form for PKGNAME variable in #{port_path}/Makefile"
109
+ raise Chef::Exceptions::Package, "Unexpected form for PKGNAME variable in #{port_path}/Makefile"
106
110
  end
107
111
  end
108
112
 
@@ -134,7 +138,7 @@ class Chef
134
138
  end
135
139
  end
136
140
  end
137
-
141
+
138
142
  def remove_package(name, version)
139
143
  # a version is mandatory
140
144
  if version