chef 0.9.18 → 0.10.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/README.rdoc +0 -3
  2. data/distro/arch/etc/rc.d/chef-server +0 -4
  3. data/distro/arch/etc/rc.d/chef-server-webui +0 -4
  4. data/distro/arch/etc/rc.d/chef-solr +0 -4
  5. data/distro/arch/etc/rc.d/chef-solr-indexer +0 -4
  6. data/lib/chef.rb +3 -3
  7. data/lib/chef/api_client.rb +1 -1
  8. data/lib/chef/application.rb +11 -1
  9. data/lib/chef/application/client.rb +18 -22
  10. data/lib/chef/application/knife.rb +28 -29
  11. data/lib/chef/application/solo.rb +14 -12
  12. data/lib/chef/client.rb +112 -54
  13. data/lib/chef/config.rb +4 -0
  14. data/lib/chef/cookbook/chefignore.rb +66 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +6 -5
  16. data/lib/chef/cookbook/cookbook_version_loader.rb +151 -0
  17. data/lib/chef/cookbook/file_system_file_vendor.rb +10 -8
  18. data/lib/chef/cookbook/metadata.rb +200 -108
  19. data/lib/chef/cookbook_loader.rb +39 -163
  20. data/lib/chef/cookbook_uploader.rb +100 -78
  21. data/lib/chef/cookbook_version.rb +92 -47
  22. data/lib/chef/cookbook_version_selector.rb +163 -0
  23. data/lib/chef/couchdb.rb +9 -1
  24. data/lib/chef/data_bag.rb +1 -1
  25. data/lib/chef/data_bag_item.rb +1 -1
  26. data/lib/chef/encrypted_data_bag_item.rb +126 -0
  27. data/lib/chef/environment.rb +386 -0
  28. data/lib/chef/exceptions.rb +82 -1
  29. data/lib/chef/index_queue/amqp_client.rb +15 -12
  30. data/lib/chef/index_queue/indexable.rb +38 -4
  31. data/lib/chef/json_compat.rb +3 -3
  32. data/lib/chef/knife.rb +97 -202
  33. data/lib/chef/knife/bootstrap.rb +27 -61
  34. data/lib/chef/knife/bootstrap/archlinux-gems.erb +4 -2
  35. data/lib/chef/knife/bootstrap/centos5-gems.erb +6 -15
  36. data/lib/chef/knife/bootstrap/fedora13-gems.erb +3 -4
  37. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  38. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -5
  39. data/lib/chef/knife/client_bulk_delete.rb +6 -3
  40. data/lib/chef/knife/client_create.rb +13 -10
  41. data/lib/chef/knife/client_delete.rb +10 -7
  42. data/lib/chef/knife/client_edit.rb +9 -6
  43. data/lib/chef/knife/client_list.rb +8 -5
  44. data/lib/chef/knife/client_reregister.rb +9 -6
  45. data/lib/chef/knife/client_show.rb +9 -6
  46. data/lib/chef/knife/configure.rb +15 -19
  47. data/lib/chef/knife/configure_client.rb +4 -4
  48. data/lib/chef/knife/cookbook_bulk_delete.rb +11 -8
  49. data/lib/chef/knife/cookbook_create.rb +120 -55
  50. data/lib/chef/knife/cookbook_delete.rb +18 -12
  51. data/lib/chef/knife/cookbook_download.rb +10 -6
  52. data/lib/chef/knife/cookbook_list.rb +15 -6
  53. data/lib/chef/knife/cookbook_metadata.rb +41 -21
  54. data/lib/chef/knife/cookbook_metadata_from_file.rb +4 -0
  55. data/lib/chef/knife/cookbook_show.rb +16 -5
  56. data/lib/chef/knife/cookbook_site_download.rb +2 -2
  57. data/lib/chef/knife/cookbook_site_share.rb +18 -13
  58. data/lib/chef/knife/cookbook_site_unshare.rb +7 -4
  59. data/lib/chef/knife/cookbook_site_vendor.rb +21 -18
  60. data/lib/chef/knife/cookbook_test.rb +14 -14
  61. data/lib/chef/knife/cookbook_upload.rb +91 -40
  62. data/lib/chef/knife/data_bag_create.rb +41 -6
  63. data/lib/chef/knife/data_bag_delete.rb +5 -3
  64. data/lib/chef/knife/data_bag_edit.rb +55 -11
  65. data/lib/chef/knife/data_bag_from_file.rb +47 -7
  66. data/lib/chef/knife/data_bag_list.rb +4 -1
  67. data/lib/chef/knife/data_bag_show.rb +44 -4
  68. data/lib/chef/knife/environment_create.rb +53 -0
  69. data/lib/chef/knife/environment_delete.rb +45 -0
  70. data/lib/chef/knife/environment_edit.rb +45 -0
  71. data/lib/chef/knife/environment_from_file.rb +39 -0
  72. data/lib/chef/knife/environment_list.rb +42 -0
  73. data/lib/chef/knife/environment_show.rb +46 -0
  74. data/lib/chef/knife/exec.rb +1 -1
  75. data/lib/chef/knife/index_rebuild.rb +8 -9
  76. data/lib/chef/knife/node_bulk_delete.rb +9 -6
  77. data/lib/chef/knife/node_create.rb +9 -6
  78. data/lib/chef/knife/node_delete.rb +10 -7
  79. data/lib/chef/knife/node_edit.rb +129 -10
  80. data/lib/chef/knife/node_from_file.rb +10 -7
  81. data/lib/chef/knife/node_list.rb +11 -6
  82. data/lib/chef/knife/node_run_list_add.rb +10 -7
  83. data/lib/chef/knife/node_run_list_remove.rb +9 -6
  84. data/lib/chef/knife/node_show.rb +15 -7
  85. data/lib/chef/knife/recipe_list.rb +4 -3
  86. data/lib/chef/knife/role_bulk_delete.rb +9 -6
  87. data/lib/chef/knife/role_create.rb +9 -6
  88. data/lib/chef/knife/role_delete.rb +10 -7
  89. data/lib/chef/knife/role_edit.rb +11 -8
  90. data/lib/chef/knife/role_from_file.rb +10 -7
  91. data/lib/chef/knife/role_list.rb +8 -5
  92. data/lib/chef/knife/role_show.rb +11 -8
  93. data/lib/chef/knife/search.rb +33 -10
  94. data/lib/chef/knife/ssh.rb +33 -61
  95. data/lib/chef/knife/status.rb +7 -4
  96. data/lib/chef/knife/subcommand_loader.rb +101 -0
  97. data/lib/chef/knife/tag_create.rb +31 -0
  98. data/lib/chef/knife/tag_delete.rb +31 -0
  99. data/lib/chef/knife/tag_list.rb +29 -0
  100. data/lib/chef/knife/ui.rb +229 -0
  101. data/lib/chef/knife/windows_bootstrap.rb +8 -5
  102. data/lib/chef/log.rb +5 -59
  103. data/lib/chef/mash.rb +211 -0
  104. data/lib/chef/mixins.rb +1 -2
  105. data/lib/chef/nil_argument.rb +3 -0
  106. data/lib/chef/node.rb +96 -34
  107. data/lib/chef/platform.rb +27 -0
  108. data/lib/chef/provider/cookbook_file.rb +21 -20
  109. data/lib/chef/provider/deploy/revision.rb +3 -0
  110. data/lib/chef/provider/file.rb +20 -11
  111. data/lib/chef/provider/git.rb +26 -26
  112. data/lib/chef/provider/group/aix.rb +70 -0
  113. data/lib/chef/provider/group/groupadd.rb +7 -4
  114. data/lib/chef/provider/group/usermod.rb +1 -1
  115. data/lib/chef/provider/package.rb +28 -28
  116. data/lib/chef/provider/package/dpkg.rb +1 -1
  117. data/lib/chef/provider/package/portage.rb +50 -39
  118. data/lib/chef/provider/package/rubygems.rb +1 -1
  119. data/lib/chef/provider/package/zypper.rb +3 -20
  120. data/lib/chef/provider/remote_directory.rb +0 -2
  121. data/lib/chef/provider/remote_file.rb +2 -3
  122. data/lib/chef/provider/service/arch.rb +28 -35
  123. data/lib/chef/provider/service/simple.rb +1 -1
  124. data/lib/chef/provider/subversion.rb +22 -22
  125. data/lib/chef/providers.rb +1 -0
  126. data/lib/chef/recipe.rb +10 -12
  127. data/lib/chef/resource.rb +49 -42
  128. data/lib/chef/resource/gem_package.rb +7 -3
  129. data/lib/chef/resource/git.rb +5 -5
  130. data/lib/chef/resource/package.rb +7 -7
  131. data/lib/chef/resource/scm.rb +2 -1
  132. data/lib/chef/resource/solaris_package.rb +0 -1
  133. data/lib/chef/resource/yum_package.rb +0 -1
  134. data/lib/chef/rest.rb +7 -16
  135. data/lib/chef/rest/rest_request.rb +0 -16
  136. data/lib/chef/role.rb +67 -13
  137. data/lib/chef/run_context.rb +37 -21
  138. data/lib/chef/run_list.rb +30 -15
  139. data/lib/chef/run_list/run_list_expansion.rb +41 -20
  140. data/lib/chef/run_list/run_list_item.rb +20 -6
  141. data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
  142. data/lib/chef/runner.rb +7 -15
  143. data/lib/chef/search/query.rb +12 -7
  144. data/lib/chef/shef.rb +6 -7
  145. data/lib/chef/shef/shef_session.rb +40 -35
  146. data/lib/chef/shell_out.rb +22 -201
  147. data/lib/chef/shell_out/unix.rb +224 -0
  148. data/lib/chef/shell_out/windows.rb +95 -0
  149. data/lib/chef/solr_query.rb +187 -0
  150. data/lib/chef/solr_query/lucene.treetop +145 -0
  151. data/lib/chef/solr_query/lucene_nodes.rb +285 -0
  152. data/lib/chef/solr_query/query_transform.rb +65 -0
  153. data/lib/chef/solr_query/solr_http_request.rb +118 -0
  154. data/lib/chef/version.rb +4 -2
  155. data/lib/chef/version_class.rb +70 -0
  156. data/lib/chef/version_constraint.rb +116 -0
  157. metadata +68 -37
  158. data/lib/chef/cookbook/metadata/version.rb +0 -87
  159. data/lib/chef/knife/bluebox_images_list.rb +0 -54
  160. data/lib/chef/knife/bluebox_server_create.rb +0 -157
  161. data/lib/chef/knife/bluebox_server_delete.rb +0 -63
  162. data/lib/chef/knife/bluebox_server_list.rb +0 -59
  163. data/lib/chef/knife/ec2_instance_data.rb +0 -46
  164. data/lib/chef/knife/ec2_server_create.rb +0 -218
  165. data/lib/chef/knife/ec2_server_delete.rb +0 -87
  166. data/lib/chef/knife/ec2_server_list.rb +0 -89
  167. data/lib/chef/knife/rackspace_server_create.rb +0 -184
  168. data/lib/chef/knife/rackspace_server_delete.rb +0 -57
  169. data/lib/chef/knife/rackspace_server_list.rb +0 -59
  170. data/lib/chef/knife/slicehost_images_list.rb +0 -53
  171. data/lib/chef/knife/slicehost_server_create.rb +0 -103
  172. data/lib/chef/knife/slicehost_server_delete.rb +0 -61
  173. data/lib/chef/knife/slicehost_server_list.rb +0 -64
  174. data/lib/chef/knife/terremark_server_create.rb +0 -152
  175. data/lib/chef/knife/terremark_server_delete.rb +0 -87
  176. data/lib/chef/knife/terremark_server_list.rb +0 -77
  177. data/lib/chef/mixin/find_preferred_file.rb +0 -92
