runa-chef 0.8.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,125 @@
1
+ #
2
+ # Author:: Matthew Kent (<mkent@magoazul.com>)
3
+ # Copyright:: Copyright (c) 2009 Matthew Kent
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
+ # yum-dump.py
20
+ # Inspired by yumhelper.py by David Lutterkort
21
+ #
22
+ # Produce a list of installed and available packages using yum and dump the
23
+ # result to stdout.
24
+ #
25
+ # This invokes yum just as the command line would which makes it subject to
26
+ # all the caching related configuration paramaters in yum.conf.
27
+ #
28
+ # Can be run as non root, but that won't update the cache.
29
+
30
+ import os
31
+ import sys
32
+ import time
33
+ import yum
34
+
35
+ from yum import Errors
36
+
37
+ PIDFILE='/var/run/yum.pid'
38
+
39
+ # Seconds to wait for exclusive access to yum
40
+ lock_timeout = 10
41
+
42
+ failure = False
43
+
44
+ # Can't do try: except: finally: in python 2.4 it seems, hence this fun.
45
+ try:
46
+ try:
47
+ y = yum.YumBase()
48
+ try:
49
+ # Only want our output
50
+ y.doConfigSetup(errorlevel=0,debuglevel=0)
51
+ except:
52
+ # but of course, yum on even moderately old
53
+ # redhat/centosen doesn't know how to do logging properly
54
+ # so we duck punch our way to victory
55
+ def __log(a,b): pass
56
+ y.doConfigSetup()
57
+ y.log = __log
58
+ y.errorlog = __log
59
+
60
+ # Yum assumes it can update the cache directory. Disable this for non root
61
+ # users.
62
+ y.conf.cache = os.geteuid() != 0
63
+
64
+ # Spin up to lock_timeout.
65
+ countdown = lock_timeout
66
+ while True:
67
+ try:
68
+ y.doLock(PIDFILE)
69
+ except Errors.LockError, e:
70
+ time.sleep(1)
71
+ countdown -= 1
72
+ if countdown == 0:
73
+ print >> sys.stderr, "Error! Couldn't obtain an exclusive yum lock in %d seconds. Giving up." % lock_timeout
74
+ failure = True
75
+ sys.exit(1)
76
+ else:
77
+ break
78
+
79
+ y.doTsSetup()
80
+ y.doRpmDBSetup()
81
+
82
+ try:
83
+ db = y.doPackageLists('all')
84
+ except AttributeError:
85
+ # some people claim that testing for yum.__version__ should be
86
+ # enough to see if this is required, but I say they're liars.
87
+ # the yum on 4.8 at least understands yum.__version__ but still
88
+ # needs to get its repos and sacks set up manually.
89
+ # Thus, we just try it, fail, and then try again. WCPGW?
90
+ y.doRepoSetup()
91
+ y.doSackSetup()
92
+ db = y.doPackageLists('all')
93
+
94
+ y.closeRpmDB()
95
+
96
+ except Errors.YumBaseError, e:
97
+ print >> sys.stderr, "Error! %s" % e
98
+ failure = True
99
+ sys.exit(1)
100
+
101
+ # Ensure we clear the lock.
102
+ finally:
103
+ try:
104
+ y.doUnlock(PIDFILE)
105
+ # Keep Unlock from raising a second exception as it does with a yum.conf
106
+ # config error.
107
+ except Errors.YumBaseError:
108
+ if failure == False:
109
+ print >> sys.stderr, "Error! %s" % e
110
+ sys.exit(1)
111
+
112
+ for pkg in db.installed:
113
+ print '%s,installed,%s,%s,%s,%s' % ( pkg.name,
114
+ pkg.epoch,
115
+ pkg.version,
116
+ pkg.release,
117
+ pkg.arch )
118
+ for pkg in db.available:
119
+ print '%s,available,%s,%s,%s,%s' % ( pkg.name,
120
+ pkg.epoch,
121
+ pkg.version,
122
+ pkg.release,
123
+ pkg.arch )
124
+
125
+ sys.exit(0)
@@ -0,0 +1,175 @@
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/provider/package'
20
+ require 'chef/mixin/command'
21
+ require 'chef/resource/package'
22
+ require 'singleton'
23
+
24
+ class Chef
25
+ class Provider
26
+ class Package
27
+ class Yum < Chef::Provider::Package
28
+
29
+ class YumCache
30
+ include Chef::Mixin::Command
31
+ include Singleton
32
+
33
+ def initialize
34
+ load_data
35
+ end
36
+
37
+ def stale?
38
+ interval = Chef::Config[:interval].to_f
39
+
40
+ # run once mode
41
+ if interval == 0
42
+ return false
43
+ elsif (Time.now - @updated_at) > interval
44
+ return true
45
+ end
46
+
47
+ false
48
+ end
49
+
50
+ def refresh
51
+ if @data.empty?
52
+ reload
53
+ elsif stale?
54
+ reload
55
+ end
56
+ end
57
+
58
+ def load_data
59
+ @data = Hash.new
60
+ error = String.new
61
+
62
+ helper = ::File.join(::File.dirname(__FILE__), 'yum-dump.py')
63
+ status = popen4("python #{helper}", :waitlast => true) do |pid, stdin, stdout, stderr|
64
+ stdout.each do |line|
65
+ line.chomp!
66
+ name, type, epoch, version, release, arch = line.split(',')
67
+ type_sym = type.to_sym
68
+ if !@data.has_key?(name)
69
+ @data[name] = Hash.new
70
+ end
71
+ @data[name][type_sym] = { :epoch => epoch, :version => version,
72
+ :release => release, :arch => arch }
73
+ end
74
+
75
+ error = stderr.readlines
76
+ end
77
+
78
+ unless status.exitstatus == 0
79
+ raise Chef::Exceptions::Package, "yum failed - #{status.inspect} - returns: #{error}"
80
+ end
81
+
82
+ @updated_at = Time.now
83
+ end
84
+ alias :reload :load_data
85
+
86
+ def version(package_name, type)
87
+ if (x = @data[package_name])
88
+ if (y = x[type])
89
+ return "#{y[:version]}-#{y[:release]}"
90
+ end
91
+ end
92
+
93
+ nil
94
+ end
95
+
96
+ def installed_version(package_name)
97
+ version(package_name, :installed)
98
+ end
99
+
100
+ def candidate_version(package_name)
101
+ version(package_name, :available)
102
+ end
103
+
104
+ def flush
105
+ @data.clear
106
+ end
107
+ end
108
+
109
+ def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
110
+ @yum = YumCache.instance
111
+ super(node, new_resource, collection, definitions, cookbook_loader)
112
+ end
113
+
114
+ def load_current_resource
115
+ @current_resource = Chef::Resource::Package.new(@new_resource.name)
116
+ @current_resource.package_name(@new_resource.package_name)
117
+
118
+ Chef::Log.debug("Checking yum info for #{@new_resource.package_name}")
119
+
120
+ @yum.refresh
121
+
122
+ installed_version = @yum.installed_version(@new_resource.package_name)
123
+ @candidate_version = @yum.candidate_version(@new_resource.package_name)
124
+
125
+ @current_resource.version(installed_version)
126
+ if candidate_version
127
+ @candidate_version = candidate_version
128
+ else
129
+ @candidate_version = installed_version
130
+ end
131
+
132
+ @current_resource
133
+ end
134
+
135
+ def install_package(name, version)
136
+ run_command_with_systems_locale(
137
+ :command => "yum -d0 -e0 -y install #{name}-#{version}"
138
+ )
139
+ @yum.flush
140
+ end
141
+
142
+ def upgrade_package(name, version)
143
+ # If we have a version, we can upgrade - otherwise, install
144
+ if @current_resource.version
145
+ run_command_with_systems_locale(
146
+ :command => "yum -d0 -e0 -y update #{name}-#{version}"
147
+ )
148
+ @yum.flush
149
+ else
150
+ install_package(name, version)
151
+ end
152
+ end
153
+
154
+ def remove_package(name, version)
155
+ if version
156
+ run_command_with_systems_locale(
157
+ :command => "yum -d0 -e0 -y remove #{name}-#{version}"
158
+ )
159
+ else
160
+ run_command_with_systems_locale(
161
+ :command => "yum -d0 -e0 -y remove #{name}"
162
+ )
163
+ end
164
+
165
+ @yum.flush
166
+ end
167
+
168
+ def purge_package(name, version)
169
+ remove_package(name, version)
170
+ end
171
+
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,132 @@
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/provider/package'
20
+ require 'chef/mixin/command'
21
+ require 'chef/resource/package'
22
+ require 'singleton'
23
+
24
+ class Chef
25
+ class Provider
26
+ class Package
27
+ class Zypper < Chef::Provider::Package
28
+
29
+
30
+ def load_current_resource
31
+ @current_resource = Chef::Resource::Package.new(@new_resource.name)
32
+ @current_resource.package_name(@new_resource.package_name)
33
+
34
+ is_installed=false
35
+ version=''
36
+ is_out_of_date=false
37
+ Chef::Log.debug("Checking zypper for #{@new_resource.package_name}")
38
+ status = popen4("zypper info #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
39
+ stdout.each do |line|
40
+ case line
41
+ when /^Version: (.+)$/
42
+ version = $1
43
+ Chef::Log.debug("zypper version=#{$1}")
44
+ when /^Installed: Yes$/
45
+ is_installed=true
46
+ Chef::Log.debug("zypper installed true")
47
+
48
+ when /^Installed: No$/
49
+ is_installed=false
50
+ Chef::Log.debug("zypper installed false")
51
+ when /^Status: out-of-date \(version (.+) installed\)$/
52
+ is_out_of_date=true
53
+ oud_version=$1
54
+ Chef::Log.debug("zypper out of date version=#{$1}")
55
+ end
56
+ end
57
+ end
58
+
59
+ if is_installed==false
60
+ @candidate_version=version
61
+ @current_resource.version(nil)
62
+ Chef::Log.debug("dentro installed false");
63
+ end
64
+
65
+ if is_installed==true
66
+ if is_out_of_date==true
67
+ @current_resource.version(oud_version)
68
+ @candidate_version=version
69
+ Chef::Log.debug("dentro installed outofdate");
70
+ else
71
+ @current_resource.version(version)
72
+ @candidate_version=version
73
+ Chef::Log.debug("dentro installed");
74
+ end
75
+ end
76
+
77
+
78
+ unless status.exitstatus == 0
79
+ raise Chef::Exceptions::Package, "zypper failed - #{status.inspect}!"
80
+ end
81
+
82
+
83
+ Chef::Log.debug("zypper current resource #{@current_resource}")
84
+ @current_resource
85
+ end
86
+
87
+ def install_package(name, version)
88
+ if version
89
+ run_command(
90
+ :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}"
91
+ )
92
+ else
93
+ run_command(
94
+ :command => "zypper -n --no-gpg-checks install -l #{name}"
95
+ )
96
+ end
97
+ end
98
+
99
+ def upgrade_package(name, version)
100
+ if version
101
+ run_command(
102
+ :command => "zypper -n --no-gpg-checks update -l #{name}=#{version}"
103
+ )
104
+ else
105
+ run_command(
106
+ :command => "zypper -n --no-gpg-checks update -l #{name}"
107
+ )
108
+ end
109
+ end
110
+
111
+ def remove_package(name, version)
112
+ if version
113
+ run_command(
114
+ :command => "zypper -n --no-gpg-checks remove #{name}=#{version}"
115
+ )
116
+ else
117
+ run_command(
118
+ :command => "zypper -n --no-gpg-checks remove #{name}"
119
+ )
120
+ end
121
+
122
+
123
+ end
124
+
125
+ def purge_package(name, version)
126
+ remove_package(name, version)
127
+ end
128
+
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,126 @@
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/provider/file'
20
+ require 'chef/provider/directory'
21
+ require 'chef/rest'
22
+ require 'chef/mixin/find_preferred_file'
23
+ require 'chef/resource/directory'
24
+ require 'chef/resource/remote_file'
25
+ require 'chef/platform'
26
+ require 'uri'
27
+ require 'tempfile'
28
+ require 'net/https'
29
+
30
+ class Chef
31
+ class Provider
32
+ class RemoteDirectory < Chef::Provider::Directory
33
+
34
+ include ::Chef::Mixin::FindPreferredFile
35
+
36
+ def action_create
37
+ super
38
+
39
+ @remote_file_list = Hash.new
40
+ do_recursive
41
+ end
42
+
43
+ protected
44
+
45
+ def do_recursive
46
+ if Chef::Config[:solo]
47
+ Chef::Log.debug("Doing a local recursive directory copy for #{@new_resource}")
48
+ files_to_transfer = files_for_directory(@new_resource.source)
49
+ else
50
+ Chef::Log.debug("Doing a remote recursive directory transfer for #{@new_resource}")
51
+ r = Chef::REST.new(Chef::Config[:remotefile_url])
52
+ files_to_transfer = r.get_rest(generate_url(@new_resource.source, "files", { :recursive => "true" }))
53
+ end
54
+
55
+ files_to_transfer.each do |remote_file_source|
56
+ fetch_remote_file(remote_file_source)
57
+ end
58
+ end
59
+
60
+ def fetch_remote_file(remote_file_source)
61
+ full_path = ::File.join(@new_resource.path, remote_file_source)
62
+ full_dir = ::File.dirname(full_path)
63
+
64
+ if !::File.directory?(full_dir)
65
+ create_directory(full_dir)
66
+ end
67
+
68
+ remote_file = Chef::Resource::RemoteFile.new(full_path, nil, @node)
69
+ remote_file.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
70
+ remote_file.source(::File.join(@new_resource.source, remote_file_source))
71
+ remote_file.mode(@new_resource.files_mode) if @new_resource.files_mode
72
+ remote_file.group(@new_resource.files_group) if @new_resource.files_group
73
+ remote_file.owner(@new_resource.files_owner) if @new_resource.files_owner
74
+ remote_file.backup(@new_resource.files_backup) if @new_resource.files_backup
75
+
76
+ rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
77
+ rf_provider.load_current_resource
78
+ rf_provider.action_create
79
+ @new_resource.updated = true if rf_provider.new_resource.updated
80
+ end
81
+
82
+ def create_directory(full_dir)
83
+ new_dir = Chef::Resource::Directory.new(full_dir, nil, @node)
84
+ new_dir.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
85
+ new_dir.mode(@new_resource.mode)
86
+ new_dir.group(@new_resource.group)
87
+ new_dir.owner(@new_resource.owner)
88
+ new_dir.recursive(true)
89
+
90
+ d_provider = Chef::Platform.provider_for_node(@node, new_dir)
91
+ d_provider.load_current_resource
92
+ d_provider.action_create
93
+ @new_resource.updated = true if d_provider.new_resource.updated
94
+ end
95
+
96
+ def action_create_if_missing
97
+ raise Chef::Exceptions::UnsupportedAction, "Remote Directories do not support create_if_missing."
98
+ end
99
+ # Pulled from chef-server-slice files controller
100
+
101
+ def files_for_directory(path)
102
+ directory = find_preferred_file(
103
+ @new_resource.cookbook_name,
104
+ :remote_file,
105
+ path,
106
+ @node[:fqdn],
107
+ @node[:platform],
108
+ @node[:platform_version]
109
+ )
110
+
111
+ unless (directory && ::File.directory?(directory))
112
+ raise NotFound, "Cannot find a suitable directory"
113
+ end
114
+
115
+ directory_listing = Array.new
116
+ Dir[::File.join(directory, '**', '*')].sort { |a,b| b <=> a }.each do |file|
117
+ next if ::File.directory?(file)
118
+ file =~ /^#{directory}\/(.+)$/
119
+ directory_listing << $1
120
+ end
121
+ directory_listing
122
+ end
123
+
124
+ end
125
+ end
126
+ end