chef 0.10.2 → 0.10.4.rc.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 (73) hide show
  1. data/distro/common/html/chef-client.8.html +4 -4
  2. data/distro/common/html/knife-cookbook.1.html +5 -3
  3. data/distro/common/html/knife-node.1.html +4 -4
  4. data/distro/common/man/man1/knife-cookbook.1 +5 -1
  5. data/distro/common/man/man1/knife-node.1 +1 -1
  6. data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
  7. data/distro/common/markdown/man1/knife-cookbook.mkd +7 -0
  8. data/distro/common/markdown/man1/knife-node.mkd +4 -3
  9. data/distro/common/markdown/man1/knife-ssh.mkd +2 -0
  10. data/lib/chef/application.rb +1 -0
  11. data/lib/chef/cookbook_loader.rb +18 -0
  12. data/lib/chef/cookbook_uploader.rb +1 -1
  13. data/lib/chef/data_bag.rb +14 -2
  14. data/lib/chef/data_bag_item.rb +8 -2
  15. data/lib/chef/encrypted_data_bag_item.rb +19 -6
  16. data/lib/chef/environment.rb +12 -6
  17. data/lib/chef/exceptions.rb +1 -0
  18. data/lib/chef/knife.rb +0 -28
  19. data/lib/chef/knife/bootstrap.rb +7 -0
  20. data/lib/chef/knife/bootstrap/archlinux-gems.erb +14 -12
  21. data/lib/chef/knife/bootstrap/centos5-gems.erb +8 -5
  22. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -0
  23. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +16 -9
  24. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -3
  25. data/lib/chef/knife/client_bulk_delete.rb +28 -6
  26. data/lib/chef/knife/cookbook_site_install.rb +2 -2
  27. data/lib/chef/knife/cookbook_upload.rb +71 -0
  28. data/lib/chef/knife/core/bootstrap_context.rb +13 -3
  29. data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -3
  30. data/lib/chef/knife/core/node_presenter.rb +5 -2
  31. data/lib/chef/knife/help.rb +13 -12
  32. data/lib/chef/knife/help_topics.rb +4 -0
  33. data/lib/chef/knife/ssh.rb +25 -4
  34. data/lib/chef/mixin/create_path.rb +3 -2
  35. data/lib/chef/mixin/get_source_from_package.rb +42 -0
  36. data/lib/chef/mixin/language.rb +8 -11
  37. data/lib/chef/monkey_patches/numeric.rb +9 -1
  38. data/lib/chef/monkey_patches/string.rb +21 -0
  39. data/lib/chef/platform.rb +2 -1
  40. data/lib/chef/provider.rb +1 -1
  41. data/lib/chef/provider/git.rb +16 -3
  42. data/lib/chef/provider/group/suse.rb +53 -0
  43. data/lib/chef/provider/mount/mount.rb +28 -20
  44. data/lib/chef/provider/package/apt.rb +39 -24
  45. data/lib/chef/provider/package/dpkg.rb +5 -2
  46. data/lib/chef/provider/package/easy_install.rb +2 -2
  47. data/lib/chef/provider/package/freebsd.rb +5 -2
  48. data/lib/chef/provider/package/macports.rb +4 -4
  49. data/lib/chef/provider/package/rpm.rb +4 -1
  50. data/lib/chef/provider/package/rubygems.rb +3 -0
  51. data/lib/chef/provider/package/solaris.rb +3 -0
  52. data/lib/chef/provider/package/yum-dump.py +239 -81
  53. data/lib/chef/provider/package/yum.rb +977 -110
  54. data/lib/chef/provider/package/zypper.rb +20 -3
  55. data/lib/chef/provider/remote_directory.rb +0 -1
  56. data/lib/chef/provider/service/arch.rb +35 -28
  57. data/lib/chef/provider/service/systemd.rb +102 -0
  58. data/lib/chef/provider/service/upstart.rb +8 -2
  59. data/lib/chef/providers.rb +2 -0
  60. data/lib/chef/resource.rb +31 -2
  61. data/lib/chef/resource/git.rb +9 -0
  62. data/lib/chef/resource/mount.rb +1 -2
  63. data/lib/chef/resource/yum_package.rb +20 -0
  64. data/lib/chef/rest.rb +1 -1
  65. data/lib/chef/role.rb +1 -1
  66. data/lib/chef/run_context.rb +3 -3
  67. data/lib/chef/runner.rb +15 -2
  68. data/lib/chef/shell_out.rb +1 -1
  69. data/lib/chef/shell_out/windows.rb +2 -2
  70. data/lib/chef/solr_query.rb +1 -1
  71. data/lib/chef/tasks/chef_repo.rake +1 -1
  72. data/lib/chef/version.rb +1 -1
  73. metadata +425 -441
