knife-openstack 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.rdoc +84 -0
- data/Rakefile +2 -0
- data/knife-openstack.gemspec +27 -0
- data/lib/chef/knife/openstack_flavor_list.rb +79 -0
- data/lib/chef/knife/openstack_image_list.rb +79 -0
- data/lib/chef/knife/openstack_server_create.rb +282 -0
- data/lib/chef/knife/openstack_server_delete.rb +100 -0
- data/lib/chef/knife/openstack_server_list.rb +95 -0
- data/lib/knife-openstack/version.rb +6 -0
- metadata +123 -0
data/Gemfile
ADDED
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= Knife OpenStack
|
2
|
+
|
3
|
+
= DESCRIPTION:
|
4
|
+
|
5
|
+
This is the official Opscode Knife plugin for OpenStack Compute (Nova). This plugin gives knife the ability to create, bootstrap, and manage instances in OpenStack Compute clouds.
|
6
|
+
|
7
|
+
= INSTALLATION:
|
8
|
+
|
9
|
+
This plugin is distributed as a Ruby Gem. To install it, run:
|
10
|
+
|
11
|
+
gem install knife-openstack
|
12
|
+
|
13
|
+
Depending on your system's configuration, you may need to run this command with root privileges.
|
14
|
+
|
15
|
+
= CONFIGURATION:
|
16
|
+
|
17
|
+
In order to communicate with an OpenStack Compute cloud's API you will have to tell Knife about your OpenStack Compute cloud API endpoint, OpenStack Access Key and Secret Access Key. The easiest way to accomplish this is to create some entries in your <tt>knife.rb</tt> file:
|
18
|
+
|
19
|
+
knife[:openstack_access_key_id] = "Your OpenStack Access Key ID"
|
20
|
+
knife[:openstack_secret_access_key] = "Your OpenStack Secret Access Key"
|
21
|
+
knife[:openstack_api_endpoint] = "https://cloud.mycompany.com/v1.0"
|
22
|
+
|
23
|
+
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:
|
24
|
+
|
25
|
+
knife[:openstack_access_key_id] = "#{ENV['OPENSTACK_ACCESS_KEY_ID']}"
|
26
|
+
knife[:openstack_secret_access_key] = "#{ENV['OPENSTACK_SECRET_ACCESS_KEY']}"
|
27
|
+
knife[:openstack_api_endpoint] = "https://cloud.mycompany.com/v1.0"
|
28
|
+
|
29
|
+
You also have the option of passing your OpenStack API Key/Secret into the individual knife subcommands using the <tt>-A</tt> (or <tt>--openstack-access-key-id</tt>) <tt>-K</tt> (or <tt>--openstack-secret-access-key</tt>) command options
|
30
|
+
|
31
|
+
# provision a new m1.small Ubuntu 10.04 webserver
|
32
|
+
knife openstack server create 'role[webserver]' -i ami-7000f019 -f m1.small -A 'Your OpenStack Access Key ID' -K 'Your OpenStack Secret Access Key' --openstack-api-endpoint 'https://cloud.mycompany.com/v1.0'
|
33
|
+
|
34
|
+
Additionally the following options may be set in your `knife.rb`:
|
35
|
+
|
36
|
+
* flavor
|
37
|
+
* image
|
38
|
+
* availability_zone
|
39
|
+
* openstack_ssh_key_id
|
40
|
+
* region
|
41
|
+
* distro
|
42
|
+
* template_file
|
43
|
+
|
44
|
+
= SUBCOMMANDS:
|
45
|
+
|
46
|
+
This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a <tt>--help</tt> flag
|
47
|
+
|
48
|
+
== knife openstack server create
|
49
|
+
|
50
|
+
Provisions a new server in an OpenStack Compute 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.
|
51
|
+
|
52
|
+
== knife openstack server delete
|
53
|
+
|
54
|
+
Deletes an existing server in the currently configured OpenStack Compute cloud account. <b>PLEASE NOTE</b> - this does not delete the associated node and client objects from the Chef server.
|
55
|
+
|
56
|
+
== knife openstack server list
|
57
|
+
|
58
|
+
Outputs a list of all servers in the currently configured OpenStack Compute 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.
|
59
|
+
|
60
|
+
== knife openstack flavor list
|
61
|
+
|
62
|
+
Outputs a list of all available flavors (available hardware configuration for a server) available to the currently configured OpenStack Compute 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 openstack server create</tt> subcommand.
|
63
|
+
|
64
|
+
== knife openstack image list
|
65
|
+
|
66
|
+
Outputs a list of all available images available to the currently configured OpenStack Compute 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 openstack server create</tt> subcommand.
|
67
|
+
|
68
|
+
= LICENSE:
|
69
|
+
|
70
|
+
Author:: Seth Chisamore (<schisamo@opscode.com>)
|
71
|
+
Copyright:: Copyright (c) 2011 Opscode, Inc.
|
72
|
+
License:: Apache License, Version 2.0
|
73
|
+
|
74
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
75
|
+
you may not use this file except in compliance with the License.
|
76
|
+
You may obtain a copy of the License at
|
77
|
+
|
78
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
79
|
+
|
80
|
+
Unless required by applicable law or agreed to in writing, software
|
81
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
82
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
83
|
+
See the License for the specific language governing permissions and
|
84
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "knife-openstack/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "knife-openstack"
|
7
|
+
s.version = Knife::OpenStack::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-openstack"
|
14
|
+
s.summary = %q{OpenStack Compute Support for Chef's Knife Command}
|
15
|
+
s.description = s.summary
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "chef", ">= 0.9.14"
|
23
|
+
s.add_dependency "fog", "~> 0.6.0"
|
24
|
+
s.add_dependency "net-ssh", "~> 2.1.3"
|
25
|
+
s.add_dependency "net-ssh-multi", "~> 1.0.1"
|
26
|
+
s.add_dependency "highline", "~> 1.6.1"
|
27
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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 'fog'
|
20
|
+
require 'chef/knife'
|
21
|
+
require 'chef/json_compat'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class OpenstackFlavorList < Knife
|
26
|
+
|
27
|
+
banner "knife openstack flavor list (options)"
|
28
|
+
|
29
|
+
option :openstack_access_key_id,
|
30
|
+
:short => "-A ID",
|
31
|
+
:long => "--openstack-access-key-id KEY",
|
32
|
+
:description => "Your OpenStack Access Key ID",
|
33
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
|
34
|
+
|
35
|
+
option :openstack_secret_access_key,
|
36
|
+
:short => "-K SECRET",
|
37
|
+
:long => "--openstack-secret-access-key SECRET",
|
38
|
+
:description => "Your OpenStack API Secret Access Key",
|
39
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
|
40
|
+
|
41
|
+
option :openstack_api_endpoint,
|
42
|
+
:long => "--openstack-api-endpoint ENDPOINT",
|
43
|
+
:description => "Your OpenStack API endpoint",
|
44
|
+
:proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
|
45
|
+
|
46
|
+
option :region,
|
47
|
+
:long => "--region REGION",
|
48
|
+
:description => "Your OpenStack region",
|
49
|
+
:proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
|
50
|
+
|
51
|
+
def h
|
52
|
+
@highline ||= HighLine.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def run
|
56
|
+
require 'fog'
|
57
|
+
|
58
|
+
connection = Fog::Compute.new(
|
59
|
+
:provider => 'AWS',
|
60
|
+
:aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
|
61
|
+
:aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
|
62
|
+
:endpoint => Chef::Config[:knife][:openstack_api_endpoint],
|
63
|
+
:region => Chef::Config[:knife][:region] || config[:region]
|
64
|
+
)
|
65
|
+
|
66
|
+
flavor_list = [ h.color('ID', :bold), h.color('Name', :bold), h.color('Architecture', :bold), h.color('RAM', :bold), h.color('Disk', :bold) , h.color('Cores', :bold) ]
|
67
|
+
connection.flavors.sort_by(&:id).each do |flavor|
|
68
|
+
flavor_list << flavor.id.to_s
|
69
|
+
flavor_list << flavor.name
|
70
|
+
flavor_list << "#{flavor.bits.to_s}-bit"
|
71
|
+
flavor_list << "#{flavor.ram.to_s}"
|
72
|
+
flavor_list << "#{flavor.disk.to_s} GB"
|
73
|
+
flavor_list << flavor.cores.to_s
|
74
|
+
end
|
75
|
+
puts h.list(flavor_list, :columns_across, 6)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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 'fog'
|
20
|
+
require 'chef/knife'
|
21
|
+
require 'chef/json_compat'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class OpenstackImageList < Knife
|
26
|
+
|
27
|
+
banner "knife openstack image list (options)"
|
28
|
+
|
29
|
+
option :openstack_access_key_id,
|
30
|
+
:short => "-A ID",
|
31
|
+
:long => "--openstack-access-key-id KEY",
|
32
|
+
:description => "Your OpenStack Access Key ID",
|
33
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
|
34
|
+
|
35
|
+
option :openstack_secret_access_key,
|
36
|
+
:short => "-K SECRET",
|
37
|
+
:long => "--openstack-secret-access-key SECRET",
|
38
|
+
:description => "Your OpenStack API Secret Access Key",
|
39
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
|
40
|
+
|
41
|
+
option :openstack_api_endpoint,
|
42
|
+
:long => "--openstack-api-endpoint ENDPOINT",
|
43
|
+
:description => "Your OpenStack API endpoint",
|
44
|
+
:proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
|
45
|
+
|
46
|
+
option :region,
|
47
|
+
:long => "--region REGION",
|
48
|
+
:description => "Your OpenStack region",
|
49
|
+
:proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
|
50
|
+
|
51
|
+
def h
|
52
|
+
@highline ||= HighLine.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def run
|
56
|
+
require 'fog'
|
57
|
+
|
58
|
+
connection = Fog::Compute.new(
|
59
|
+
:provider => 'AWS',
|
60
|
+
:aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
|
61
|
+
:aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
|
62
|
+
:endpoint => Chef::Config[:knife][:openstack_api_endpoint],
|
63
|
+
:region => Chef::Config[:knife][:region] || config[:region]
|
64
|
+
)
|
65
|
+
|
66
|
+
image_list = [ h.color('ID', :bold), h.color('Kernel ID', :bold), h.color('Architecture', :bold), h.color('Root Store', :bold), h.color('Name', :bold), h.color('Location', :bold) ]
|
67
|
+
connection.images.sort_by(&:name).each do |image|
|
68
|
+
image_list << image.id.to_s
|
69
|
+
image_list << image.kernel_id.to_s
|
70
|
+
image_list << image.architecture.to_s
|
71
|
+
image_list << image.root_device_type
|
72
|
+
image_list << image.name
|
73
|
+
image_list << image.location
|
74
|
+
end
|
75
|
+
puts h.list(image_list, :columns_across, 6)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,282 @@
|
|
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 'fog'
|
20
|
+
require 'socket'
|
21
|
+
require 'chef/knife'
|
22
|
+
require 'chef/knife/bootstrap'
|
23
|
+
require 'chef/json_compat'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
class OpenstackServerCreate < Knife
|
28
|
+
|
29
|
+
banner "knife openstack server create (options)"
|
30
|
+
|
31
|
+
attr_accessor :initial_sleep_delay
|
32
|
+
|
33
|
+
option :flavor,
|
34
|
+
:short => "-f FLAVOR",
|
35
|
+
:long => "--flavor FLAVOR",
|
36
|
+
:description => "The flavor of server (m1.small, m1.medium, etc)",
|
37
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:flavor] = f }
|
38
|
+
|
39
|
+
option :image,
|
40
|
+
:short => "-I IMAGE",
|
41
|
+
:long => "--image IMAGE",
|
42
|
+
:description => "The AMI for the server",
|
43
|
+
:proc => Proc.new { |i| Chef::Config[:knife][:image] = i }
|
44
|
+
|
45
|
+
option :security_groups,
|
46
|
+
:short => "-G X,Y,Z",
|
47
|
+
:long => "--groups X,Y,Z",
|
48
|
+
:description => "The security groups for this server",
|
49
|
+
:default => ["default"],
|
50
|
+
:proc => Proc.new { |groups| groups.split(',') }
|
51
|
+
|
52
|
+
option :availability_zone,
|
53
|
+
:short => "-Z ZONE",
|
54
|
+
:long => "--availability-zone ZONE",
|
55
|
+
:description => "The Availability Zone",
|
56
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:availability_zone] = key }
|
57
|
+
|
58
|
+
option :chef_node_name,
|
59
|
+
:short => "-N NAME",
|
60
|
+
:long => "--node-name NAME",
|
61
|
+
:description => "The Chef node name for your new node"
|
62
|
+
|
63
|
+
option :ssh_key_name,
|
64
|
+
:short => "-S KEY",
|
65
|
+
:long => "--ssh-key KEY",
|
66
|
+
:description => "The OpenStack SSH key id",
|
67
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_ssh_key_id] = key }
|
68
|
+
|
69
|
+
option :ssh_user,
|
70
|
+
:short => "-x USERNAME",
|
71
|
+
:long => "--ssh-user USERNAME",
|
72
|
+
:description => "The ssh username",
|
73
|
+
:default => "root"
|
74
|
+
|
75
|
+
option :ssh_password,
|
76
|
+
:short => "-P PASSWORD",
|
77
|
+
:long => "--ssh-password PASSWORD",
|
78
|
+
:description => "The ssh password"
|
79
|
+
|
80
|
+
option :identity_file,
|
81
|
+
:short => "-i IDENTITY_FILE",
|
82
|
+
:long => "--identity-file IDENTITY_FILE",
|
83
|
+
:description => "The SSH identity file used for authentication"
|
84
|
+
|
85
|
+
option :openstack_access_key_id,
|
86
|
+
:short => "-A ID",
|
87
|
+
:long => "--openstack-access-key-id KEY",
|
88
|
+
:description => "Your OpenStack Access Key ID",
|
89
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
|
90
|
+
|
91
|
+
option :openstack_secret_access_key,
|
92
|
+
:short => "-K SECRET",
|
93
|
+
:long => "--openstack-secret-access-key SECRET",
|
94
|
+
:description => "Your OpenStack API Secret Access Key",
|
95
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
|
96
|
+
|
97
|
+
option :openstack_api_endpoint,
|
98
|
+
:long => "--openstack-api-endpoint ENDPOINT",
|
99
|
+
:description => "Your OpenStack API endpoint",
|
100
|
+
:proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
|
101
|
+
|
102
|
+
option :prerelease,
|
103
|
+
:long => "--prerelease",
|
104
|
+
:description => "Install the pre-release chef gems"
|
105
|
+
|
106
|
+
option :region,
|
107
|
+
:long => "--region REGION",
|
108
|
+
:description => "Your OpenStack region",
|
109
|
+
:proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
|
110
|
+
|
111
|
+
option :distro,
|
112
|
+
:short => "-d DISTRO",
|
113
|
+
:long => "--distro DISTRO",
|
114
|
+
:description => "Bootstrap a distro using a template",
|
115
|
+
:proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
|
116
|
+
:default => "ubuntu10.04-gems"
|
117
|
+
|
118
|
+
option :template_file,
|
119
|
+
:long => "--template-file TEMPLATE",
|
120
|
+
:description => "Full path to location of template to use",
|
121
|
+
:proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
|
122
|
+
:default => false
|
123
|
+
|
124
|
+
option :run_list,
|
125
|
+
:short => "-r RUN_LIST",
|
126
|
+
:long => "--run-list RUN_LIST",
|
127
|
+
:description => "Comma separated list of roles/recipes to apply",
|
128
|
+
:proc => lambda { |o| o.split(/[\s,]+/) },
|
129
|
+
:default => []
|
130
|
+
|
131
|
+
option :no_host_key_verify,
|
132
|
+
:long => "--no-host-key-verify",
|
133
|
+
:description => "Disable host key verification",
|
134
|
+
:boolean => true,
|
135
|
+
:default => false
|
136
|
+
|
137
|
+
def h
|
138
|
+
@highline ||= HighLine.new
|
139
|
+
end
|
140
|
+
|
141
|
+
def tcp_test_ssh(hostname)
|
142
|
+
tcp_socket = TCPSocket.new(hostname, 22)
|
143
|
+
readable = IO.select([tcp_socket], nil, nil, 5)
|
144
|
+
if readable
|
145
|
+
Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
|
146
|
+
yield
|
147
|
+
true
|
148
|
+
else
|
149
|
+
false
|
150
|
+
end
|
151
|
+
rescue Errno::ETIMEDOUT
|
152
|
+
false
|
153
|
+
rescue Errno::ECONNREFUSED
|
154
|
+
sleep 2
|
155
|
+
false
|
156
|
+
ensure
|
157
|
+
tcp_socket && tcp_socket.close
|
158
|
+
end
|
159
|
+
|
160
|
+
def run
|
161
|
+
require 'fog'
|
162
|
+
require 'highline'
|
163
|
+
require 'net/ssh/multi'
|
164
|
+
require 'readline'
|
165
|
+
|
166
|
+
$stdout.sync = true
|
167
|
+
|
168
|
+
connection = Fog::Compute.new(
|
169
|
+
:provider => 'AWS',
|
170
|
+
:aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
|
171
|
+
:aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
|
172
|
+
:endpoint => Chef::Config[:knife][:openstack_api_endpoint],
|
173
|
+
:region => locate_config_value(:region)
|
174
|
+
)
|
175
|
+
|
176
|
+
ami = connection.images.get(locate_config_value(:image))
|
177
|
+
|
178
|
+
server_def = {
|
179
|
+
:image_id => locate_config_value(:image),
|
180
|
+
:groups => config[:security_groups],
|
181
|
+
:flavor_id => locate_config_value(:flavor),
|
182
|
+
:key_name => Chef::Config[:knife][:openstack_ssh_key_id],
|
183
|
+
:availability_zone => Chef::Config[:knife][:availability_zone]
|
184
|
+
}
|
185
|
+
server_def[:subnet_id] = config[:subnet_id] if config[:subnet_id]
|
186
|
+
|
187
|
+
if ami.root_device_type == "ebs"
|
188
|
+
ami_map = ami.block_device_mapping.first
|
189
|
+
ebs_size = begin
|
190
|
+
if config[:ebs_size]
|
191
|
+
Integer(config[:ebs_size]).to_s
|
192
|
+
else
|
193
|
+
ami_map["volumeSize"].to_s
|
194
|
+
end
|
195
|
+
rescue ArgumentError
|
196
|
+
puts "--ebs-size must be an integer"
|
197
|
+
msg opt_parser
|
198
|
+
exit 1
|
199
|
+
end
|
200
|
+
delete_term = if config[:ebs_no_delete_on_term]
|
201
|
+
"false"
|
202
|
+
else
|
203
|
+
ami_map["deleteOnTermination"]
|
204
|
+
end
|
205
|
+
server_def[:block_device_mapping] =
|
206
|
+
[{
|
207
|
+
'DeviceName' => ami_map["deviceName"],
|
208
|
+
'Ebs.VolumeSize' => ebs_size,
|
209
|
+
'Ebs.DeleteOnTermination' => delete_term
|
210
|
+
}]
|
211
|
+
end
|
212
|
+
server = connection.servers.create(server_def)
|
213
|
+
|
214
|
+
puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
|
215
|
+
puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
|
216
|
+
puts "#{h.color("Image", :cyan)}: #{server.image_id}"
|
217
|
+
puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
|
218
|
+
puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
|
219
|
+
puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
|
220
|
+
|
221
|
+
print "\n#{h.color("Waiting for server", :magenta)}"
|
222
|
+
|
223
|
+
display_name = server.dns_name
|
224
|
+
|
225
|
+
# wait for it to be ready to do stuff
|
226
|
+
server.wait_for { print "."; ready? }
|
227
|
+
|
228
|
+
puts("\n")
|
229
|
+
|
230
|
+
puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
|
231
|
+
puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
|
232
|
+
puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
|
233
|
+
puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
|
234
|
+
|
235
|
+
print "\n#{h.color("Waiting for sshd", :magenta)}"
|
236
|
+
|
237
|
+
print(".") until tcp_test_ssh(display_name) {
|
238
|
+
sleep @initial_sleep_delay ||= 10
|
239
|
+
puts("done")
|
240
|
+
}
|
241
|
+
|
242
|
+
bootstrap_for_node(server).run
|
243
|
+
|
244
|
+
puts "\n"
|
245
|
+
puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
|
246
|
+
puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
|
247
|
+
puts "#{h.color("Image", :cyan)}: #{server.image_id}"
|
248
|
+
puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
|
249
|
+
puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
|
250
|
+
puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
|
251
|
+
puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
|
252
|
+
puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
|
253
|
+
puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
|
254
|
+
puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
|
255
|
+
puts "#{h.color("Run List", :cyan)}: #{@name_args.join(', ')}"
|
256
|
+
end
|
257
|
+
|
258
|
+
def bootstrap_for_node(server)
|
259
|
+
bootstrap = Chef::Knife::Bootstrap.new
|
260
|
+
bootstrap.name_args = [server.dns_name]
|
261
|
+
bootstrap.config[:run_list] = config[:run_list]
|
262
|
+
bootstrap.config[:ssh_user] = config[:ssh_user]
|
263
|
+
bootstrap.config[:identity_file] = config[:identity_file]
|
264
|
+
bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
|
265
|
+
bootstrap.config[:prerelease] = config[:prerelease]
|
266
|
+
bootstrap.config[:distro] = locate_config_value(:distro)
|
267
|
+
bootstrap.config[:use_sudo] = true
|
268
|
+
bootstrap.config[:template_file] = locate_config_value(:template_file)
|
269
|
+
bootstrap.config[:environment] = config[:environment]
|
270
|
+
# may be needed for vpc_mode
|
271
|
+
bootstrap.config[:no_host_key_verify] = config[:no_host_key_verify]
|
272
|
+
bootstrap
|
273
|
+
end
|
274
|
+
|
275
|
+
def locate_config_value(key)
|
276
|
+
key = key.to_sym
|
277
|
+
Chef::Config[:knife][key] || config[key]
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
@@ -0,0 +1,100 @@
|
|
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'
|
20
|
+
require 'chef/json_compat'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class OpenstackServerDelete < Knife
|
25
|
+
|
26
|
+
banner "knife openstack server delete SERVER [SERVER] (options)"
|
27
|
+
|
28
|
+
option :openstack_access_key_id,
|
29
|
+
:short => "-A ID",
|
30
|
+
:long => "--openstack-access-key-id KEY",
|
31
|
+
:description => "Your OpenStack Access Key ID",
|
32
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
|
33
|
+
|
34
|
+
option :openstack_secret_access_key,
|
35
|
+
:short => "-K SECRET",
|
36
|
+
:long => "--openstack-secret-access-key SECRET",
|
37
|
+
:description => "Your OpenStack API Secret Access Key",
|
38
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
|
39
|
+
|
40
|
+
option :openstack_api_endpoint,
|
41
|
+
:long => "--openstack-api-endpoint ENDPOINT",
|
42
|
+
:description => "Your OpenStack API endpoint",
|
43
|
+
:proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
|
44
|
+
|
45
|
+
option :region,
|
46
|
+
:long => "--region REGION",
|
47
|
+
:description => "Your OpenStack region",
|
48
|
+
:proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
|
49
|
+
|
50
|
+
def h
|
51
|
+
@highline ||= HighLine.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def run
|
55
|
+
require 'fog'
|
56
|
+
require 'highline'
|
57
|
+
require 'net/ssh/multi'
|
58
|
+
require 'readline'
|
59
|
+
|
60
|
+
connection = Fog::Compute.new(
|
61
|
+
:provider => 'AWS',
|
62
|
+
:aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
|
63
|
+
:aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
|
64
|
+
:endpoint => Chef::Config[:knife][:openstack_api_endpoint],
|
65
|
+
:region => Chef::Config[:knife][:region] || config[:region]
|
66
|
+
)
|
67
|
+
|
68
|
+
@name_args.each do |instance_id|
|
69
|
+
server = connection.servers.get(instance_id)
|
70
|
+
|
71
|
+
msg("Instance ID", server.id)
|
72
|
+
msg("Flavor", server.flavor_id)
|
73
|
+
msg("Image", server.image_id)
|
74
|
+
msg("Availability Zone", server.availability_zone)
|
75
|
+
msg("Security Groups", server.groups.join(", "))
|
76
|
+
msg("SSH Key", server.key_name)
|
77
|
+
msg("Public DNS Name", server.dns_name)
|
78
|
+
msg("Public IP Address", server.ip_address)
|
79
|
+
msg("Private DNS Name", server.private_dns_name)
|
80
|
+
msg("Private IP Address", server.private_ip_address)
|
81
|
+
|
82
|
+
puts "\n"
|
83
|
+
confirm("Do you really want to delete this server")
|
84
|
+
|
85
|
+
server.destroy
|
86
|
+
|
87
|
+
Chef::Log.warn("Deleted server #{server.id}")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def msg(label, value)
|
92
|
+
if value && !value.empty?
|
93
|
+
puts "#{h.color(label, :cyan)}: #{value}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
@@ -0,0 +1,95 @@
|
|
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'
|
20
|
+
require 'chef/json_compat'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class OpenstackServerList < Knife
|
25
|
+
|
26
|
+
banner "knife openstack server list (options)"
|
27
|
+
|
28
|
+
option :openstack_access_key_id,
|
29
|
+
:short => "-A ID",
|
30
|
+
:long => "--openstack-access-key-id KEY",
|
31
|
+
:description => "Your OpenStack Access Key ID",
|
32
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_access_key_id] = key }
|
33
|
+
|
34
|
+
option :openstack_secret_access_key,
|
35
|
+
:short => "-K SECRET",
|
36
|
+
:long => "--openstack-secret-access-key SECRET",
|
37
|
+
:description => "Your OpenStack API Secret Access Key",
|
38
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:openstack_secret_access_key] = key }
|
39
|
+
|
40
|
+
option :openstack_api_endpoint,
|
41
|
+
:long => "--openstack-api-endpoint ENDPOINT",
|
42
|
+
:description => "Your OpenStack API endpoint",
|
43
|
+
:proc => Proc.new { |endpoint| Chef::Config[:knife][:openstack_api_endpoint] = endpoint }
|
44
|
+
|
45
|
+
option :region,
|
46
|
+
:long => "--region REGION",
|
47
|
+
:description => "Your OpenStack region",
|
48
|
+
:proc => Proc.new { |region| Chef::Config[:knife][:region] = region }
|
49
|
+
|
50
|
+
def h
|
51
|
+
@highline ||= HighLine.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def run
|
55
|
+
require 'fog'
|
56
|
+
require 'highline'
|
57
|
+
require 'net/ssh/multi'
|
58
|
+
require 'readline'
|
59
|
+
|
60
|
+
$stdout.sync = true
|
61
|
+
|
62
|
+
connection = Fog::Compute.new(
|
63
|
+
:provider => 'AWS',
|
64
|
+
:aws_access_key_id => Chef::Config[:knife][:openstack_access_key_id],
|
65
|
+
:aws_secret_access_key => Chef::Config[:knife][:openstack_secret_access_key],
|
66
|
+
:endpoint => Chef::Config[:knife][:openstack_api_endpoint],
|
67
|
+
:region => Chef::Config[:knife][:region] || config[:region]
|
68
|
+
)
|
69
|
+
|
70
|
+
server_list = [
|
71
|
+
h.color('Instance ID', :bold),
|
72
|
+
h.color('Public IP', :bold),
|
73
|
+
h.color('Private IP', :bold),
|
74
|
+
h.color('Flavor', :bold),
|
75
|
+
h.color('Image', :bold),
|
76
|
+
h.color('Security Groups', :bold),
|
77
|
+
h.color('State', :bold)
|
78
|
+
]
|
79
|
+
connection.servers.all.each do |server|
|
80
|
+
server_list << server.id.to_s
|
81
|
+
server_list << (server.ip_address == nil ? "" : server.public_ip_address)
|
82
|
+
server_list << (server.private_ip_address == nil ? "" : server.private_ip_address)
|
83
|
+
server_list << (server.flavor_id == nil ? "" : server.flavor_id)
|
84
|
+
server_list << (server.image_id == nil ? "" : server.image_id)
|
85
|
+
server_list << server.groups.join(", ")
|
86
|
+
server_list << server.state
|
87
|
+
end
|
88
|
+
puts h.list(server_list, :columns_across, 7)
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-openstack
|
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-03-29 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: chef
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.9.14
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fog
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.6.0
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: net-ssh
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.1.3
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: net-ssh-multi
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.0.1
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: highline
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.1
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: *id005
|
71
|
+
description: OpenStack Compute Support for Chef's Knife Command
|
72
|
+
email:
|
73
|
+
- schisamo@opscode.com
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files:
|
79
|
+
- README.rdoc
|
80
|
+
- LICENSE
|
81
|
+
files:
|
82
|
+
- .gitignore
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE
|
85
|
+
- README.rdoc
|
86
|
+
- Rakefile
|
87
|
+
- knife-openstack.gemspec
|
88
|
+
- lib/chef/knife/openstack_flavor_list.rb
|
89
|
+
- lib/chef/knife/openstack_image_list.rb
|
90
|
+
- lib/chef/knife/openstack_server_create.rb
|
91
|
+
- lib/chef/knife/openstack_server_delete.rb
|
92
|
+
- lib/chef/knife/openstack_server_list.rb
|
93
|
+
- lib/knife-openstack/version.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: https://github.com/opscode/knife-openstack
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.6.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: OpenStack Compute Support for Chef's Knife Command
|
122
|
+
test_files: []
|
123
|
+
|