knife-eucalyptus 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-eucalyptus.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,89 @@
1
+ = Knife Eucalyptus
2
+
3
+ = DESCRIPTION:
4
+
5
+ This is the official Opscode Knife plugin for Eucalyptus. This plugin gives knife the ability to create, bootstrap, and manage instances in Eucalyptus clouds.
6
+
7
+ = INSTALLATION:
8
+
9
+ Be sure you are running the latest version Chef. Versions earlier than 0.10.0 don't support plugins:
10
+
11
+ $ gem install chef
12
+
13
+ This plugin is distributed as a Ruby Gem. To install it, run:
14
+
15
+ $ gem install knife-eucalyptus
16
+
17
+ Depending on your system's configuration, you may need to run this command with root privileges.
18
+
19
+ = CONFIGURATION:
20
+
21
+ In order to communicate with an Eucalyptus Cloud's API you will have to tell Knife about your Eucalyptus cloud API endpoint, Eucalyptus Access Key and Secret Access Key. The easiest way to accomplish this is to create some entries in your <tt>knife.rb</tt> file:
22
+
23
+ ### Connect the Eucalyptus Community Cloud
24
+ knife[:euca_access_key_id] = "Your Eucalyptus Access Key ID"
25
+ knife[:euca_secret_access_key] = "Your Eucalyptus Secret Access Key"
26
+ knife[:euca_api_endpoint] = "http://ecc.eucalyptus.com:8773/services/Eucalyptus"
27
+
28
+ If your knife.rb file will be checked into a SCM system (ie readable by others) you may want to read the values from environment variables:
29
+
30
+ knife[:euca_access_key_id] = "#{ENV['EUCA_ACCESS_KEY']}"
31
+ knife[:euca_secret_access_key] = "#{ENV['EUCA_SECRET_KEY']}"
32
+ knife[:euca_api_endpoint] = "#{ENV['EUCA_URL']}"
33
+
34
+ You also have the option of passing your Eucalyptus API Key/Secret into the individual knife subcommands using the <tt>-A</tt> (or <tt>--euca-access-key-id</tt>) <tt>-K</tt> (or <tt>--euca-secret-access-key</tt>) command options
35
+
36
+ # provision a new m1.large Ubuntu 10.04 webserver
37
+ knife euca server create 'role[webserver]' -I emi-8A1119CC -f m1.large -A 'Your Eucalyptus Access Key ID' -K 'Your Eucalyptus Secret Access Key' --euca-api-endpoint 'https://cloud.mycompany.com:8773/services/Eucalyptus'
38
+
39
+ Additionally the following options may be set in your `knife.rb`:
40
+
41
+ * flavor
42
+ * image
43
+ * availability_zone
44
+ * euca_ssh_key_id
45
+ * region
46
+ * distro
47
+ * template_file
48
+
49
+ = SUBCOMMANDS:
50
+
51
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a <tt>--help</tt> flag
52
+
53
+ == knife euca server create
54
+
55
+ Provisions a new server in an Eucalyptus cloud and then perform a Chef bootstrap (using the SSH protocol). The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists (provided by the provisioning). It is primarily intended for Chef Client systems that talk to a Chef server. By default the server is bootstrapped using the {ubuntu10.04-gems}[https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb] template. This can be overridden using the <tt>-d</tt> or <tt>--template-file</tt> command options.
56
+
57
+ == knife euca server delete
58
+
59
+ Deletes an existing server in the currently configured Eucalyptus cloud account. <b>PLEASE NOTE</b> - this does not delete the associated node and client objects from the Chef server.
60
+
61
+ == knife euca server list
62
+
63
+ Outputs a list of all servers in the currently configured Eucalyptus cloud account. <b>PLEASE NOTE</b> - this shows all instances associated with the account, some of which may not be currently managed by the Chef server.
64
+
65
+ == knife euca flavor list
66
+
67
+ Outputs a list of all available flavors (available hardware configuration for a server) available to the currently configured Eucalyptus cloud account. Each flavor has a unique combination of disk space, memory capacity and priority for CPU time. This data can be useful when choosing a flavor id to pass to the <tt>knife euca server create</tt> subcommand.
68
+
69
+ == knife euca image list
70
+
71
+ Outputs a list of all available images available to the currently configured Eucalyptus cloud account. An image is a collection of files used to create or rebuild a server. This data can be useful when choosing an image id to pass to the <tt>knife euca server create</tt> subcommand.
72
+
73
+ = LICENSE:
74
+
75
+ Author:: Seth Chisamore (<schisamo@opscode.com>)
76
+ Copyright:: Copyright (c) 2011 Opscode, Inc.
77
+ License:: Apache License, Version 2.0
78
+
79
+ Licensed under the Apache License, Version 2.0 (the "License");
80
+ you may not use this file except in compliance with the License.
81
+ You may obtain a copy of the License at
82
+
83
+ http://www.apache.org/licenses/LICENSE-2.0
84
+
85
+ Unless required by applicable law or agreed to in writing, software
86
+ distributed under the License is distributed on an "AS IS" BASIS,
87
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88
+ See the License for the specific language governing permissions and
89
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "knife-eucalyptus/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "knife-eucalyptus"
7
+ s.version = Knife::Eucalyptus::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
11
+ s.authors = ["Seth Chisamore"]
12
+ s.email = ["schisamo@opscode.com"]
13
+ s.homepage = "https://github.com/opscode/knife-eucalyptus"
14
+ s.summary = %q{Eucalyptus Cloud Support for Chef's Knife Command}
15
+ s.description = s.summary
16
+
17
+ s.rubyforge_project = "knife-eucalyptus"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_dependency "fog", "~> 0.8.2"
25
+ s.add_dependency "net-ssh", "~> 2.1.3"
26
+ s.add_dependency "net-ssh-multi", "~> 1.0.1"
27
+ end
@@ -0,0 +1,86 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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 File.expand_path('../../../knife-eucalyptus/highline_patch', __FILE__)
20
+ require 'chef/knife'
21
+
22
+ class Chef
23
+ class Knife
24
+ class EucaBase < Knife
25
+
26
+ deps do
27
+ require 'fog'
28
+ require 'net/ssh/multi'
29
+ require 'readline'
30
+ require 'chef/json_compat'
31
+ end
32
+
33
+ banner ""
34
+
35
+ option :euca_access_key_id,
36
+ :short => "-A ID",
37
+ :long => "--euca-access-key-id KEY",
38
+ :description => "Your Eucalyptus Access Key ID",
39
+ :proc => Proc.new { |key| Chef::Config[:knife][:euca_access_key_id] = key }
40
+
41
+ option :euca_secret_access_key,
42
+ :short => "-K SECRET",
43
+ :long => "--euca-secret-access-key SECRET",
44
+ :description => "Your Eucalyptus API Secret Access Key",
45
+ :proc => Proc.new { |key| Chef::Config[:knife][:euca_secret_access_key] = key }
46
+
47
+ option :euca_api_endpoint,
48
+ :long => "--euca-api-endpoint ENDPOINT",
49
+ :description => "Your Eucalyptus API endpoint",
50
+ :default => "http://ecc.eucalyptus.com:8773/services/Eucalyptus",
51
+ :proc => Proc.new { |endpoint| Chef::Config[:knife][:euca_api_endpoint] = endpoint }
52
+
53
+ option :region,
54
+ :long => "--region REGION",
55
+ :description => "Your Eucalyptus region",
56
+ :proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
57
+
58
+ def connection
59
+ @connection ||= begin
60
+ Fog::Compute.new(
61
+ :provider => 'AWS',
62
+ :aws_access_key_id => Chef::Config[:knife][:euca_access_key_id],
63
+ :aws_secret_access_key => Chef::Config[:knife][:euca_secret_access_key],
64
+ :endpoint => Chef::Config[:knife][:euca_api_endpoint] || config[:euca_api_endpoint],
65
+ :region => Chef::Config[:knife][:region] || config[:region]
66
+ )
67
+ end
68
+ end
69
+
70
+ def public_ip(public_dns)
71
+ @public_ip ||= begin
72
+ require 'resolv'
73
+ Resolv.getaddress(public_dns)
74
+ rescue
75
+ end
76
+ end
77
+
78
+ def locate_config_value(key)
79
+ key = key.to_sym
80
+ Chef::Config[:knife][key] || config[key]
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+
@@ -0,0 +1,46 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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/euca_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EucaFlavorList < EucaBase
24
+
25
+ banner "knife euca flavor list (options)"
26
+
27
+ def run
28
+ flavor_list = [
29
+ ui.color('ID', :bold),
30
+ ui.color('Architecture', :bold),
31
+ ui.color('RAM', :bold),
32
+ ui.color('Disk', :bold),
33
+ ui.color('Cores', :bold)
34
+ ]
35
+ connection.flavors.sort_by(&:id).each do |flavor|
36
+ flavor_list << flavor.id.to_s
37
+ flavor_list << "#{flavor.bits.to_s}-bit"
38
+ flavor_list << "#{flavor.ram.to_s} MB"
39
+ flavor_list << "#{flavor.disk.to_s} GB"
40
+ flavor_list << flavor.cores.to_s
41
+ end
42
+ puts ui.list(flavor_list, :columns_across, 5)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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/euca_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EucaImageList < EucaBase
24
+
25
+ banner "knife euca image list (options)"
26
+
27
+ def run
28
+ image_list = [
29
+ ui.color('ID', :bold),
30
+ ui.color('Kernel ID', :bold),
31
+ ui.color('Architecture', :bold),
32
+ ui.color('Location', :bold)
33
+ ]
34
+
35
+ connection.images.sort_by do |image|
36
+ [image.location, image.architecture].compact
37
+ end.each do |image|
38
+ image_list << image.id
39
+ image_list << image.kernel_id
40
+ image_list << image.architecture
41
+ image_list << image.location
42
+ end
43
+
44
+ image_list = image_list.map do |item|
45
+ item.to_s
46
+ end
47
+
48
+ puts ui.list(image_list, :columns_across, 4)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,226 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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/euca_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EucaServerCreate < EucaBase
24
+
25
+ deps do
26
+ require 'chef/knife/bootstrap'
27
+ Chef::Knife::Bootstrap.load_deps
28
+ end
29
+
30
+ banner "knife euca server create (options)"
31
+
32
+ attr_accessor :initial_sleep_delay
33
+
34
+ option :flavor,
35
+ :short => "-f FLAVOR",
36
+ :long => "--flavor FLAVOR",
37
+ :description => "The flavor of server (m1.small, m1.medium, etc)",
38
+ :proc => Proc.new { |f| Chef::Config[:knife][:flavor] = f }
39
+
40
+ option :image,
41
+ :short => "-I IMAGE",
42
+ :long => "--image IMAGE",
43
+ :description => "The AMI for the server",
44
+ :proc => Proc.new { |i| Chef::Config[:knife][:image] = i }
45
+
46
+ option :security_groups,
47
+ :short => "-G X,Y,Z",
48
+ :long => "--groups X,Y,Z",
49
+ :description => "The security groups for this server",
50
+ :default => ["default"],
51
+ :proc => Proc.new { |groups| groups.split(',') }
52
+
53
+ option :availability_zone,
54
+ :short => "-Z ZONE",
55
+ :long => "--availability-zone ZONE",
56
+ :description => "The Availability Zone",
57
+ :proc => Proc.new { |key| Chef::Config[:knife][:availability_zone] = key }
58
+
59
+ option :chef_node_name,
60
+ :short => "-N NAME",
61
+ :long => "--node-name NAME",
62
+ :description => "The Chef node name for your new node"
63
+
64
+ option :ssh_key_name,
65
+ :short => "-S KEY",
66
+ :long => "--ssh-key KEY",
67
+ :description => "The Eucalyptus SSH key id",
68
+ :proc => Proc.new { |key| Chef::Config[:knife][:euca_ssh_key_id] = key }
69
+
70
+ option :ssh_user,
71
+ :short => "-x USERNAME",
72
+ :long => "--ssh-user USERNAME",
73
+ :description => "The ssh username",
74
+ :default => "root"
75
+
76
+ option :ssh_password,
77
+ :short => "-P PASSWORD",
78
+ :long => "--ssh-password PASSWORD",
79
+ :description => "The ssh password"
80
+
81
+ option :identity_file,
82
+ :short => "-i IDENTITY_FILE",
83
+ :long => "--identity-file IDENTITY_FILE",
84
+ :description => "The SSH identity file used for authentication"
85
+
86
+ option :prerelease,
87
+ :long => "--prerelease",
88
+ :description => "Install the pre-release chef gems"
89
+
90
+ option :bootstrap_version,
91
+ :long => "--bootstrap-version VERSION",
92
+ :description => "The version of Chef to install",
93
+ :proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
94
+
95
+ option :distro,
96
+ :short => "-d DISTRO",
97
+ :long => "--distro DISTRO",
98
+ :description => "Bootstrap a distro using a template",
99
+ :proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
100
+ :default => "ubuntu10.04-gems"
101
+
102
+ option :template_file,
103
+ :long => "--template-file TEMPLATE",
104
+ :description => "Full path to location of template to use",
105
+ :proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
106
+ :default => false
107
+
108
+ option :run_list,
109
+ :short => "-r RUN_LIST",
110
+ :long => "--run-list RUN_LIST",
111
+ :description => "Comma separated list of roles/recipes to apply",
112
+ :proc => lambda { |o| o.split(/[\s,]+/) },
113
+ :default => []
114
+
115
+ option :no_host_key_verify,
116
+ :long => "--no-host-key-verify",
117
+ :description => "Disable host key verification",
118
+ :boolean => true,
119
+ :default => false
120
+
121
+ def tcp_test_ssh(hostname)
122
+ tcp_socket = TCPSocket.new(hostname, 22)
123
+ readable = IO.select([tcp_socket], nil, nil, 5)
124
+ if readable
125
+ Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
126
+ yield
127
+ true
128
+ else
129
+ false
130
+ end
131
+ rescue Errno::ETIMEDOUT
132
+ false
133
+ rescue Errno::EPERM
134
+ false
135
+ rescue Errno::ECONNREFUSED
136
+ sleep 2
137
+ false
138
+ rescue Errno::EHOSTUNREACH
139
+ sleep 2
140
+ false
141
+ ensure
142
+ tcp_socket && tcp_socket.close
143
+ end
144
+
145
+ def run
146
+ $stdout.sync = true
147
+
148
+ server_def = {
149
+ :image_id => locate_config_value(:image),
150
+ :groups => config[:security_groups],
151
+ :flavor_id => locate_config_value(:flavor),
152
+ :key_name => Chef::Config[:knife][:euca_ssh_key_id],
153
+ :availability_zone => Chef::Config[:knife][:availability_zone]
154
+ }
155
+
156
+ server = connection.servers.create(server_def)
157
+
158
+ puts "#{ui.color("Instance ID", :cyan)}: #{server.id}"
159
+ puts "#{ui.color("Flavor", :cyan)}: #{server.flavor_id}"
160
+ puts "#{ui.color("Image", :cyan)}: #{server.image_id}"
161
+ puts "#{ui.color("Availability Zone", :cyan)}: #{server.availability_zone}"
162
+ puts "#{ui.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
163
+ puts "#{ui.color("SSH Key", :cyan)}: #{server.key_name}"
164
+
165
+ print "\n#{ui.color("Waiting for server", :magenta)}"
166
+
167
+ display_name = server.dns_name
168
+
169
+ # wait for it to be ready to do stuff
170
+ server.wait_for { print "."; ready? }
171
+
172
+ puts("\n")
173
+
174
+ puts "#{ui.color("Public DNS Name", :cyan)}: #{server.dns_name}"
175
+ puts "#{ui.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
176
+
177
+ print "\n#{ui.color("Waiting for sshd", :magenta)}"
178
+
179
+ print(".") until tcp_test_ssh(display_name) {
180
+ sleep @initial_sleep_delay ||= 10
181
+ puts("done")
182
+ }
183
+
184
+ until begin
185
+ bootstrap_for_node(server).run
186
+ true
187
+ rescue Errno::ECONNREFUSED
188
+ sleep 2
189
+ false
190
+ end
191
+ end
192
+
193
+ puts "\n"
194
+ puts "#{ui.color("Instance ID", :cyan)}: #{server.id}"
195
+ puts "#{ui.color("Flavor", :cyan)}: #{server.flavor_id}"
196
+ puts "#{ui.color("Image", :cyan)}: #{server.image_id}"
197
+ puts "#{ui.color("Availability Zone", :cyan)}: #{server.availability_zone}"
198
+ puts "#{ui.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
199
+ puts "#{ui.color("Public DNS Name", :cyan)}: #{server.dns_name}"
200
+ puts "#{ui.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
201
+ puts "#{ui.color("SSH Key", :cyan)}: #{server.key_name}"
202
+ puts "#{ui.color("Environment", :cyan)}: #{config[:environment] || '_default'}"
203
+ puts "#{ui.color("Run List", :cyan)}: #{config[:run_list].join(', ')}"
204
+ end
205
+
206
+ def bootstrap_for_node(server)
207
+ bootstrap = Chef::Knife::Bootstrap.new
208
+ bootstrap.name_args = [server.dns_name]
209
+ bootstrap.config[:run_list] = config[:run_list]
210
+ bootstrap.config[:ssh_user] = config[:ssh_user]
211
+ bootstrap.config[:identity_file] = config[:identity_file]
212
+ bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
213
+ bootstrap.config[:prerelease] = config[:prerelease]
214
+ bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version)
215
+ bootstrap.config[:distro] = locate_config_value(:distro)
216
+ bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root'
217
+ bootstrap.config[:template_file] = locate_config_value(:template_file)
218
+ bootstrap.config[:environment] = config[:environment]
219
+ # may be needed for vpc_mode
220
+ bootstrap.config[:no_host_key_verify] = config[:no_host_key_verify]
221
+ bootstrap
222
+ end
223
+
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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/euca_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EucaServerDelete < EucaBase
24
+
25
+ banner "knife euca server delete SERVER_ID [SERVER_ID] (options)"
26
+
27
+ def run
28
+ @name_args.each do |instance_id|
29
+ server = connection.servers.get(instance_id)
30
+
31
+ msg("Instance ID", server.id)
32
+ msg("Flavor", server.flavor_id)
33
+ msg("Image", server.image_id)
34
+ msg("Availability Zone", server.availability_zone)
35
+ msg("Security Groups", server.groups.join(", "))
36
+ msg("SSH Key", server.key_name)
37
+ msg("Public DNS Name", server.dns_name)
38
+ msg("Private DNS Name", server.private_dns_name)
39
+
40
+ puts "\n"
41
+ confirm("Do you really want to delete this server")
42
+
43
+ server.destroy
44
+
45
+ ui.warn("Deleted server #{server.id}")
46
+ end
47
+ end
48
+
49
+ def msg(label, value)
50
+ if value && !value.empty?
51
+ puts "#{ui.color(label, :cyan)}: #{value}"
52
+ end
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,52 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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/euca_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EucaServerList < EucaBase
24
+
25
+ banner "knife euca server list (options)"
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ server_list = [
31
+ ui.color('Instance ID', :bold),
32
+ ui.color('Public DNS Name', :bold),
33
+ ui.color('Flavor', :bold),
34
+ ui.color('Image', :bold),
35
+ ui.color('Security Groups', :bold),
36
+ ui.color('State', :bold)
37
+ ]
38
+ connection.servers.all.each do |server|
39
+ server_list << server.id.to_s
40
+ server_list << (server.dns_name || "" )
41
+ server_list << (server.flavor_id || "")
42
+ server_list << (server.image_id || "")
43
+ server_list << server.groups.join(", ")
44
+ server_list << server.state
45
+ end
46
+ puts ui.list(server_list, :columns_across, 6)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+
@@ -0,0 +1,53 @@
1
+ # monkey patch highline to allow max_length to be
2
+ # based on individual columns
3
+ require 'highline'
4
+ class HighLine
5
+
6
+ alias :old_list :list
7
+
8
+ def list( items, mode = :rows, option = nil )
9
+ case mode
10
+ when :columns_across
11
+
12
+ row_count = (items.size / option.to_f).ceil
13
+
14
+ if option.nil?
15
+ limit = @wrap_at || 80
16
+ option = (limit + 2) / (max_length + 2)
17
+ end
18
+
19
+ rows = Array.new(row_count) { Array.new }
20
+ items.each_with_index do |item, index|
21
+ rows[index / option] << item
22
+ end
23
+
24
+ cols = Array.new(option) { Array.new }
25
+ rows.each do |row|
26
+ row.each_with_index do |item, index|
27
+ cols[index] << item
28
+ end
29
+ end
30
+
31
+ max_length = cols.map do |col|
32
+ actual_length(
33
+ col.max { |a, b| actual_length(a) <=> actual_length(b) }
34
+ )
35
+ end
36
+
37
+ require 'enumerator'
38
+ rows = rows.enum_for(:each_with_index).map do |row, row_index|
39
+ row.enum_for(:each_with_index).map do |item, col_index|
40
+ pad = max_length[col_index] + (item.length - actual_length(item))
41
+ "%-#{pad}s" % item
42
+ end
43
+ end
44
+
45
+ rows.map { |row| row.join(" ") + "\n" }.join
46
+
47
+ else
48
+
49
+ old_list(items, mode, option)
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ module Knife
2
+ module Eucalyptus
3
+ VERSION = "0.5.0"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-eucalyptus
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.5.0
6
+ platform: ruby
7
+ authors:
8
+ - Seth Chisamore
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-15 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: fog
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.8.2
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-ssh
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 2.1.3
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: net-ssh-multi
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.1
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ description: Eucalyptus Cloud Support for Chef's Knife Command
50
+ email:
51
+ - schisamo@opscode.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - README.rdoc
58
+ - LICENSE
59
+ files:
60
+ - .gitignore
61
+ - Gemfile
62
+ - LICENSE
63
+ - README.rdoc
64
+ - Rakefile
65
+ - knife-eucalyptus.gemspec
66
+ - lib/chef/knife/euca_base.rb
67
+ - lib/chef/knife/euca_flavor_list.rb
68
+ - lib/chef/knife/euca_image_list.rb
69
+ - lib/chef/knife/euca_server_create.rb
70
+ - lib/chef/knife/euca_server_delete.rb
71
+ - lib/chef/knife/euca_server_list.rb
72
+ - lib/knife-eucalyptus/highline_patch.rb
73
+ - lib/knife-eucalyptus/version.rb
74
+ has_rdoc: true
75
+ homepage: https://github.com/opscode/knife-eucalyptus
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project: knife-eucalyptus
98
+ rubygems_version: 1.6.2
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Eucalyptus Cloud Support for Chef's Knife Command
102
+ test_files: []
103
+