@@ -115,7 +115,7 @@ class Chef
115
115
  end
116
116
 
117
117
  def install_package(name, version)
118
- run_command(:command => "#{easy_install_binary_path} \"#{name}==#{version}\"")
118
+ run_command(:command => "#{easy_install_binary_path}#{expand_options(@new_resource.options)} \"#{name}==#{version}\"")
119
119
  end
120
120
 
121
121
  def upgrade_package(name, version)
@@ -123,7 +123,7 @@ class Chef
123
123
  end
124
124
 
125
125
  def remove_package(name, version)
126
- run_command(:command => "#{easy_install_binary_path} -m #{name}")
126
+ run_command(:command => "#{easy_install_binary_path }#{expand_options(@new_resource.options)} -m #{name}")
127
127
  end
128
128
 
129
129
  def purge_package(name, version)
@@ -20,6 +20,7 @@
20
20
  require 'chef/provider/package'
21
21
  require 'chef/mixin/shell_out'
22
22
  require 'chef/resource/package'
23
+ require 'chef/mixin/get_source_from_package'
23
24
 
24
25
  class Chef
25
26
  class Provider
@@ -27,6 +28,8 @@ class Chef
27
28
  class Freebsd < Chef::Provider::Package
28
29
  include Chef::Mixin::ShellOut
29
30
 
31
+ include Chef::Mixin::GetSourceFromPackage
32
+
30
33
  def initialize(*args)
31
34
  super
32
35
  @current_resource = Chef::Resource::Package.new(@new_resource.name)
@@ -57,7 +60,7 @@ class Chef
57
60
  end
58
61
 
59
62
  def ports_makefile_variable_value(variable)
60
- make_v = shell_out!("make -V #{variable}", :cwd => port_path, :env => nil, :returns => [0,1])
63
+ make_v = shell_out!("make -V #{variable} -f #{port_path}/Makefile", :env => nil, :returns => [0,1])
61
64
  make_v.stdout.strip.split($\).first # $\ is the line separator, i.e., newline
62
65
  end
63
66
 
@@ -94,7 +97,7 @@ class Chef
94
97
  unless @current_resource.version
95
98
  case @new_resource.source
96
99
  when /^ports$/
97
- shell_out!("make -DBATCH install", :cwd => port_path, :env => nil).status
100
+ shell_out!("make -DBATCH -f #{port_path}/Makefile install", :timeout => 1200, :env => nil).status
98
101
  when /^http/, /^ftp/
99
102
  shell_out!("pkg_add -r #{package_name}", :env => { "PACKAGESITE" => @new_resource.source, 'LC_ALL' => nil }).status
100
103
  Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
@@ -43,7 +43,7 @@ class Chef
43
43
 
44
44
  def install_package(name, version)
45
45
  unless @current_resource.version == version
46
- command = "port install #{name}"
46
+ command = "port#{expand_options(@new_resource.options)} install #{name}"
47
47
  command << " @#{version}" if version and !version.empty?
