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
@@ -38,7 +38,7 @@ class Chef
38
38
 
39
39
  Chef::Log.info("Saved data_bag_item[#{@name_args[1]}]")
40
40
 
41
- json_pretty_print(format_for_display(object)) if config[:print_after]
41
+ output(format_for_display(object)) if config[:print_after]
42
42
  end
43
43
  end
44
44
  end
@@ -30,8 +30,8 @@ class Chef
30
30
  :long => "--with-uri",
31
31
  :description => "Show corresponding URIs"
32
32
 
33
- def run
34
- json_pretty_print(format_list_for_display(Chef::DataBag.list))
33
+ def run
34
+ output(format_list_for_display(Chef::DataBag.list))
35
35
  end
36
36
  end
37
37
  end
@@ -32,7 +32,7 @@ class Chef
32
32
  else
33
33
  format_list_for_display(Chef::DataBag.load(@name_args[0]))
34
34
  end
35
- json_pretty_print(display)
35
+ output(display)
36
36
  end
37
37
  end
38
38
  end
@@ -38,7 +38,7 @@ class Chef
38
38
  "attributes" => { "run_list" => @name_args }
39
39
  }
40
40
  data = edit_data(data) if config[:edit]
41
- json_pretty_print(data)
41
+ output(data)
42
42
  end
43
43
  end
44
44
  end
@@ -32,7 +32,7 @@ class Chef
32
32
 
33
33
  def run
34
34
  nag
35
- json_pretty_print rest.post_rest("/search/reindex", {})
35
+ output rest.post_rest("/search/reindex", {})
36
36
  end
37
37
 
38
38
  def nag
@@ -48,4 +48,4 @@ class Chef
48
48
 
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -31,7 +31,7 @@ class Chef
31
31
 
32
32
  updated.save
33
33
 
34
- json_pretty_print(format_for_display(updated)) if config[:print_after]
34
+ output(format_for_display(updated)) if config[:print_after]
35
35
 
36
36
  Chef::Log.warn("Updated Node #{updated.name}!")
37
37
  end
@@ -31,8 +31,8 @@ class Chef
31
31
  :long => "--with-uri",
32
32
  :description => "Show corresponding URIs"
33
33
 
34
- def run
35
- json_pretty_print(format_list_for_display(Chef::Node.list))
34
+ def run
35
+ output(format_list_for_display(Chef::Node.list))
36
36
  end
37
37
  end
38
38
  end
@@ -41,7 +41,7 @@ class Chef
41
41
 
42
42
  config[:run_list] = true
43
43
 
44
- json_pretty_print(format_for_display(node))
44
+ output(format_for_display(node))
45
45
  end
46
46
 
47
47
  def add_to_run_list(node, new_value, after=nil)
@@ -36,7 +36,7 @@ class Chef
36
36
 
37
37
  config[:run_list] = true
38
38
 
39
- json_pretty_print(format_for_display(node))
39
+ output(format_for_display(node))
40
40
  end
41
41
 
42
42
  end
@@ -38,7 +38,7 @@ class Chef
38
38
 
39
39
  def run
40
40
  node = Chef::Node.load(@name_args[0])
41
- json_pretty_print(format_for_display(node))
41
+ output(format_for_display(node))
42
42
  end
43
43
  end
44
44
  end
