runa-chef 0.8.0.1

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 (216) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +136 -0
  3. data/bin/chef-client +26 -0
  4. data/bin/chef-solo +26 -0
  5. data/bin/knife +27 -0
  6. data/bin/shef +45 -0
  7. data/distro/README +2 -0
  8. data/distro/common/man/man1/chef-indexer.1 +42 -0
  9. data/distro/common/man/man1/chef-server.1 +108 -0
  10. data/distro/common/man/man8/chef-client.8 +61 -0
  11. data/distro/common/man/man8/chef-solo.8 +58 -0
  12. data/distro/common/man/man8/knife.8 +359 -0
  13. data/distro/debian/etc/init.d/chef-client +175 -0
  14. data/distro/debian/etc/init.d/chef-indexer +175 -0
  15. data/distro/debian/etc/init.d/chef-server +120 -0
  16. data/distro/redhat/etc/init.d/chef-client +78 -0
  17. data/distro/redhat/etc/init.d/chef-indexer +76 -0
  18. data/distro/redhat/etc/init.d/chef-server +78 -0
  19. data/distro/redhat/etc/sysconfig/chef-client +10 -0
  20. data/distro/redhat/etc/sysconfig/chef-indexer +8 -0
  21. data/distro/redhat/etc/sysconfig/chef-server +10 -0
  22. data/distro/suse/etc/init.d/chef-client +121 -0
  23. data/lib/chef.rb +49 -0
  24. data/lib/chef/api_client.rb +269 -0
  25. data/lib/chef/application.rb +98 -0
  26. data/lib/chef/application/agent.rb +18 -0
  27. data/lib/chef/application/client.rb +214 -0
  28. data/lib/chef/application/knife.rb +138 -0
  29. data/lib/chef/application/server.rb +19 -0
  30. data/lib/chef/application/solo.rb +214 -0
  31. data/lib/chef/cache.rb +61 -0
  32. data/lib/chef/cache/checksum.rb +70 -0
  33. data/lib/chef/certificate.rb +154 -0
  34. data/lib/chef/client.rb +323 -0
  35. data/lib/chef/compile.rb +158 -0
  36. data/lib/chef/config.rb +195 -0
  37. data/lib/chef/cookbook.rb +198 -0
  38. data/lib/chef/cookbook/metadata.rb +487 -0
  39. data/lib/chef/cookbook/metadata/version.rb +87 -0
  40. data/lib/chef/cookbook_loader.rb +180 -0
  41. data/lib/chef/couchdb.rb +273 -0
  42. data/lib/chef/daemon.rb +170 -0
  43. data/lib/chef/data_bag.rb +216 -0
  44. data/lib/chef/data_bag_item.rb +227 -0
  45. data/lib/chef/exceptions.rb +39 -0
  46. data/lib/chef/file_cache.rb +205 -0
  47. data/lib/chef/knife.rb +300 -0
  48. data/lib/chef/knife/client_bulk_delete.rb +41 -0
  49. data/lib/chef/knife/client_create.rb +55 -0
  50. data/lib/chef/knife/client_delete.rb +37 -0
  51. data/lib/chef/knife/client_edit.rb +37 -0
  52. data/lib/chef/knife/client_list.rb +40 -0
  53. data/lib/chef/knife/client_reregister.rb +48 -0
  54. data/lib/chef/knife/client_show.rb +42 -0
  55. data/lib/chef/knife/configure.rb +84 -0
  56. data/lib/chef/knife/cookbook_bulk_delete.rb +47 -0
  57. data/lib/chef/knife/cookbook_delete.rb +41 -0
  58. data/lib/chef/knife/cookbook_download.rb +57 -0
  59. data/lib/chef/knife/cookbook_list.rb +41 -0
  60. data/lib/chef/knife/cookbook_metadata.rb +87 -0
  61. data/lib/chef/knife/cookbook_show.rb +75 -0
  62. data/lib/chef/knife/cookbook_upload.rb +173 -0
  63. data/lib/chef/knife/data_bag_create.rb +43 -0
  64. data/lib/chef/knife/data_bag_delete.rb +43 -0
  65. data/lib/chef/knife/data_bag_edit.rb +49 -0
  66. data/lib/chef/knife/data_bag_list.rb +42 -0
  67. data/lib/chef/knife/data_bag_show.rb +40 -0
  68. data/lib/chef/knife/ec2_instance_data.rb +46 -0
  69. data/lib/chef/knife/node_bulk_delete.rb +44 -0
  70. data/lib/chef/knife/node_create.rb +39 -0
  71. data/lib/chef/knife/node_delete.rb +36 -0
  72. data/lib/chef/knife/node_edit.rb +36 -0
  73. data/lib/chef/knife/node_from_file.rb +42 -0
  74. data/lib/chef/knife/node_list.rb +41 -0
  75. data/lib/chef/knife/node_run_list_add.rb +64 -0
  76. data/lib/chef/knife/node_run_list_remove.rb +45 -0
  77. data/lib/chef/knife/node_show.rb +46 -0
  78. data/lib/chef/knife/role_bulk_delete.rb +45 -0
  79. data/lib/chef/knife/role_create.rb +44 -0
  80. data/lib/chef/knife/role_delete.rb +36 -0
  81. data/lib/chef/knife/role_edit.rb +37 -0
  82. data/lib/chef/knife/role_from_file.rb +46 -0
  83. data/lib/chef/knife/role_list.rb +40 -0
  84. data/lib/chef/knife/role_show.rb +43 -0
  85. data/lib/chef/knife/search.rb +94 -0
  86. data/lib/chef/log.rb +39 -0
  87. data/lib/chef/mixin/check_helper.rb +31 -0
  88. data/lib/chef/mixin/checksum.rb +32 -0
  89. data/lib/chef/mixin/command.rb +390 -0
  90. data/lib/chef/mixin/convert_to_class_name.rb +57 -0
  91. data/lib/chef/mixin/create_path.rb +56 -0
  92. data/lib/chef/mixin/deep_merge.rb +33 -0
  93. data/lib/chef/mixin/find_preferred_file.rb +92 -0
  94. data/lib/chef/mixin/from_file.rb +50 -0
  95. data/lib/chef/mixin/generate_url.rb +58 -0
  96. data/lib/chef/mixin/language.rb +107 -0
  97. data/lib/chef/mixin/language_include_attribute.rb +56 -0
  98. data/lib/chef/mixin/language_include_recipe.rb +53 -0
  99. data/lib/chef/mixin/params_validate.rb +197 -0
  100. data/lib/chef/mixin/recipe_definition_dsl_core.rb +79 -0
  101. data/lib/chef/mixin/template.rb +94 -0
  102. data/lib/chef/nanite.rb +100 -0
  103. data/lib/chef/node.rb +463 -0
  104. data/lib/chef/node/attribute.rb +412 -0
  105. data/lib/chef/openid_registration.rb +181 -0
  106. data/lib/chef/platform.rb +268 -0
  107. data/lib/chef/provider.rb +101 -0
  108. data/lib/chef/provider/breakpoint.rb +36 -0
  109. data/lib/chef/provider/cron.rb +184 -0
  110. data/lib/chef/provider/deploy.rb +314 -0
  111. data/lib/chef/provider/deploy/revision.rb +70 -0
  112. data/lib/chef/provider/deploy/timestamped.rb +33 -0
  113. data/lib/chef/provider/directory.rb +72 -0
  114. data/lib/chef/provider/erl_call.rb +72 -0
  115. data/lib/chef/provider/execute.rb +58 -0
  116. data/lib/chef/provider/file.rb +195 -0
  117. data/lib/chef/provider/git.rb +203 -0
  118. data/lib/chef/provider/group.rb +120 -0
  119. data/lib/chef/provider/group/dscl.rb +128 -0
  120. data/lib/chef/provider/group/gpasswd.rb +50 -0
  121. data/lib/chef/provider/group/groupadd.rb +78 -0
  122. data/lib/chef/provider/group/pw.rb +88 -0
  123. data/lib/chef/provider/group/usermod.rb +57 -0
  124. data/lib/chef/provider/http_request.rb +106 -0
  125. data/lib/chef/provider/ifconfig.rb +131 -0
  126. data/lib/chef/provider/link.rb +157 -0
  127. data/lib/chef/provider/mdadm.rb +88 -0
  128. data/lib/chef/provider/mount.rb +117 -0
  129. data/lib/chef/provider/mount/mount.rb +208 -0
  130. data/lib/chef/provider/package.rb +160 -0
  131. data/lib/chef/provider/package/apt.rb +110 -0
  132. data/lib/chef/provider/package/dpkg.rb +109 -0
  133. data/lib/chef/provider/package/easy_install.rb +106 -0
  134. data/lib/chef/provider/package/freebsd.rb +153 -0
  135. data/lib/chef/provider/package/macports.rb +105 -0
  136. data/lib/chef/provider/package/portage.rb +124 -0
  137. data/lib/chef/provider/package/rpm.rb +99 -0
  138. data/lib/chef/provider/package/rubygems.rb +136 -0
  139. data/lib/chef/provider/package/yum-dump.py +125 -0
  140. data/lib/chef/provider/package/yum.rb +175 -0
  141. data/lib/chef/provider/package/zypper.rb +132 -0
  142. data/lib/chef/provider/remote_directory.rb +126 -0
  143. data/lib/chef/provider/remote_file.rb +141 -0
  144. data/lib/chef/provider/route.rb +118 -0
  145. data/lib/chef/provider/ruby_block.rb +33 -0
  146. data/lib/chef/provider/script.rb +42 -0
  147. data/lib/chef/provider/service.rb +135 -0
  148. data/lib/chef/provider/service/debian.rb +64 -0
  149. data/lib/chef/provider/service/freebsd.rb +156 -0
  150. data/lib/chef/provider/service/gentoo.rb +54 -0
  151. data/lib/chef/provider/service/init.rb +71 -0
  152. data/lib/chef/provider/service/redhat.rb +62 -0
  153. data/lib/chef/provider/service/simple.rb +114 -0
  154. data/lib/chef/provider/subversion.rb +156 -0
  155. data/lib/chef/provider/template.rb +175 -0
  156. data/lib/chef/provider/user.rb +170 -0
  157. data/lib/chef/provider/user/dscl.rb +280 -0
  158. data/lib/chef/provider/user/pw.rb +113 -0
  159. data/lib/chef/provider/user/useradd.rb +108 -0
  160. data/lib/chef/recipe.rb +105 -0
  161. data/lib/chef/resource.rb +380 -0
  162. data/lib/chef/resource/apt_package.rb +34 -0
  163. data/lib/chef/resource/bash.rb +33 -0
  164. data/lib/chef/resource/breakpoint.rb +35 -0
  165. data/lib/chef/resource/cron.rb +179 -0
  166. data/lib/chef/resource/csh.rb +33 -0
  167. data/lib/chef/resource/deploy.rb +359 -0
  168. data/lib/chef/resource/deploy_revision.rb +35 -0
  169. data/lib/chef/resource/directory.rb +76 -0
  170. data/lib/chef/resource/dpkg_package.rb +34 -0
  171. data/lib/chef/resource/easy_install_package.rb +41 -0
  172. data/lib/chef/resource/erl_call.rb +83 -0
  173. data/lib/chef/resource/execute.rb +127 -0
  174. data/lib/chef/resource/file.rb +84 -0
  175. data/lib/chef/resource/gem_package.rb +41 -0
  176. data/lib/chef/resource/git.rb +36 -0
  177. data/lib/chef/resource/group.rb +70 -0
  178. data/lib/chef/resource/http_request.rb +52 -0
  179. data/lib/chef/resource/ifconfig.rb +134 -0
  180. data/lib/chef/resource/link.rb +78 -0
  181. data/lib/chef/resource/macports_package.rb +29 -0
  182. data/lib/chef/resource/mdadm.rb +82 -0
  183. data/lib/chef/resource/mount.rb +135 -0
  184. data/lib/chef/resource/package.rb +80 -0
  185. data/lib/chef/resource/perl.rb +33 -0
  186. data/lib/chef/resource/portage_package.rb +33 -0
  187. data/lib/chef/resource/python.rb +33 -0
  188. data/lib/chef/resource/remote_directory.rb +91 -0
  189. data/lib/chef/resource/remote_file.rb +60 -0
  190. data/lib/chef/resource/route.rb +135 -0
  191. data/lib/chef/resource/ruby.rb +33 -0
  192. data/lib/chef/resource/ruby_block.rb +39 -0
  193. data/lib/chef/resource/scm.rb +137 -0
  194. data/lib/chef/resource/script.rb +51 -0
  195. data/lib/chef/resource/service.rb +134 -0
  196. data/lib/chef/resource/subversion.rb +34 -0
  197. data/lib/chef/resource/template.rb +60 -0
  198. data/lib/chef/resource/timestamped_deploy.rb +31 -0
  199. data/lib/chef/resource/user.rb +101 -0
  200. data/lib/chef/resource_collection.rb +212 -0
  201. data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
  202. data/lib/chef/resource_definition.rb +67 -0
  203. data/lib/chef/rest.rb +298 -0
  204. data/lib/chef/role.rb +301 -0
  205. data/lib/chef/run_list.rb +164 -0
  206. data/lib/chef/runner.rb +130 -0
  207. data/lib/chef/search/query.rb +71 -0
  208. data/lib/chef/shef.rb +220 -0
  209. data/lib/chef/shef/ext.rb +297 -0
  210. data/lib/chef/shef/shef_session.rb +175 -0
  211. data/lib/chef/streaming_cookbook_uploader.rb +185 -0
  212. data/lib/chef/tasks/chef_repo.rake +245 -0
  213. data/lib/chef/util/file_edit.rb +125 -0
  214. data/lib/chef/util/fileedit.rb +121 -0
  215. data/lib/chef/webui_user.rb +231 -0
  216. metadata +398 -0