48
48
  run_command_with_systems_locale(
49
49
  :command => command
@@ -52,7 +52,7 @@ class Chef
52
52
  end
53
53
 
54
54
  def purge_package(name, version)
55
- command = "port uninstall #{name}"
55
+ command = "port#{expand_options(@new_resource.options)} uninstall #{name}"
56
56
  command << " @#{version}" if version and !version.empty?
57
57
  run_command_with_systems_locale(
58
58
  :command => command
@@ -60,7 +60,7 @@ class Chef
60
60
  end
61
61
 
62
62
  def remove_package(name, version)
63
- command = "port deactivate #{name}"
63
+ command = "port#{expand_options(@new_resource.options)} deactivate #{name}"
64
64
  command << " @#{version}" if version and !version.empty?
65
65
 
66
66
  run_command_with_systems_locale(
@@ -79,7 +79,7 @@ class Chef
79
79
  install_package(name, version)
80
80
  elsif current_version != version
81
81
  run_command_with_systems_locale(
82
- :command => "port upgrade #{name} @#{version}"
82
+ :command => "port#{expand_options(@new_resource.options)} upgrade #{name} @#{version}"
83
83
  )
84
84
  end
85
85
  end
@@ -18,12 +18,15 @@
18
18
  require 'chef/provider/package'
19
19
  require 'chef/mixin/command'
20
20
  require 'chef/resource/package'
21
+ require 'chef/mixin/get_source_from_package'
21
22
 
22
23
  class Chef
23
24
  class Provider
24
25
  class Package
25
26
  class Rpm < Chef::Provider::Package
26
-
27
+
28
+ include Chef::Mixin::GetSourceFromPackage
29
+
27
30
  def load_current_resource
28
31
  @current_resource = Chef::Resource::Package.new(@new_resource.name)
29
32
  @current_resource.package_name(@new_resource.package_name)
@@ -20,6 +20,7 @@
20
20
  require 'chef/provider/package'
21
21
  require 'chef/mixin/command'
22
22
  require 'chef/resource/package'
23
+ require 'chef/mixin/get_source_from_package'
23
24
 
24
25
  # Class methods on Gem are defined in rubygems
25
26
  require 'rubygems'
@@ -299,6 +300,8 @@ class Chef
299
300
  Chef::Log.logger
300
301
  end
301
302
 
303
+ include Chef::Mixin::GetSourceFromPackage
304
+
302
305
  def initialize(new_resource, run_context=nil)
303
306
  super
304
307
  if new_resource.gem_binary
@@ -18,12 +18,15 @@
18
18
  require 'chef/provider/package'
19
19
  require 'chef/mixin/command'
20
20
  require 'chef/resource/package'
21
+ require 'chef/mixin/get_source_from_package'
21
22
 
22
23
  class Chef
23
24
  class Provider
24
25
  class Package
25
26
  class Solaris < Chef::Provider::Package
26
27
 
28
+ include Chef::Mixin::GetSourceFromPackage
29
+
27
30
  # def initialize(*args)
28
31
  # super
29
32
  # @current_resource = Chef::Resource::Package.new(@new_resource.name)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Matthew Kent (<mkent@magoazul.com>)
3
- # Copyright:: Copyright (c) 2009 Matthew Kent
3
+ # Copyright:: Copyright (c) 2009, 2011 Matthew Kent
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,110 +19,268 @@
19
19
  # yum-dump.py
20
20
  # Inspired by yumhelper.py by David Lutterkort
21
21
  #
22
- # Produce a list of installed and available packages using yum and dump the
23
- # result to stdout.
22
+ # Produce a list of installed, available and re-installable packages using yum
23
+ # and dump the results to stdout.
24
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.
25
+ # yum-dump invokes yum similarly to the command line interface which makes it
26
+ # subject to most of the configuration paramaters in yum.conf. yum-dump will
27
+ # also load yum plugins in the same manor as yum - these can affect the output.
27
28
  #
28
29
  # Can be run as non root, but that won't update the cache.
30
+ #
31
+ # Intended to support yum 2.x and 3.x
29
32
 
30
33
  import os
31
34
  import sys
32
35
  import time
33
36
  import yum
37
+ import re
38
+ import errno
34
39
 
35
40
  from yum import Errors
41
+ from optparse import OptionParser
42
+ from distutils import version
36
43
 
37
- PIDFILE='/var/run/yum.pid'
44
+ YUM_PID_FILE='/var/run/yum.pid'
38
45
 
39
46
  # Seconds to wait for exclusive access to yum
40
- lock_timeout = 10
47
+ LOCK_TIMEOUT = 10
41
48
 
42
- failure = False
49
+ YUM_VER = version.StrictVersion(yum.__version__)
50
+ YUM_MAJOR = YUM_VER.version[0]
43
51
 
44
- # Can't do try: except: finally: in python 2.4 it seems, hence this fun.
45
- try:
46
- try:
47
- y = yum.YumBase()
52
+ if YUM_MAJOR > 3 or YUM_MAJOR < 2:
53
+ print >> sys.stderr, "yum-dump Error: Can't match supported yum version" \
54
+ " (%s)" % yum.__version__
55
+ sys.exit(1)
56
+
57
+ # Required for Provides output
58
+ if YUM_MAJOR == 2:
59
+ import rpm
60
+ import rpmUtils.miscutils
61
+
62
+ def setup(yb, options):
63
+ # Only want our output
64
+ #
65
+ if YUM_MAJOR == 3:
48
66
  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
- # Override any setting in yum.conf - we only care about the newest
65
- y.conf.showdupesfromrepos = False
66
-
67
- # Spin up to lock_timeout.
68
- countdown = lock_timeout
67
+ if YUM_VER >= version.StrictVersion("3.2.22"):
68
+ yb.preconf.errorlevel=0
69
+ yb.preconf.debuglevel=0
70
+
71
+ # initialize the config
72
+ yb.conf
73
+ else:
74
+ yb.doConfigSetup(errorlevel=0, debuglevel=0)
75
+ except yum.Errors.ConfigError, e:
76
+ # supresses an ignored exception at exit
77
+ yb.preconf = None
78
+ print >> sys.stderr, "yum-dump Config Error: %s" % e
79
+ return 1
80
+ except ValueError, e:
81
+ yb.preconf = None
82
+ print >> sys.stderr, "yum-dump Options Error: %s" % e
83
+ return 1
84
+ elif YUM_MAJOR == 2:
85
+ yb.doConfigSetup()
86
+
87
+ def __log(a,b): pass
88
+
89
+ yb.log = __log
90
+ yb.errorlog = __log
91
+
92
+ # Give Chef every possible package version, it can decide what to do with them
93
+ if YUM_MAJOR == 3:
94
+ yb.conf.showdupesfromrepos = True
95
+ elif YUM_MAJOR == 2:
96
+ yb.conf.setConfigOption('showdupesfromrepos', True)
97
+
98
+ # Optionally run only on cached repositories, but non root must use the cache
99
+ if os.geteuid() != 0:
100
+ if YUM_MAJOR == 3:
101
+ yb.conf.cache = True
102
+ elif YUM_MAJOR == 2:
103
+ yb.conf.setConfigOption('cache', True)
104
+ else:
105
+ if YUM_MAJOR == 3:
106
+ yb.conf.cache = options.cache
107
+ elif YUM_MAJOR == 2:
108
+ yb.conf.setConfigOption('cache', options.cache)
109
+
110
+ return 0
111
+
112
+ def dump_packages(yb, list, output_provides):
113
+ packages = {}
114
+
115
+ if YUM_MAJOR == 2:
116
+ yb.doTsSetup()
117
+ yb.doRepoSetup()
118
+ yb.doSackSetup()
119
+
120
+ db = yb.doPackageLists(list)
121
+
122
+ for pkg in db.installed:
123
+ pkg.type = 'i'
124
+ packages[str(pkg)] = pkg
125
+
126
+ if YUM_VER >= version.StrictVersion("3.2.21"):
127
+ for pkg in db.available:
128
+ pkg.type = 'a'
129
+ packages[str(pkg)] = pkg
130
+
131
+ # These are both installed and available
132
+ for pkg in db.reinstall_available:
133
+ pkg.type = 'r'
134
+ packages[str(pkg)] = pkg
135
+ else:
136
+ # Old style method - no reinstall list
137
+ for pkg in yb.pkgSack.returnPackages():
138
+
139
+ if str(pkg) in packages:
140
+ if packages[str(pkg)].type == "i":
141
+ packages[str(pkg)].type = 'r'
142
+ continue
143
+
144
+ pkg.type = 'a'
145
+ packages[str(pkg)] = pkg
146
+
147
+ unique_packages = packages.values()
148
+
149
+ unique_packages.sort(lambda x, y: cmp(x.name, y.name))
150
+
151
+ for pkg in unique_packages:
152
+ if output_provides == "all" or \
153
+ (output_provides == "installed" and (pkg.type == "i" or pkg.type == "r")):
154
+
155
+ # yum 2 doesn't have provides_print, implement it ourselves using methods
156
+ # based on requires gathering in packages.py
157
+ if YUM_MAJOR == 2:
158
+ provlist = []
159
+
160
+ # Installed and available are gathered in different ways
161
+ if pkg.type == 'i' or pkg.type == 'r':
162
+ names = pkg.hdr[rpm.RPMTAG_PROVIDENAME]
163
+ flags = pkg.hdr[rpm.RPMTAG_PROVIDEFLAGS]
164
+ ver = pkg.hdr[rpm.RPMTAG_PROVIDEVERSION]
165
+ if names is not None:
166
+ tmplst = zip(names, flags, ver)
167
+
168
+ for (n, f, v) in tmplst:
169
+ prov = rpmUtils.miscutils.formatRequire(n, v, f)
170
+ provlist.append(prov)
171
+ # This is slow :(
172
+ elif pkg.type == 'a':
173
+ for prcoTuple in pkg.returnPrco('provides'):
174
+ prcostr = pkg.prcoPrintable(prcoTuple)
175
+ provlist.append(prcostr)
176
+
177
+ provides = provlist
178
+ else:
179
+ provides = pkg.provides_print
180
+ else:
181
+ provides = "[]"
182
+
183
+ print '%s %s %s %s %s %s %s' % (
184
+ pkg.name,
185
+ pkg.epoch,
186
+ pkg.version,
187
+ pkg.release,
188
+ pkg.arch,
189
+ provides,
190
+ pkg.type )
191
+
192
+ return 0
193
+
194
+ def yum_dump(options):
195
+ lock_obtained = False
196
+
197
+ yb = yum.YumBase()
198
+
199
+ status = setup(yb, options)
200
+ if status != 0:
201
+ return status
202
+
203
+ if options.output_options:
204
+ print "[option installonlypkgs] %s" % " ".join(yb.conf.installonlypkgs)
205
+
206
+ # Non root can't handle locking on rhel/centos 4
207
+ if os.geteuid() != 0:
208
+ return dump_packages(yb, options.package_list, options.output_provides)
209
+
210
+ # Wrap the collection and output of packages in yum's global lock to prevent
211
+ # any inconsistencies.
212
+ try:
213
+ # Spin up to LOCK_TIMEOUT
214
+ countdown = LOCK_TIMEOUT
69
215
  while True:
70
216
  try:
71
- y.doLock(PIDFILE)
217
+ yb.doLock(YUM_PID_FILE)
218
+ lock_obtained = True
72
219
  except Errors.LockError, e:
73
220
  time.sleep(1)
74
- countdown -= 1
221
+ countdown -= 1
75
222
  if countdown == 0:
76
- print >> sys.stderr, "Error! Couldn't obtain an exclusive yum lock in %d seconds. Giving up." % lock_timeout
77
- failure = True
78
- sys.exit(1)
223
+ print >> sys.stderr, "yum-dump Locking Error! Couldn't obtain an " \
224
+ "exclusive yum lock in %d seconds. Giving up." % LOCK_TIMEOUT
225
+ return 200
79
226
  else:
80
227
  break
81
-
82
- y.doTsSetup()
83
- y.doRpmDBSetup()
84
-
228
+
229
+ return dump_packages(yb, options.package_list, options.output_provides)
230
+
231
+ # Ensure we clear the lock and cleanup any resources
232
+ finally:
85
233
  try:
86
- db = y.doPackageLists('all')
87
- except AttributeError:
88
- # some people claim that testing for yum.__version__ should be
89
- # enough to see if this is required, but I say they're liars.
90
- # the yum on 4.8 at least understands yum.__version__ but still
91
- # needs to get its repos and sacks set up manually.
92
- # Thus, we just try it, fail, and then try again. WCPGW?
93
- y.doRepoSetup()
94
- y.doSackSetup()
95
- db = y.doPackageLists('all')
96
-
97
- y.closeRpmDB()
98
-
99
- except Errors.YumBaseError, e:
100
- print >> sys.stderr, "Error! %s" % e
101
- failure = True
102
- sys.exit(1)
234
+ yb.closeRpmDB()
235
+ if lock_obtained == True:
236
+ yb.doUnlock(YUM_PID_FILE)
237
+ except Errors.LockError, e:
238
+ print >> sys.stderr, "yum-dump Unlock Error: %s" % e
239
+ return 200
240
+
241
+ def main():
242
+ usage = "Usage: %prog [options]\n" + \
243
+ "Output a list of installed, available and re-installable packages via yum"
244
+ parser = OptionParser(usage=usage)
245
+ parser.add_option("-C", "--cache",
246
+ action="store_true", dest="cache", default=False,
247
+ help="run entirely from cache, don't update cache")
248
+ parser.add_option("-o", "--options",
249
+ action="store_true", dest="output_options", default=False,
250
+ help="output select yum options useful to Chef")
251
+ parser.add_option("-p", "--installed-provides",
252
+ action="store_const", const="installed", dest="output_provides", default="none",
253
+ help="output Provides for installed packages, big/wide output")
254
+ parser.add_option("-P", "--all-provides",
255
+ action="store_const", const="all", dest="output_provides", default="none",
256
+ help="output Provides for all package, slow, big/wide output")
257
+ parser.add_option("-i", "--installed",
258
+ action="store_const", const="installed", dest="package_list", default="all",
259
+ help="output only installed packages")
260
+ parser.add_option("-a", "--available",
261
+ action="store_const", const="available", dest="package_list", default="all",
262
+ help="output only available and re-installable packages")
263
+
264
+ (options, args) = parser.parse_args()
103
265
 
104
- # Ensure we clear the lock.
105
- finally:
106
266
  try:
107
- y.doUnlock(PIDFILE)
108
- # Keep Unlock from raising a second exception as it does with a yum.conf
109
- # config error.
110
- except Errors.YumBaseError:
111
- if failure == False:
112
- print >> sys.stderr, "Error! %s" % e
267
+ return yum_dump(options)
268
+
269
+ except yum.Errors.RepoError, e:
270
+ print >> sys.stderr, "yum-dump Repository Error: %s" % e
271
+ return 1
272
+
273
+ except yum.Errors.YumBaseError, e:
274
+ print >> sys.stderr, "yum-dump General Error: %s" % e
275
+ return 1
276
+
277
+ try:
278
+ status = main()
279
+ # Suppress a nasty broken pipe error when output is piped to utilities like 'head'
280
+ except IOError, e:
281
+ if e.errno == errno.EPIPE:
113
282
  sys.exit(1)
114
-
115
- for pkg in db.installed:
116
- print '%s,installed,%s,%s,%s,%s' % ( pkg.name,
117
- pkg.epoch,
118
- pkg.version,
119
- pkg.release,
120
- pkg.arch )
121
- for pkg in db.available:
122
- print '%s,available,%s,%s,%s,%s' % ( pkg.name,
123
- pkg.epoch,
124
- pkg.version,
125
- pkg.release,
126
- pkg.arch )
127
-
128
- sys.exit(0)
283
+ else:
284
+ raise
285
+
286
+ sys.exit(status)