@@ -1,218 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2010 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 'socket'
20
- require 'chef/knife'
21
- require 'chef/json_compat'
22
-
23
- class Chef
24
- class Knife
25
- class Ec2ServerCreate < Knife
26
-
27
- banner "knife ec2 server create [RUN LIST...] (options)"
28
-
29
- attr_accessor :initial_sleep_delay
30
-
31
- option :flavor,
32
- :short => "-f FLAVOR",
33
- :long => "--flavor FLAVOR",
34
- :description => "The flavor of server (m1.small, m1.medium, etc)",
35
- :default => "m1.small"
36
-
37
- option :image,
38
- :short => "-i IMAGE",
39
- :long => "--image IMAGE",
40
- :description => "The AMI for the server"
41
-
42
- option :security_groups,
43
- :short => "-G X,Y,Z",
44
- :long => "--groups X,Y,Z",
45
- :description => "The security groups for this server",
46
- :default => ["default"],
47
- :proc => Proc.new { |groups| groups.split(',') }
48
-
49
- option :availability_zone,
50
- :short => "-Z ZONE",
51
- :long => "--availability-zone ZONE",
52
- :description => "The Availability Zone",
53
- :default => "us-east-1b",
54
- :proc => Proc.new { |key| Chef::Config[:knife][:availability_zone] = key }
55
-
56
- option :chef_node_name,
57
- :short => "-N NAME",
58
- :long => "--node-name NAME",
59
- :description => "The Chef node name for your new node"
60
-
61
- option :ssh_key_name,
62
- :short => "-S KEY",
63
- :long => "--ssh-key KEY",
64
- :description => "The AWS SSH key id",
65
- :proc => Proc.new { |key| Chef::Config[:knife][:aws_ssh_key_id] = key }
66
-
67
- option :ssh_user,
68
- :short => "-x USERNAME",
69
- :long => "--ssh-user USERNAME",
70
- :description => "The ssh username",
71
- :default => "root"
72
-
73
- option :ssh_password,
74
- :short => "-P PASSWORD",
75
- :long => "--ssh-password PASSWORD",
76
- :description => "The ssh password"
77
-
78
- option :identity_file,
79
- :short => "-I IDENTITY_FILE",
80
- :long => "--identity-file IDENTITY_FILE",
81
- :description => "The SSH identity file used for authentication"
82
-
83
- option :aws_access_key_id,
84
- :short => "-A ID",
85
- :long => "--aws-access-key-id KEY",
86
- :description => "Your AWS Access Key ID",
87
- :proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key }
88
-
89
- option :aws_secret_access_key,
90
- :short => "-K SECRET",
91
- :long => "--aws-secret-access-key SECRET",
92
- :description => "Your AWS API Secret Access Key",
93
- :proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key }
94
-
95
- option :prerelease,
96
- :long => "--prerelease",
97
- :description => "Install the pre-release chef gems"
98
-
99
- option :region,
100
- :long => "--region REGION",
101
- :description => "Your AWS region",
102
- :default => "us-east-1",
103
- :proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
104
-
105
- option :distro,
106
- :short => "-d DISTRO",
107
- :long => "--distro DISTRO",
108
- :description => "Bootstrap a distro using a template",
109
- :default => "ubuntu10.04-gems"
110
-
111
- option :template_file,
112
- :long => "--template-file TEMPLATE",
113
- :description => "Full path to location of template to use",
114
- :default => false
115
-
116
- def h
117
- @highline ||= HighLine.new
118
- end
119
-
120
- def tcp_test_ssh(hostname)
121
- tcp_socket = TCPSocket.new(hostname, 22)
122
- readable = IO.select([tcp_socket], nil, nil, 5)
123
- if readable
124
- Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
125
- yield
126
- true
127
- else
128
- false
129
- end
130
- rescue Errno::ETIMEDOUT
131
- false
132
- rescue Errno::ECONNREFUSED
133
- sleep 2
134
- false
135
- ensure
136
- tcp_socket && tcp_socket.close
137
- end
138
-
139
- def run
140
- require 'fog'
141
- require 'highline'
142
- require 'net/ssh/multi'
143
- require 'readline'
144
-
145
- $stdout.sync = true
146
-
147
- connection = Fog::AWS::Compute.new(
148
- :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
149
- :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key],
150
- :region => Chef::Config[:knife][:region]
151
- )
152
-
153
- server = connection.servers.create(
154
- :image_id => config[:image],
155
- :groups => config[:security_groups],
156
- :flavor_id => config[:flavor],
157
- :key_name => Chef::Config[:knife][:aws_ssh_key_id],
158
- :availability_zone => Chef::Config[:knife][:availability_zone]
159
- )
160
-
161
- puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
162
- puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
163
- puts "#{h.color("Image", :cyan)}: #{server.image_id}"
164
- puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
165
- puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
166
- puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
167
-
168
- print "\n#{h.color("Waiting for server", :magenta)}"
169
-
170
- # wait for it to be ready to do stuff
171
- server.wait_for { print "."; ready? }
172
-
173
- puts("\n")
174
-
175
-
176
- puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
177
- puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
178
- puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
179
- puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
180
-
181
- print "\n#{h.color("Waiting for sshd", :magenta)}"
182
-
183
- print(".") until tcp_test_ssh(server.dns_name) { sleep @initial_sleep_delay ||= 10; puts("done") }
184
-
185
-
186
- bootstrap_for_node(server).run
187
-
188
- puts "\n"
189
- puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
190
- puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
191
- puts "#{h.color("Image", :cyan)}: #{server.image_id}"
192
- puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
193
- puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
194
- puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
195
- puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
196
- puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
197
- puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
198
- puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
199
- puts "#{h.color("Run List", :cyan)}: #{@name_args.join(', ')}"
200
- end
201
-
202
- def bootstrap_for_node(server)
203
- bootstrap = Chef::Knife::Bootstrap.new
204
- bootstrap.name_args = [server.dns_name]
205
- bootstrap.config[:run_list] = @name_args
206
- bootstrap.config[:ssh_user] = config[:ssh_user]
207
- bootstrap.config[:identity_file] = config[:identity_file]
208
- bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
209
- bootstrap.config[:prerelease] = config[:prerelease]
210
- bootstrap.config[:distro] = config[:distro]
211
- bootstrap.config[:use_sudo] = true
212
- bootstrap.config[:template_file] = config[:template_file]
213
- bootstrap
214
- end
215
-
216
- end
217
- end
218
- end
@@ -1,87 +0,0 @@
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 'chef/json_compat'
21
-
22
- class Chef
23
- class Knife
24
- class Ec2ServerDelete < Knife
25
-
26
- banner "knife ec2 server delete SERVER [SERVER] (options)"
27
-
28
- option :aws_access_key_id,
29
- :short => "-A ID",
30
- :long => "--aws-access-key-id KEY",
31
- :description => "Your AWS Access Key ID",
32
- :proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key }
33
-
34
- option :aws_secret_access_key,
35
- :short => "-K SECRET",
36
- :long => "--aws-secret-access-key SECRET",
37
- :description => "Your AWS API Secret Access Key",
38
- :proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key }
39
-
40
- option :region,
41
- :long => "--region REGION",
42
- :description => "Your AWS region",
43
- :default => "us-east-1",
44
- :proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
45
-
46
- def h
47
- @highline ||= HighLine.new
48
- end
49
-
50
- def run
51
- require 'fog'
52
- require 'highline'
53
- require 'net/ssh/multi'
54
- require 'readline'
55
-
56
- connection = Fog::AWS::Compute.new(
57
- :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
58
- :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key],
59
- :region => Chef::Config[:knife][:region]
60
- )
61
-
62
- @name_args.each do |instance_id|
63
- server = connection.servers.get(instance_id)
64
-
65
- puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
66
- puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
67
- puts "#{h.color("Image", :cyan)}: #{server.image_id}"
68
- puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
69
- puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
70
- puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
71
- puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
72
- puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
73
- puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
74
- puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
75
-
76
- puts "\n"
77
- confirm("Do you really want to delete this server")
78
-
79
- server.destroy
80
-
81
- Chef::Log.warn("Deleted server #{server.id}")
82
- end
83
- end
84
- end
85
- end
86
- end
87
-
@@ -1,89 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2010 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 'chef/json_compat'
21
-
22
- class Chef
23
- class Knife
24
- class Ec2ServerList < Knife
25
-
26
- banner "knife ec2 server list [RUN LIST...] (options)"
27
-
28
- option :aws_access_key_id,
29
- :short => "-A ID",
30
- :long => "--aws-access-key-id KEY",
31
- :description => "Your AWS Access Key ID",
32
- :proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key }
33
-
34
- option :aws_secret_access_key,
35
- :short => "-K SECRET",
36
- :long => "--aws-secret-access-key SECRET",
37
- :description => "Your AWS API Secret Access Key",
38
- :proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key }
39
-
40
- option :region,
41
- :long => "--region REGION",
42
- :description => "Your AWS region",
43
- :default => "us-east-1",
44
- :proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
45
-
46
- def h
47
- @highline ||= HighLine.new
48
- end
49
-
50
- def run
51
- require 'fog'
52
- require 'highline'
53
- require 'net/ssh/multi'
54
- require 'readline'
55
-
56
- $stdout.sync = true
57
-
58
- connection = Fog::AWS::Compute.new(
59
- :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
60
- :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key],
61
- :region => Chef::Config[:knife][:region]
62
- )
63
-
64
- server_list = [
65
- h.color('Instance ID', :bold),
66
- h.color('Public IP', :bold),
67
- h.color('Private IP', :bold),
68
- h.color('Flavor', :bold),
69
- h.color('Image', :bold),
70
- h.color('Security Groups', :bold),
71
- h.color('State', :bold)
72
- ]
73
- connection.servers.all.each do |server|
74
- server_list << server.id.to_s
75
- server_list << (server.ip_address == nil ? "" : server.ip_address)
76
- server_list << (server.private_ip_address == nil ? "" : server.private_ip_address)
77
- server_list << (server.flavor_id == nil ? "" : server.flavor_id)
78
- server_list << (server.image_id == nil ? "" : server.image_id)
79
- server_list << server.groups.join(", ")
80
- server_list << server.state
81
- end
82
- puts h.list(server_list, :columns_across, 7)
83
-
84
- end
85
- end
86
- end
87
- end
88
-
89
-
@@ -1,184 +0,0 @@
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 'chef/json_compat'
21
- require 'uuidtools'
22
-
23
- class Chef
24
- class Knife
25
- class RackspaceServerCreate < Knife
26
-
27
- banner "knife rackspace server create [RUN LIST...] (options)"
28
-
29
- option :flavor,
30
- :short => "-f FLAVOR",
31
- :long => "--flavor FLAVOR",
32
- :description => "The flavor of server",
33
- :proc => Proc.new { |f| f.to_i },
34
- :default => 1
35
-
36
- option :image,
37
- :short => "-i IMAGE",
38
- :long => "--image IMAGE",
39
- :description => "The image of the server",
40
- :proc => Proc.new { |i| i.to_i }
41
-
42
- option :server_name,
43
- :short => "-S NAME",
44
- :long => "--server-name NAME",
45
- :description => "The server name. Defaults to a random UUID.",
46
- :default => UUIDTools::UUID.random_create.to_s
47
-
48
- option :chef_node_name,
49
- :short => "-N NAME",
50
- :long => "--node-name NAME",
51
- :description => "The Chef node name for your new node"
52
-
53
- option :ssh_user,
54
- :short => "-x USERNAME",
55
- :long => "--ssh-user USERNAME",
56
- :description => "The ssh username",
57
- :default => "root"
58
-
59
- option :ssh_password,
60
- :short => "-P PASSWORD",
61
- :long => "--ssh-password PASSWORD",
62
- :description => "The ssh password"
63
-
64
- option :api_key,
65
- :short => "-K KEY",
66
- :long => "--rackspace-api-key KEY",
67
- :description => "Your rackspace API key",
68
- :proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }
69
-
70
- option :api_username,
71
- :short => "-A USERNAME",
72
- :long => "--rackspace-api-username USERNAME",
73
- :description => "Your rackspace API username",
74
- :proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }
75
-
76
- option :prerelease,
77
- :long => "--prerelease",
78
- :description => "Install the pre-release chef gems"
79
-
80
- option :distro,
81
- :short => "-d DISTRO",
82
- :long => "--distro DISTRO",
83
- :description => "Bootstrap a distro using a template",
84
- :default => "ubuntu10.04-gems"
85
-
86
- option :template_file,
87
- :long => "--template-file TEMPLATE",
88
- :description => "Full path to location of template to use",
89
- :default => false
90
-
91
- def h
92
- @highline ||= HighLine.new
93
- end
94
-
95
- def tcp_test_ssh(hostname)
96
- tcp_socket = TCPSocket.new(hostname, 22)
97
- readable = IO.select([tcp_socket], nil, nil, 5)
98
- if readable
99
- Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
100
- yield
101
- true
102
- else
103
- false
104
- end
105
- rescue Errno::ETIMEDOUT
106
- false
107
- rescue Errno::ECONNREFUSED
108
- sleep 2
109
- false
110
- ensure
111
- tcp_socket && tcp_socket.close
112
- end
113
-
114
- def run
115
- require 'fog'
116
- require 'highline'
117
- require 'net/ssh/multi'
118
- require 'readline'
119
-
120
- $stdout.sync = true
121
-
122
- connection = Fog::Rackspace::Compute.new(
123
- :rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
124
- :rackspace_username => Chef::Config[:knife][:rackspace_api_username]
125
- )
126
-
127
- server = connection.servers.create(
128
- :name => config[:server_name],
129
- :image_id => config[:image],
130
- :flavor_id => config[:flavor]
131
- )
132
-
133
- puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
134
- puts "#{h.color("Name", :cyan)}: #{server.name}"
135
- puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
136
- puts "#{h.color("Image", :cyan)}: #{server.image_id}"
137
- puts "#{h.color("Public IP Address", :cyan)}: #{server.addresses["public"][0]}"
138
- puts "#{h.color("Private IP Address", :cyan)}: #{server.addresses["private"][0]}"
139
- puts "#{h.color("Password", :cyan)}: #{server.password}"
140
-
141
- print "\n#{h.color("Requesting server", :magenta)}"
142
-
143
- # wait for it to be ready to do stuff
144
- server.wait_for { print "."; ready? }
145
-
146
- puts("\n")
147
-
148
- print "\n#{h.color("Waiting for sshd", :magenta)}"
149
-
150
- print(".") until tcp_test_ssh(server.addresses["public"][0]) { sleep @initial_sleep_delay ||= 10; puts("done") }
151
-
152
- bootstrap_for_node(server).run
153
-
154
- puts "\n"
155
- puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
156
- puts "#{h.color("Name", :cyan)}: #{server.name}"
157
- puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
158
- puts "#{h.color("Image", :cyan)}: #{server.image_id}"
159
- puts "#{h.color("Public IP Address", :cyan)}: #{server.addresses["public"][0]}"
160
- puts "#{h.color("Private IP Address", :cyan)}: #{server.addresses["private"][0]}"
161
- puts "#{h.color("Password", :cyan)}: #{server.password}"
162
- puts "#{h.color("Run List", :cyan)}: #{@name_args.join(', ')}"
163
- end
164
-
165
- def bootstrap_for_node(server)
166
- bootstrap = Chef::Knife::Bootstrap.new
167
- bootstrap.name_args = [server.addresses["public"][0]]
168
- bootstrap.config[:run_list] = @name_args
169
- bootstrap.config[:ssh_user] = config[:ssh_user] || "root"
170
- bootstrap.config[:ssh_password] = server.password
171
- bootstrap.config[:identity_file] = config[:identity_file]
172
- bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
173
- bootstrap.config[:prerelease] = config[:prerelease]
174
- bootstrap.config[:distro] = config[:distro]
175
- bootstrap.config[:use_sudo] = true
176
- bootstrap.config[:template_file] = config[:template_file]
177
- bootstrap.config[:environment] = config[:environment]
178
- bootstrap
179
- end
180
- end
181
- end
182
- end
183
-
184
-