@@ -0,0 +1,156 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@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/knife'
20
+ require 'json'
21
+
22
+ class Chef
23
+ class Knife
24
+ class RackspaceServerCreate < Knife
25
+
26
+ banner "Sub-Command: rackspace server create [RUN LIST...] (options)"
27
+
28
+ option :flavor,
29
+ :short => "-f FLAVOR",
30
+ :long => "--flavor FLAVOR",
31
+ :description => "The flavor of server",
32
+ :proc => Proc.new { |f| f.to_i },
33
+ :default => 1
34
+
35
+ option :image,
36
+ :short => "-i IMAGE",
37
+ :long => "--image IMAGE",
38
+ :description => "The image of the server",
39
+ :proc => Proc.new { |i| i.to_i },
40
+ :default => 14362
41
+
42
+ option :server_name,
43
+ :short => "-N NAME",
44
+ :long => "--server-name NAME",
45
+ :description => "The server name",
46
+ :default => "wtf"
47
+
48
+ option :api_key,
49
+ :short => "-K KEY",
50
+ :long => "--rackspace-api-key KEY",
51
+ :description => "Your rackspace API key",
52
+ :proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }
53
+
54
+ option :api_username,
55
+ :short => "-A USERNAME",
56
+ :long => "--rackspace-api-username USERNAME",
57
+ :description => "Your rackspace API username",
58
+ :proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }
59
+
60
+ def h
61
+ @highline ||= HighLine.new
62
+ end
63
+
64
+ def run
65
+ require 'fog'
66
+ require 'highline'
67
+ require 'net/ssh/multi'
68
+ require 'readline'
69
+
70
+ connection = Fog::Rackspace::Servers.new(
71
+ :rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
72
+ :rackspace_username => Chef::Config[:knife][:rackspace_api_username]
73
+ )
74
+
75
+ server = connection.servers.new
76
+
77
+ server.flavor_id = config[:flavor]
78
+ server.image_id = config[:image]
79
+ server.name = config[:server_name]
80
+ server.personality = [
81
+ {
82
+ 'path' => '/etc/install-chef',
83
+ 'contents' => <<-EOH
84
+ #!/bin/bash
85
+ # Customized rc.local for chef installation
86
+
87
+ if [ ! -f /usr/bin/chef-client ]; then
88
+ apt-get update
89
+ apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
90
+ cd /tmp
91
+ wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
92
+ tar xvf rubygems-1.3.6.tgz
93
+ cd rubygems-1.3.6
94
+ ruby setup.rb
95
+ cp /usr/bin/gem1.8 /usr/bin/gem
96
+ gem install chef ohai --no-rdoc --no-ri --verbose
97
+ fi
98
+
99
+ exit 0
100
+ EOH
101
+ },
102
+ {
103
+ 'path' => "/etc/chef/validation.pem",
104
+ 'contents' => IO.read(Chef::Config[:validation_key])
105
+ },
106
+ {
107
+ 'path' => "/etc/chef/client.rb",
108
+ 'contents' => <<-EOH
109
+ log_level :info
110
+ log_location STDOUT
111
+ chef_server_url "#{Chef::Config[:chef_server_url]}"
112
+ validation_client_name "#{Chef::Config[:validation_client_name]}"
113
+ EOH
114
+ },
115
+ {
116
+ 'path' => "/etc/chef/first-boot.json",
117
+ 'contents' => { "run_list" => @name_args }.to_json
118
+ },
119
+ ]
120
+
121
+ server.save
122
+
123
+ $stdout.sync = true
124
+
125
+ puts "#{h.color("Name", :cyan)}: #{server.name}"
126
+ puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
127
+ puts "#{h.color("Image", :cyan)}: #{server.image_id}"
128
+ puts "#{h.color("Public Address", :cyan)}: #{server.addresses["public"]}"
129
+ puts "#{h.color("Private Address", :cyan)}: #{server.addresses["private"]}"
130
+ puts "#{h.color("Password", :cyan)}: #{server.password}"
131
+
132
+ print "\n#{h.color("Requesting server", :magenta)}"
133
+ saved_password = server.password
134
+
135
+ # wait for it to be ready to do stuff
136
+ server.wait_for { print "."; ready? }
137
+
138
+ puts "\nServer ready, waiting 15 seconds to bootstrap."
139
+ sleep 15
140
+
141
+ puts "\nBootstrapping #{h.color(server.name, :bold)}..."
142
+
143
+ ssh = Chef::Knife::Ssh.new
144
+ ssh.name_args = [ server.addresses["public"][0], "/bin/bash /etc/install-chef && /usr/bin/chef-client -j /etc/chef/first-boot.json" ]
145
+ ssh.config[:ssh_user] = "root"
146
+ ssh.config[:manual] = true
147
+ ssh.config[:password] = saved_password
148
+ ssh.password = saved_password
149
+ ssh.run
150
+
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+
@@ -0,0 +1,57 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@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/knife'
20
+ require 'json'
21
+
22
+ class Chef
23
+ class Knife
24
+ class RackspaceServerDelete < Knife
25
+
26
+ banner "Sub-Command: rackspace server delete SERVER (options)"
27
+
28
+ def h
29
+ @highline ||= HighLine.new
30
+ end
31
+
32
+ def run
33
+ require 'fog'
34
+ require 'highline'
35
+ require 'net/ssh/multi'
36
+ require 'readline'
37
+
38
+ connection = Fog::Rackspace::Servers.new(
39
+ :rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
40
+ :rackspace_username => Chef::Config[:knife][:rackspace_api_username]
41
+ )
42
+
43
+ server = connection.servers.get(@name_args[0])
44
+
45
+ confirm("Do you really want to delete server ID #{server.id} named #{server.name}")
46
+
47
+ server.destroy
48
+
49
+ Chef::Log.warn("Deleted server #{server.id} named #{server.name}")
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+
56
+
57
+
@@ -0,0 +1,59 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@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/knife'
20
+ require 'json'
21
+
22
+ class Chef
23
+ class Knife
24
+ class RackspaceServerList < Knife
25
+
26
+ banner "Sub-Command: rackspace server list (options)"
27
+
28
+ def h
29
+ @highline ||= HighLine.new
30
+ end
31
+
32
+ def run
33
+ require 'fog'
34
+ require 'highline'
35
+ require 'net/ssh/multi'
36
+ require 'readline'
37
+
38
+ connection = Fog::Rackspace::Servers.new(
39
+ :rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
40
+ :rackspace_username => Chef::Config[:knife][:rackspace_api_username]
41
+ )
42
+
43
+ server_list = [ h.color('ID', :bold), h.color('Name', :bold), h.color('Public IP', :bold), h.color('Private IP', :bold), h.color('Flavor ID', :bold) ]
44
+ connection.servers.all.each do |server|
45
+ server_list << server.id.to_s
46
+ server_list << server.name
47
+ server_list << server.addresses["public"][0]
48
+ server_list << server.addresses["private"][0]
49
+ server_list << server.flavor_id.to_s
50
+ end
51
+ puts h.list(server_list, :columns_across, 5)
52
+
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+
@@ -31,7 +31,7 @@ class Chef
31
31
 