@@ -0,0 +1,88 @@
1
+ #
2
+ # Author:: Joe Williams (<joe@joetify.com>)
3
+ # Copyright:: Copyright (c) 2009 Joe Williams
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
+
19
+ require 'chef/log'
20
+ require 'chef/mixin/command'
21
+ require 'chef/provider'
22
+
23
+ class Chef
24
+ class Provider
25
+ class Mdadm < Chef::Provider
26
+
27
+ include Chef::Mixin::Command
28
+
29
+ def initialize(node, new_resource)
30
+ super(node, new_resource)
31
+ end
32
+
33
+ def load_current_resource
34
+ @current_resource = Chef::Resource::Mdadm.new(@new_resource.name)
35
+ @current_resource.raid_device(@new_resource.raid_device)
36
+ Chef::Log.debug("Checking for software raid device #{@current_resource.raid_device}")
37
+
38
+ command = "mdadm --detail --scan"
39
+ exists = false
40
+ status = popen4(command) do |pid, stdin, stdout, stderr|
41
+ stdout.each do |line|
42
+ if line.include? @new_resource.raid_device
43
+ exists = true
44
+ end
45
+ end
46
+ end
47
+ @current_resource.exists(exists)
48
+ end
49
+
50
+ def action_create
51
+ unless @current_resource.exists
52
+ command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.collect{|x| x + " "}.to_s.chop}"
53
+ Chef::Log.debug("mdadm command: #{command}")
54
+ pid, stdin, stdout, stderr = popen4(command)
55
+ Chef::Log.info("Created mdadm raid device (#{@new_resource.raid_device})")
56
+ @new_resource.updated = true
57
+ else
58
+ Chef::Log.debug("mdadm raid device already exists (#{@new_resource.raid_device})")
59
+ end
60
+ end
61
+
62
+ def action_assemble
63
+ unless @current_resource.exists
64
+ command = "yes | mdadm --assemble #{@new_resource.raid_device} #{@new_resource.devices.collect{|x| x + " "}.to_s.chop}"
65
+ Chef::Log.debug("mdadm command: #{command}")
66
+ pid, stdin, stdout, stderr = popen4(command)
67
+ Chef::Log.info("Assembled mdadm raid device (#{@new_resource.raid_device})")
68
+ @new_resource.updated = true
69
+ else
70
+ Chef::Log.debug("mdadm raid device already exists (#{@new_resource.raid_device})")
71
+ end
72
+ end
73
+
74
+ def action_stop
75
+ if @current_resource.exists
76
+ command = "yes | mdadm --stop #{@new_resource.raid_device}"
77
+ Chef::Log.debug("mdadm command: #{command}")
78
+ pid, stdin, stdout, stderr = popen4(command)
79
+ Chef::Log.info("Stopped mdadm raid device (#{@new_resource.raid_device})")
80
+ @new_resource.updated = true
81
+ else
82
+ Chef::Log.debug("mdadm raid device doesn't exist (#{@new_resource.raid_device})")
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,117 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 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
+
19
+ require 'chef/log'
20
+ require 'chef/mixin/command'
21
+ require 'chef/provider'
22
+
23
+ class Chef
24
+ class Provider
25
+ class Mount < Chef::Provider
26
+
27
+ include Chef::Mixin::Command
28
+
29
+ def action_mount
30
+ unless @current_resource.mounted
31
+ Chef::Log.debug("#{@new_resource}: attempting to mount")
32
+ status = mount_fs()
33
+ if status
34
+ @new_resource.updated = true
35
+ Chef::Log.info("#{@new_resource}: mounted successfully")
36
+ end
37
+ else
38
+ Chef::Log.debug("#{@new_resource}: not mounting, already mounted")
39
+ end
40
+ end
41
+
42
+ def action_umount
43
+ if @current_resource.mounted
44
+ Chef::Log.debug("#{@new_resource}: attempting to unmount")
45
+ status = umount_fs()
46
+ if status
47
+ @new_resource.updated = true
48
+ Chef::Log.info("#{@new_resource}: unmounted successfully")
49
+ end
50
+ else
51
+ Chef::Log.debug("#{@new_resource}: not unmounting, already unmounted")
52
+ end
53
+ end
54
+
55
+ def action_remount
56
+ unless @new_resource.supports[:remount]
57
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
58
+ else
59
+ if @current_resource.mounted
60
+ Chef::Log.debug("#{@new_resource}: attempting to remount")
61
+ status = remount_fs()
62
+ if status
63
+ @new_resource.updated = true
64
+ Chef::Log.info("#{@new_resource}: remounted successfully")
65
+ end
66
+ else
67
+ Chef::Log.debug("#{@new_resource}: not mounted, not remounting")
68
+ end
69
+ end
70
+ end
71
+
72
+ def action_enable
73
+ unless @current_resource.enabled
74
+ status = enable_fs
75
+ if status
76
+ @new_resource.updated = true
77
+ Chef::Log.info("#{@new_resource}: enabled successfully")
78
+ else
79
+ Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
80
+ end
81
+ end
82
+ end
83
+
84
+ def action_disable
85
+ if @current_resource.enabled
86
+ status = disable_fs
87
+ if status
88
+ @new_resource.updated = true
89
+ Chef::Log.info("#{@new_resource}: disabled successfully")
90
+ else
91
+ Chef::Log.debug("#{@new_resource}: not disabling, already disabled")
92
+ end
93
+ end
94
+ end
95
+
96
+ def mount_fs
97
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :mount"
98
+ end
99
+
100
+ def umount_fs
101
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :umount"
102
+ end
103
+
104
+ def remount_fs
105
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
106
+ end
107
+
108
+ def enable_fs
109
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
110
+ end
111
+
112
+ def disable_fs
113
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,208 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 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
+
19
+ require 'chef/provider/mount'
20
+ require 'chef/log'
21
+ require 'chef/mixin/command'
22
+
23
+ class Chef
24
+ class Provider
25
+ class Mount
26
+ class Mount < Chef::Provider::Mount
27
+
28
+ include Chef::Mixin::Command
29
+
30
+ def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
31
+ super(node, new_resource, collection, definitions, cookbook_loader)
32
+ @real_device = nil
33
+ end
34
+ attr_accessor :real_device
35
+
36
+ def load_current_resource
37
+ @current_resource = Chef::Resource::Mount.new(@new_resource.name)
38
+ @current_resource.mount_point(@new_resource.mount_point)
39
+ @current_resource.device(@new_resource.device)
40
+ Chef::Log.debug("Checking for mount point #{@current_resource.mount_point}")
41
+
42
+ # only check for existence of non-remote devices
43
+ if(@new_resource.device !~ /:/ && @new_resource.device !~ /\/\// && !::File.exists?(@new_resource.device) )
44
+ raise Chef::Exceptions::Mount, "Device #{@new_resource.device} does not exist"
45
+ elsif( !::File.exists?(@new_resource.mount_point) )
46
+ raise Chef::Exceptions::Mount, "Mount point #{@new_resource.mount_point} does not exist"
47
+ end
48
+
49
+ # Check to see if the volume is mounted. Last volume entry wins.
50
+ mounted = false
51
+ popen4("mount") do |pid, stdin, stdout, stderr|
52
+ stdout.each do |line|
53
+ case line
54
+ when /^#{device_mount_regex}\s+on\s+#{@new_resource.mount_point}/
55
+ mounted = true
56
+ Chef::Log.debug("Special device #{device_logstring} mounted as #{@new_resource.mount_point}")
57
+ when /^([\/\w])+\son\s#{@new_resource.mount_point}\s+/
58
+ mounted = false
59
+ Chef::Log.debug("Special device #{$~[1]} mounted as #{@new_resource.mount_point}")
60
+ end
61
+ end
62
+ end
63
+ @current_resource.mounted(mounted)
64
+
65
+ # Check to see if there is a entry in /etc/fstab. Last entry for a volume wins.
66
+ enabled = false
67
+ ::File.read("/etc/fstab").each do |line|
68
+ case line
69
+ when /^[#\s]/
70
+ next
71
+ when /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
72
+ enabled = true
73
+ Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab")
74
+ when /^[\/\w]+\s+#{@new_resource.mount_point}/
75
+ enabled = false
76
+ Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab")
77
+ end
78
+ end
79
+ @current_resource.enabled(enabled)
80
+ end
81
+
82
+ def mount_fs
83
+ unless @current_resource.mounted
84
+ command = "mount -t #{@new_resource.fstype}"
85
+ command << " -o #{@new_resource.options.join(',')}" unless @new_resource.options.nil? || @new_resource.options.empty?
86
+ command << " #{device_real}"
87
+ command << " #{@new_resource.mount_point}"
88
+ run_command(:command => command)
89
+ Chef::Log.info("Mounted #{@new_resource.mount_point}")
90
+ else
91
+ Chef::Log.debug("#{@new_resource.mount_point} is already mounted.")
92
+ end
93
+ end
94
+
95
+ def umount_fs
96
+ if @current_resource.mounted
97
+ command = "umount #{@new_resource.mount_point}"
98
+ run_command(:command => command)
99
+ Chef::Log.info("Unmounted #{@new_resource.mount_point}")
100
+ else
101
+ Chef::Log.debug("#{@new_resource.mount_point} is not mounted.")
102
+ end
103
+ end
104
+
105
+ def remount_fs
106
+ if @current_resource.mounted and @new_resource.supports[:remount]
107
+ command = "mount -o remount #{@new_resource.mount_point}"
108
+ run_command(:command => command)
109
+
110
+ @new_resource.updated = true
111
+ Chef::Log.info("Remounted #{@new_resource.mount_point}")
112
+ elsif @current_resource.mounted
113
+ umount_fs
114
+ sleep 1
115
+ mount_fs
116
+ else
117
+ Chef::Log.debug("#{@new_resource.mount_point} is not mounted.")
118
+ end
119
+ end
120
+
121
+ 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
+ end
127
+ else
128
+ Chef::Log.debug("#{@new_resource.mount_point} is already enabled.")
129
+ end
130
+ end
131
+
132
+ def disable_fs
133
+ if @current_resource.enabled
134
+ contents = []
135
+
136
+ found = false
137
+ ::File.readlines("/etc/fstab").reverse_each do |line|
138
+ if !found && line =~ /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
139
+ found = true
140
+ Chef::Log.debug("Removing #{@new_resource.mount_point} from fstab")
141
+ next
142
+ else
143
+ contents << line
144
+ end
145
+ end
146
+
147
+ ::File.open("/etc/fstab", "w") do |fstab|
148
+ contents.reverse_each { |line| fstab.puts line}
149
+ end
150
+ else
151
+ Chef::Log.debug("#{@new_resource.mount_point} is not enabled")
152
+ end
153
+ end
154
+
155
+ private
156
+ def device_fstab
157
+ case @new_resource.device_type
158
+ when :device
159
+ @new_resource.device
160
+ when :label
161
+ "LABEL=#{@new_resource.device}"
162
+ when :uuid
163
+ "UUID=#{@new_resource.device}"
164
+ end
165
+ end
166
+
167
+ def device_real
168
+ if @real_device == nil
169
+ if @new_resource.device_type == :device
170
+ @real_device = @new_resource.device
171
+ else
172
+ status = popen4("/sbin/findfs #{device_fstab}") do |pid, stdin, stdout, stderr|
173
+ @real_device = stdout.first.chomp
174
+ end
175
+ unless status.exitstatus == 0
176
+ @real_device = "/dev/null"
177
+ end
178
+ end
179
+ end
180
+ @real_device
181
+ end
182
+
183
+ def device_logstring
184
+ case @new_resource.device_type
185
+ when :device
186
+ "#{device_real}"
187
+ when :label
188
+ "#{device_real} with label #{@new_resource.device}"
189
+ when :uuid
190
+ "#{device_real} with uuid #{@new_resource.device}"
191
+ end
192
+ end
193
+
194
+ def device_mount_regex
195
+ ::File.symlink?(device_real) ? "(?:#{device_real})|(?:#{::File.readlink(device_real)})" : device_real
196
+ end
197
+
198
+ def device_fstab_regex
199
+ if @new_resource.device_type == :device
200
+ device_mount_regex
201
+ else
202
+ device_fstab
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,160 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
19
+ require 'chef/mixin/command'
20
+ require 'chef/log'
21
+ require 'chef/file_cache'
22
+ require 'chef/resource/remote_file'
23
+ require 'chef/platform'
24
+
25
+ class Chef
26
+ class Provider
27
+ class Package < Chef::Provider
28
+
29
+ include Chef::Mixin::Command
30
+
31
+ attr_accessor :candidate_version
32
+
33
+ def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
34
+ super(node, new_resource, collection, definitions, cookbook_loader)
35
+ @candidate_version = nil
36
+ end
37
+
38
+ def action_install
39
+ # If we specified a version, and it's not the current version, move to the specified version
40
+ if @new_resource.version != nil && @new_resource.version != @current_resource.version
41
+ install_version = @new_resource.version
42
+ # If it's not installed at all, install it
43
+ elsif @current_resource.version == nil
44
+ install_version = candidate_version
45
+ else
46
+ return
47
+ end
48
+
49
+ unless install_version
50
+ raise(Chef::Exceptions::Package, "No version specified, and no candidate version available!")
51
+ end
52
+
53
+ Chef::Log.info("Installing #{@new_resource} version #{install_version}")
54
+
55
+ # We need to make sure we handle the preseed file
56
+ if @new_resource.response_file
57
+ preseed_package(@new_resource.package_name, install_version)
58
+ end
59
+
60
+ status = install_package(@new_resource.package_name, install_version)
61
+ if status
62
+ @new_resource.updated = true
63
+ end
64
+ end
65
+
66
+ def action_upgrade
67
+ if @current_resource.version != candidate_version
68
+ orig_version = @current_resource.version || "uninstalled"
69
+ Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
70
+ status = upgrade_package(@new_resource.package_name, candidate_version)
71
+ if status
72
+ @new_resource.updated = true
73
+ end
74
+ end
75
+ end
76
+
77
+ def action_remove
78
+ if should_remove_package(@current_resource.version, @new_resource.version)
79
+ Chef::Log.info("Removing #{@new_resource}")
80
+ remove_package(@current_resource.package_name, @new_resource.version)
81
+ @new_resource.updated = true
82
+ end
83
+ end
84
+
85
+ def should_remove_package(current_version, new_version)
86
+ to_remove_package = false
87
+ if current_version != nil
88
+ if new_version != nil
89
+ if new_version == current_version
90
+ to_remove_package = true
91
+ end
92
+ else
93
+ to_remove_package = true
94
+ end
95
+ end
96
+ to_remove_package
97
+ end
98
+
99
+ def action_purge
100
+ if should_remove_package(@current_resource.version, @new_resource.version)
101
+ Chef::Log.info("Purging #{@new_resource}")
102
+ purge_package(@current_resource.package_name, @new_resource.version)
103
+ @new_resource.updated = true
104
+ end
105
+ end
106
+
107
+ def install_package(name, version)
108
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :install"
109
+ end
110
+
111
+ def upgrade_package(name, version)
112
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :upgrade"
113
+ end
114
+
115
+ def remove_package(name, version)
116
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remove"
117
+ end
118
+
119
+ def purge_package(name, version)
120
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :purge"
121
+ end
122
+
123
+ def preseed_package(name, version, preseed)
124
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
125
+ end
126
+
127
+ def get_preseed_file(name, version)
128
+ full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}")
129
+ full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed"
130
+ cache_path = "preseed/#{@new_resource.cookbook_name}/#{name}-#{version}.seed"
131
+
132
+ Chef::Log.debug("Fetching preseed file to #{cache_path}")
133
+
134
+ remote_file = Chef::Resource::RemoteFile.new(
135
+ full_cache_file,
136
+ nil,
137
+ @node
138
+ )
139
+ remote_file.cookbook_name = @new_resource.cookbook_name
140
+ remote_file.source(@new_resource.response_file)
141
+ remote_file.backup(false)
142
+
143
+ rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
144
+ rf_provider.load_current_resource
145
+ rf_provider.action_create
146
+
147
+ if remote_file.updated
148
+ Chef::FileCache.load(cache_path, false)
149
+ else
150
+ false
151
+ end
152
+ end
153
+
154
+ def expand_options(options)
155
+ options ? " #{options}" : ""
156
+ end
157
+
158
+ end
159
+ end
160
+ end