32
32
  updated.save
33
33
 
34
- json_pretty_print(format_for_display(updated)) if config[:print_after]
34
+ output(format_for_display(updated)) if config[:print_after]
35
35
 
36
36
  Chef::Log.warn("Updated Role #{updated.name}!")
37
37
  end
@@ -32,7 +32,7 @@ class Chef
32
32
  :description => "Show corresponding URIs"
33
33
 
34
34
  def run
35
- json_pretty_print(format_list_for_display(Chef::Role.list))
35
+ output(format_list_for_display(Chef::Role.list))
36
36
  end
37
37
  end
38
38
  end
@@ -33,7 +33,7 @@ class Chef
33
33
 
34
34
  def run
35
35
  role = Chef::Role.load(@name_args[0])
36
- json_pretty_print(format_for_display(role))
36
+ output(format_for_display(role))
37
37
  end
38
38
 
39
39
  end
@@ -82,7 +82,7 @@ class Chef
82
82
  puts display[:rows].join("\n")
83
83
  end
84
84
  else
85
- json_pretty_print(display)
85
+ output(display)
86
86
  end
87
87
  end
88
88
  end
@@ -23,6 +23,8 @@ class Chef
23
23
  class Knife
24
24
  class Ssh < Knife
25
25
 
26
+ attr_writer :password
27
+
26
28
  banner "Sub-Command: ssh QUERY COMMAND (options)"
27
29
 
28
30
  option :concurrency,
@@ -44,11 +46,20 @@ class Chef
44
46
  :description => "QUERY is a space separated list of servers",
45
47
  :default => false
46
48
 
49
+ option :ssh_user,
50
+ :short => "-x USERNAME",
51
+ :long => "--ssh-user USERNAME",
52
+ :description => "The ssh username"
53
+
54
+ option :ssh_password,
55
+ :short => "-P PASSWORD",
56
+ :long => "--ssh-password PASSWORD",
57
+ :description => "The ssh password"
58
+
47
59
  def session
48
60
  @session ||= Net::SSH::Multi.start(:concurrent_connections => config[:concurrency])
49
61
  end
50
62
 
51
-
52
63
  def h
53
64
  @highline ||= HighLine.new
54
65
  end
@@ -71,7 +82,12 @@ class Chef
71
82
  def session_from_list(list)
72
83
  list.each do |item|
73
84
  Chef::Log.debug("Adding #{item}")
74
- session.use item
85
+
86
+ if config[:password]
87
+ session.use config[:ssh_user] ? "#{config[:ssh_user]}@#{item}" : item, :password => config[:password]
88
+ else
89
+ session.use config[:ssh_user] ? "#{config[:ssh_user]}@#{item}" : item
90
+ end
75
91
  @longest = item.length if item.length > @longest
76
92
  end
77
93
  session
@@ -173,8 +189,9 @@ class Chef
173
189
  tf.puts("caption always '%w'")
174
190
  tf.puts("hardstatus alwayslastline 'knife ssh #{@name_args[0]}'")
175
191
  window = 0
176
- session.servers_for.collect { |s| s.host }.each do |server|
177
- tf.puts("screen -t \"#{server}\" #{window} ssh #{server}")
192
+ session.servers_for.each do |server|
193
+ tf.print("screen -t \"#{server.host}\" #{window} ssh ")
194
+ server.user ? tf.puts("#{server.user}@#{server.host}") : tf.puts(server.host)
178
195
  window += 1
179
196
  end
180
197
  tf.close