knife-hp 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +112 -0
- data/Rakefile +2 -0
- data/knife-hp.gemspec +25 -0
- data/lib/chef/knife/hp_base.rb +118 -0
- data/lib/chef/knife/hp_flavor_list.rb +51 -0
- data/lib/chef/knife/hp_image_list.rb +61 -0
- data/lib/chef/knife/hp_server_create.rb +275 -0
- data/lib/chef/knife/hp_server_delete.rb +110 -0
- data/lib/chef/knife/hp_server_list.rb +72 -0
- data/lib/knife-hp/version.rb +6 -0
- metadata +95 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# TODO #
|
2
|
+
This is a list of features currently lacking and (eventually) under development:
|
3
|
+
* filter out extraneous images from knife hp image list (requires HP metadata not yet available)
|
4
|
+
* should the node.name and node.id be the same (might have to fix this in the ohai plugin since this appears unavailable for setting)
|
5
|
+
* take either the flavor ID or the flavor name for server create
|
6
|
+
* take either the image ID or the image name for server create
|
7
|
+
* Virtual cpus to `hp flavor list`?
|
8
|
+
* Show the flavor and image names in `hp server list`
|
9
|
+
* Floating IPs are assigned on creation, but the public ip is incorrect
|
10
|
+
* Floating IPs are assigned on creation, support creating nodes without them (see knife-openstack's --private-network)
|
11
|
+
* Floating IPs are freed on node deletion, support not freeing them
|
12
|
+
* Re-assign a floating IPs on node creation
|
13
|
+
* Create the `hp` Ohai plugin (or re-use the `openstack` one) to key off of the /etc/chef/ohai/hints/hp.json file, pulling from the meta-data service.
|
14
|
+
* Validate ohai cloud support
|
15
|
+
|
16
|
+
## v0.2.0
|
17
|
+
* support for uneven_columns for prettier output
|
18
|
+
* added bootstrap-proxy support. (Matt Butcher)
|
19
|
+
* updated to point to Fog 1.4.0 for `HP` provider
|
20
|
+
* chef-full is now default bootstrap template
|
21
|
+
* Add support for floating IPs and address associating
|
22
|
+
* push the AZ stuff into the hints file
|
23
|
+
* Add support for `--no-host-key-verify`
|
24
|
+
* switched from hp_account_id to hp_access_key (Hugues Malphettes reported)
|
25
|
+
patch didn't make it into Fog 1.4, so reverted for now
|
26
|
+
* --purge (and --node-name) added for `knife hp server delete` to remove client and nodes
|
27
|
+
* Floating IPs are automatically disassociated on server delete
|
28
|
+
* Added /etc/chef/ohai/hints/hp.json for use by Ohai
|
29
|
+
|
30
|
+
## v0.1.0
|
31
|
+
* initial developer release
|
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.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
Knife HP
|
2
|
+
========
|
3
|
+
|
4
|
+
This is the official Opscode Knife plugin for HP Cloud Compute. This plugin gives knife the ability to create, bootstrap and manage instances in the HP Cloud.
|
5
|
+
|
6
|
+
Please refer to the CHANGELOG.md for version history.
|
7
|
+
|
8
|
+
# Installation #
|
9
|
+
|
10
|
+
Be sure you are running the latest version Chef. Versions earlier than 0.10.0 don't support plugins:
|
11
|
+
|
12
|
+
$ gem install chef
|
13
|
+
|
14
|
+
This plugin is distributed as a Ruby Gem. To install it, run:
|
15
|
+
|
16
|
+
$ gem install knife-hp
|
17
|
+
|
18
|
+
Depending on your system's configuration, you may need to run this command with root privileges.
|
19
|
+
|
20
|
+
# Configuration #
|
21
|
+
|
22
|
+
In order to communicate with HP Compute Cloud's API you will need to tell Knife the Access Key ID, the Secret Key and Tenant ID (found on the "API Keys" page). You may also override the auth URI and availability zone. The easiest way to accomplish this is to create these entries in your `knife.rb` file:
|
23
|
+
|
24
|
+
knife[:hp_account_id] = "Your HP Cloud Access Key ID"
|
25
|
+
knife[:hp_secret_key] = "Your HP Cloud Secret Key"
|
26
|
+
knife[:hp_tenant_id] = "Your HP Cloud Tenant ID"
|
27
|
+
knife[:hp_auth_uri] = "Your HP Cloud Auth URI" (optional, default is "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/")
|
28
|
+
knife[:hp_avl_zone] = "Your HP Cloud Availability Zone" (optional, default is "az1")
|
29
|
+
|
30
|
+
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:
|
31
|
+
|
32
|
+
knife[:hp_account_id] = "#{ENV['HP_ACCESS_KEY']}"
|
33
|
+
knife[:hp_secret_key] = "#{ENV['HP_SECRET_KEY']}"
|
34
|
+
knife[:hp_tenant_id] = "#{ENV['HP_TENANT_ID']}"
|
35
|
+
knife[:hp_auth_uri] = "#{ENV['HP_AUTH_URI']}"
|
36
|
+
knife[:hp_avl_zone] = "#{ENV['HP_AVL_ZONE']}"
|
37
|
+
|
38
|
+
You also have the option of passing your HP Cloud API options from the command line:
|
39
|
+
|
40
|
+
`-A` (or `--hp-account`) your HP Cloud Access Key ID
|
41
|
+
`-K` (or `--hp-secret`) your HP Cloud Secret Key
|
42
|
+
`-T` (or `--hp-tenant`) your HP Cloud Tenant ID
|
43
|
+
`--hp-auth` your HP Cloud Auth URI (optional, default is "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/")
|
44
|
+
`-Z` (or `--hp-zone`) your HP Cloud Availability Zone (optional, default is "az1")
|
45
|
+
|
46
|
+
knife hp server create -A 'MyUsername' -K 'MyPassword' -T 'MyTenant' -f 101 -I 120 -S hpkeypair -i ~/.ssh/hpkeypair.pem -r 'role[webserver]'
|
47
|
+
|
48
|
+
Additionally the following options may be set in your `knife.rb`:
|
49
|
+
|
50
|
+
* flavor
|
51
|
+
* image
|
52
|
+
* hp_ssh_key_id
|
53
|
+
* template_file
|
54
|
+
|
55
|
+
# Subcommands #
|
56
|
+
|
57
|
+
This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a `--help` flag
|
58
|
+
|
59
|
+
knife hp server create
|
60
|
+
----------------------
|
61
|
+
|
62
|
+
Provisions a new server in the HP 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 [chef-full](https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/chef-full.erb) template. This can be overridden using the `-d` or `--template-file` command options. If you do not pass a node name with `-N NAME` (or `--node-name NAME`) a name will be generated for the node. The default behavior for nodes created through HP's API are to be given an public floating address.
|
63
|
+
|
64
|
+
knife hp server create -f 101 -I 9883 -S hpkeypair -i ~/.ssh/hpkeypair.pem -Z az2 -x ubuntu
|
65
|
+
|
66
|
+
knife hp server delete
|
67
|
+
----------------------
|
68
|
+
|
69
|
+
Deletes an existing server in the currently configured HP Compute Cloud account. <b>PLEASE NOTE</b> - this does not delete the associated node and client objects from the Chef Server without using the `-P` or `--purge` option to purge the client. The floating address associated with the node is released on deletion.
|
70
|
+
|
71
|
+
knife hp server list
|
72
|
+
--------------------
|
73
|
+
|
74
|
+
Outputs a list of all servers in the currently configured HP 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.
|
75
|
+
|
76
|
+
knife hp flavor list
|
77
|
+
--------------------
|
78
|
+
|
79
|
+
Outputs a list of all available flavors (available hardware configuration for a server) available to the currently configured HP Compute Cloud account. Each flavor has a unique combination of virtual cores, disk space and memory capacity. This data can be useful when choosing a flavor id to pass to the `knife hp server create` subcommand.
|
80
|
+
|
81
|
+
knife hp image list
|
82
|
+
-------------------
|
83
|
+
|
84
|
+
Outputs a list of all available images available to the currently configured HP Compute Cloud account. An image is a collection of files used to create or rebuild a server. Currently the list returned is unfiltered and does not match the view on the dashboard, images with "(Kernel)" and "(Ramdisk)" are not intended for use bootstrapping. This data can be useful when choosing an image id to pass to the `knife hp server create` subcommand.
|
85
|
+
|
86
|
+
KNOWN ISSUES
|
87
|
+
============
|
88
|
+
There are a number of known issues waiting for upstream patches to be merged in Fog and added to Ohai. The CHANGELOG.md has more missing/incomplete features listed.
|
89
|
+
|
90
|
+
* az1 is currently unavailable via Fog. The default Availability Zone through the API is 'az3', even when specifying 'az1'. Yet 'az3' is unavailable as an selection option (https://github.com/fog/fog/pull/903). To work with az3, do not pass an Availability Zone at all. See also https://github.com/fog/fog/issues/1175
|
91
|
+
* The names of the HP Cloud Access Key ID should change from `hp_access_key` to `hp_account_id` to match HP's description https://github.com/fog/fog/pull/902
|
92
|
+
* There is no support in Ohai yet, but the empty `/etc/chef/ohai/hints/hp.json` is created. http://tickets.opscode.com/browse/OHAI-335
|
93
|
+
|
94
|
+
# License #
|
95
|
+
|
96
|
+
Author:: Matt Ray (<matt@opscode.com>)
|
97
|
+
|
98
|
+
Copyright:: Copyright (c) 2012 Opscode, Inc.
|
99
|
+
|
100
|
+
License:: Apache License, Version 2.0
|
101
|
+
|
102
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
103
|
+
you may not use this file except in compliance with the License.
|
104
|
+
You may obtain a copy of the License at
|
105
|
+
|
106
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
107
|
+
|
108
|
+
Unless required by applicable law or agreed to in writing, software
|
109
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
110
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
111
|
+
See the License for the specific language governing permissions and
|
112
|
+
limitations under the License.
|
data/Rakefile
ADDED
data/knife-hp.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "knife-hp/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "knife-hp"
|
7
|
+
s.version = Knife::Hp::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.extra_rdoc_files = ["README.md", "LICENSE" ]
|
11
|
+
s.authors = ["Matt Ray", "Adam Jacob"]
|
12
|
+
s.email = ["adam@opscode.com", "matt@opscode.com"]
|
13
|
+
s.homepage = "https://github.com/opscode/knife-hp"
|
14
|
+
s.summary = %q{HP Cloud Services Cloud 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 "fog", "~> 1.4"
|
23
|
+
s.add_dependency "chef", ">= 0.10.10"
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
module HpBase
|
24
|
+
|
25
|
+
# :nodoc:
|
26
|
+
# Would prefer to do this in a rational way, but can't be done b/c of
|
27
|
+
# Mixlib::CLI's design :(
|
28
|
+
def self.included(includer)
|
29
|
+
includer.class_eval do
|
30
|
+
|
31
|
+
deps do
|
32
|
+
require 'fog'
|
33
|
+
require 'readline'
|
34
|
+
require 'chef/json_compat'
|
35
|
+
end
|
36
|
+
|
37
|
+
option :hp_account_id,
|
38
|
+
:short => "-A ID",
|
39
|
+
:long => "--hp-account ID",
|
40
|
+
:description => "Your HP Cloud Access Key ID",
|
41
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:hp_account_id] = key }
|
42
|
+
|
43
|
+
option :hp_secret_key,
|
44
|
+
:short => "-K SECRET",
|
45
|
+
:long => "--hp-secret SECRET",
|
46
|
+
:description => "Your HP Cloud Secret Key",
|
47
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:hp_secret_key] = key }
|
48
|
+
|
49
|
+
option :hp_tenant_id,
|
50
|
+
:short => "-T ID",
|
51
|
+
:long => "--hp-tenant ID",
|
52
|
+
:description => "Your HP Cloud Tenant ID",
|
53
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:hp_tenant_id] = key }
|
54
|
+
|
55
|
+
option :hp_auth_uri,
|
56
|
+
:long => "--hp-auth URI",
|
57
|
+
:description => "Your HP Cloud Auth URI",
|
58
|
+
:default => "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/",
|
59
|
+
:proc => Proc.new { |endpoint| Chef::Config[:knife][:hp_auth_uri] = endpoint }
|
60
|
+
|
61
|
+
option :hp_avl_zone,
|
62
|
+
:short => "-Z Zone",
|
63
|
+
:long => "--hp-zone Zone",
|
64
|
+
:default => "az1",
|
65
|
+
:description => "Your HP Cloud Availability Zone (az1/az2)",
|
66
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:hp_avl_zone] = key }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def connection
|
71
|
+
Chef::Log.debug("hp_account_id: #{Chef::Config[:knife][:hp_account_id]}")
|
72
|
+
Chef::Log.debug("hp_secret_key: #{Chef::Config[:knife][:hp_secret_key]}")
|
73
|
+
Chef::Log.debug("hp_tenant_id: #{Chef::Config[:knife][:hp_tenant_id]}")
|
74
|
+
Chef::Log.debug("hp_auth_uri: #{locate_config_value(:hp_auth_uri)}")
|
75
|
+
Chef::Log.debug("hp_avl_zone: #{locate_config_value(:hp_avl_zone)}")
|
76
|
+
@connection ||= begin
|
77
|
+
connection = Fog::Compute.new(
|
78
|
+
:provider => 'HP',
|
79
|
+
:hp_account_id => Chef::Config[:knife][:hp_account_id],
|
80
|
+
:hp_secret_key => Chef::Config[:knife][:hp_secret_key],
|
81
|
+
:hp_tenant_id => Chef::Config[:knife][:hp_tenant_id],
|
82
|
+
:hp_auth_uri => locate_config_value(:hp_auth_uri),
|
83
|
+
:hp_avl_zone => locate_config_value(:hp_avl_zone).to_sym
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def locate_config_value(key)
|
89
|
+
key = key.to_sym
|
90
|
+
Chef::Config[:knife][key] || config[key]
|
91
|
+
end
|
92
|
+
|
93
|
+
def msg_pair(label, value, color=:cyan)
|
94
|
+
if value && !value.to_s.empty?
|
95
|
+
puts "#{ui.color(label, color)}: #{value}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def validate!(keys=[:hp_account_id, :hp_secret_key, :hp_tenant_id])
|
100
|
+
errors = []
|
101
|
+
|
102
|
+
keys.each do |k|
|
103
|
+
pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(hp)/i) ? w.upcase : w.capitalize }
|
104
|
+
if Chef::Config[:knife][k].nil?
|
105
|
+
errors << "You did not provided a valid '#{pretty_key}' value."
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
if errors.each{|e| ui.error(e)}.any?
|
110
|
+
exit 1
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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/hp_base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class HpFlavorList < Knife
|
24
|
+
|
25
|
+
include Knife::HpBase
|
26
|
+
|
27
|
+
banner "knife hp flavor list (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
|
31
|
+
validate!
|
32
|
+
|
33
|
+
flavor_list = [
|
34
|
+
ui.color('ID', :bold),
|
35
|
+
ui.color('Name', :bold),
|
36
|
+
ui.color('Cores', :bold),
|
37
|
+
ui.color('RAM', :bold),
|
38
|
+
ui.color('Disk', :bold),
|
39
|
+
]
|
40
|
+
connection.flavors.sort_by(&:id).each do |flavor|
|
41
|
+
flavor_list << flavor.id.to_s
|
42
|
+
flavor_list << flavor.name
|
43
|
+
flavor_list << flavor.cores.to_s
|
44
|
+
flavor_list << "#{flavor.ram.to_s} MB"
|
45
|
+
flavor_list << "#{flavor.disk.to_s} GB"
|
46
|
+
end
|
47
|
+
puts ui.list(flavor_list, :uneven_columns_across, 5)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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/hp_base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class HpImageList < Knife
|
24
|
+
|
25
|
+
include Knife::HpBase
|
26
|
+
|
27
|
+
banner "knife hp image list (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
|
31
|
+
validate!
|
32
|
+
|
33
|
+
image_list = [
|
34
|
+
ui.color('ID', :bold),
|
35
|
+
ui.color('Name', :bold),
|
36
|
+
# ui.color('Kernel ID', :bold),
|
37
|
+
# ui.color('Architecture', :bold),
|
38
|
+
# ui.color('Root Store', :bold),
|
39
|
+
# ui.color('Location', :bold)
|
40
|
+
]
|
41
|
+
|
42
|
+
connection.images.sort_by do |image|
|
43
|
+
[image.name.downcase, image.id].compact
|
44
|
+
end.each do |image|
|
45
|
+
image_list << image.id
|
46
|
+
image_list << image.name
|
47
|
+
# image_list << image.kernel_id
|
48
|
+
# image_list << image.architecture
|
49
|
+
# image_list << image.root_device_type
|
50
|
+
# image_list << image.location
|
51
|
+
end
|
52
|
+
|
53
|
+
image_list = image_list.map do |item|
|
54
|
+
item.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
puts ui.list(image_list, :uneven_columns_across, 2)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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/hp_base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class HpServerCreate < Knife
|
24
|
+
|
25
|
+
include Knife::HpBase
|
26
|
+
|
27
|
+
deps do
|
28
|
+
require 'fog'
|
29
|
+
require 'readline'
|
30
|
+
require 'chef/json_compat'
|
31
|
+
require 'chef/knife/bootstrap'
|
32
|
+
Chef::Knife::Bootstrap.load_deps
|
33
|
+
end
|
34
|
+
|
35
|
+
banner "knife hp server create (options)"
|
36
|
+
|
37
|
+
option :flavor,
|
38
|
+
:short => "-f FLAVOR_ID",
|
39
|
+
:long => "--flavor FLAVOR_ID",
|
40
|
+
:description => "The HP Cloud Size for the server",
|
41
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:flavor] = f }
|
42
|
+
|
43
|
+
option :image,
|
44
|
+
:short => "-I IMAGE_ID",
|
45
|
+
:long => "--image IMAGE_ID",
|
46
|
+
:description => "The HP Cloud Install Image ID for the server",
|
47
|
+
:proc => Proc.new { |i| Chef::Config[:knife][:image] = i }
|
48
|
+
|
49
|
+
option :security_groups,
|
50
|
+
:short => "-G X,Y,Z",
|
51
|
+
:long => "--groups X,Y,Z",
|
52
|
+
:description => "The HP Cloud Security Group(s) for this server",
|
53
|
+
:default => ["default"],
|
54
|
+
:proc => Proc.new { |groups| groups.split(',') }
|
55
|
+
|
56
|
+
option :ssh_key_name,
|
57
|
+
:short => "-S KEY",
|
58
|
+
:long => "--ssh-key KEY",
|
59
|
+
:description => "The HP Cloud Key Pair ID",
|
60
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:hp_ssh_key_id] = key }
|
61
|
+
|
62
|
+
option :chef_node_name,
|
63
|
+
:short => "-N NAME",
|
64
|
+
:long => "--node-name NAME",
|
65
|
+
:description => "The Chef node name for your new node"
|
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 :prerelease,
|
84
|
+
:long => "--prerelease",
|
85
|
+
:description => "Install the pre-release chef gems"
|
86
|
+
|
87
|
+
option :bootstrap_version,
|
88
|
+
:long => "--bootstrap-version VERSION",
|
89
|
+
:description => "The version of Chef to install",
|
90
|
+
:proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
|
91
|
+
|
92
|
+
option :bootstrap_proxy,
|
93
|
+
:long => "--bootstrap-proxy PROXY_URL",
|
94
|
+
:description => "The proxy server for the node being bootstrapped",
|
95
|
+
:proc => Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p }
|
96
|
+
|
97
|
+
option :distro,
|
98
|
+
:short => "-d DISTRO",
|
99
|
+
:long => "--distro DISTRO",
|
100
|
+
:description => "Bootstrap a distro using a template; default is 'chef-full'",
|
101
|
+
:proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
|
102
|
+
:default => "chef-full"
|
103
|
+
|
104
|
+
option :template_file,
|
105
|
+
:long => "--template-file TEMPLATE",
|
106
|
+
:description => "Full path to location of template to use",
|
107
|
+
:proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
|
108
|
+
:default => false
|
109
|
+
|
110
|
+
option :run_list,
|
111
|
+
:short => "-r RUN_LIST",
|
112
|
+
:long => "--run-list RUN_LIST",
|
113
|
+
:description => "Comma separated list of roles/recipes to apply",
|
114
|
+
:proc => lambda { |o| o.split(/[\s,]+/) },
|
115
|
+
:default => []
|
116
|
+
|
117
|
+
option :host_key_verify,
|
118
|
+
:long => "--[no-]host-key-verify",
|
119
|
+
:description => "Verify host key, enabled by default",
|
120
|
+
:boolean => true,
|
121
|
+
:default => true
|
122
|
+
|
123
|
+
def tcp_test_ssh(hostname)
|
124
|
+
tcp_socket = TCPSocket.new(hostname, 22)
|
125
|
+
readable = IO.select([tcp_socket], nil, nil, 5)
|
126
|
+
if readable
|
127
|
+
Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
|
128
|
+
yield
|
129
|
+
true
|
130
|
+
else
|
131
|
+
false
|
132
|
+
end
|
133
|
+
rescue Errno::ETIMEDOUT
|
134
|
+
false
|
135
|
+
rescue Errno::EPERM
|
136
|
+
false
|
137
|
+
rescue Errno::ECONNREFUSED
|
138
|
+
sleep 2
|
139
|
+
false
|
140
|
+
rescue Errno::EHOSTUNREACH
|
141
|
+
sleep 2
|
142
|
+
false
|
143
|
+
ensure
|
144
|
+
tcp_socket && tcp_socket.close
|
145
|
+
end
|
146
|
+
|
147
|
+
def run
|
148
|
+
$stdout.sync = true
|
149
|
+
|
150
|
+
validate!
|
151
|
+
|
152
|
+
connection = Fog::Compute.new(
|
153
|
+
:provider => 'HP',
|
154
|
+
:hp_account_id => Chef::Config[:knife][:hp_account_id],
|
155
|
+
:hp_secret_key => Chef::Config[:knife][:hp_secret_key],
|
156
|
+
:hp_tenant_id => Chef::Config[:knife][:hp_tenant_id],
|
157
|
+
:hp_auth_uri => locate_config_value(:hp_auth_uri),
|
158
|
+
:hp_avl_zone => locate_config_value(:hp_avl_zone).to_sym
|
159
|
+
)
|
160
|
+
|
161
|
+
#request and assign a floating IP for the server
|
162
|
+
address = connection.addresses.create()
|
163
|
+
Chef::Log.debug("Floating IP #{address.ip}")
|
164
|
+
|
165
|
+
#servers require a name, generate one if not passed
|
166
|
+
node_name = get_node_name(config[:chef_node_name], address.ip)
|
167
|
+
|
168
|
+
Chef::Log.debug("Name #{node_name}")
|
169
|
+
Chef::Log.debug("Flavor #{locate_config_value(:flavor)}")
|
170
|
+
Chef::Log.debug("Image #{locate_config_value(:image)}")
|
171
|
+
Chef::Log.debug("Group(s) #{config[:security_groups]}")
|
172
|
+
Chef::Log.debug("Key Pair #{Chef::Config[:knife][:hp_ssh_key_id]}")
|
173
|
+
|
174
|
+
server_def = {
|
175
|
+
:name => node_name,
|
176
|
+
:flavor_id => locate_config_value(:flavor),
|
177
|
+
:image_id => locate_config_value(:image),
|
178
|
+
:security_groups => config[:security_groups],
|
179
|
+
:key_name => Chef::Config[:knife][:hp_ssh_key_id],
|
180
|
+
:personality => [{
|
181
|
+
"path" => "/etc/chef/ohai/hints/hp.json",
|
182
|
+
"contents" => ''
|
183
|
+
}]
|
184
|
+
}
|
185
|
+
|
186
|
+
server = connection.servers.create(server_def)
|
187
|
+
|
188
|
+
msg_pair("Instance ID", server.id)
|
189
|
+
msg_pair("Instance Name", server.name)
|
190
|
+
msg_pair("Flavor", server.flavor['id'])
|
191
|
+
msg_pair("Image", server.image['id'])
|
192
|
+
#msg_pair("Security Group(s)", server.security_groups.join(", "))
|
193
|
+
msg_pair("SSH Key Pair", server.key_name)
|
194
|
+
|
195
|
+
print "\n#{ui.color("Waiting for server", :magenta)}"
|
196
|
+
|
197
|
+
# wait for it to be ready to do stuff
|
198
|
+
server.wait_for { print "."; ready? }
|
199
|
+
|
200
|
+
address.server = server
|
201
|
+
|
202
|
+
server.wait_for { print "."; ready? }
|
203
|
+
|
204
|
+
puts("\n")
|
205
|
+
|
206
|
+
msg_pair("Public IP Address", server.public_ip_address)
|
207
|
+
msg_pair("Private IP Address", server.private_ip_address)
|
208
|
+
|
209
|
+
print "\n#{ui.color("Waiting for sshd", :magenta)}"
|
210
|
+
|
211
|
+
#hack to ensure the nodes have had time to spin up
|
212
|
+
print(".")
|
213
|
+
sleep 30
|
214
|
+
print(".")
|
215
|
+
|
216
|
+
print(".") until tcp_test_ssh(server.public_ip_address) {
|
217
|
+
sleep @initial_sleep_delay ||= 10
|
218
|
+
puts("done")
|
219
|
+
}
|
220
|
+
|
221
|
+
bootstrap_for_node(server).run
|
222
|
+
|
223
|
+
puts "\n"
|
224
|
+
msg_pair("Instance ID", server.id)
|
225
|
+
msg_pair("Instance Name", server.name)
|
226
|
+
msg_pair("Flavor", server.flavor['id'])
|
227
|
+
msg_pair("Image", server.image['id'])
|
228
|
+
#msg_pair("Security Group(s)", server.security_groups.join(", "))
|
229
|
+
msg_pair("SSH Key Pair", server.key_name)
|
230
|
+
msg_pair("Public IP Address", server.public_ip_address)
|
231
|
+
msg_pair("Private IP Address", server.private_ip_address)
|
232
|
+
msg_pair("Environment", config[:environment] || '_default')
|
233
|
+
msg_pair("Run List", config[:run_list].join(', '))
|
234
|
+
end
|
235
|
+
|
236
|
+
def bootstrap_for_node(server)
|
237
|
+
bootstrap = Chef::Knife::Bootstrap.new
|
238
|
+
bootstrap.name_args = [server.public_ip_address]
|
239
|
+
bootstrap.config[:run_list] = config[:run_list]
|
240
|
+
bootstrap.config[:ssh_user] = config[:ssh_user]
|
241
|
+
bootstrap.config[:identity_file] = config[:identity_file]
|
242
|
+
bootstrap.config[:host_key_verify] = config[:host_key_verify]
|
243
|
+
bootstrap.config[:chef_node_name] = server.name
|
244
|
+
bootstrap.config[:prerelease] = config[:prerelease]
|
245
|
+
bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version)
|
246
|
+
bootstrap.config[:bootstrap_proxy] = locate_config_value(:bootstrap_proxy)
|
247
|
+
bootstrap.config[:distro] = locate_config_value(:distro)
|
248
|
+
bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root'
|
249
|
+
bootstrap.config[:template_file] = locate_config_value(:template_file)
|
250
|
+
bootstrap.config[:environment] = config[:environment]
|
251
|
+
bootstrap
|
252
|
+
end
|
253
|
+
|
254
|
+
def ami
|
255
|
+
@ami ||= connection.images.get(locate_config_value(:image))
|
256
|
+
end
|
257
|
+
|
258
|
+
def validate!
|
259
|
+
|
260
|
+
super([:image, :flavor, :hp_account_id, :hp_secret_key, :hp_tenant_id])
|
261
|
+
|
262
|
+
if ami.nil?
|
263
|
+
ui.error("You have not provided a valid image ID. Please note the short option for this value recently changed from '-i' to '-I'.")
|
264
|
+
exit 1
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
#generate a name from the IP if chef_node_name is empty
|
269
|
+
def get_node_name(chef_node_name, ipaddress)
|
270
|
+
return chef_node_name unless chef_node_name.nil?
|
271
|
+
chef_node_name = "hp"+ipaddress.gsub(/\./,'-')
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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/hp_base'
|
20
|
+
|
21
|
+
# These two are needed for the '--purge' deletion case
|
22
|
+
require 'chef/node'
|
23
|
+
require 'chef/api_client'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
class HpServerDelete < Knife
|
28
|
+
|
29
|
+
include Knife::HpBase
|
30
|
+
|
31
|
+
banner "knife hp server delete SERVER [SERVER] (options)"
|
32
|
+
|
33
|
+
option :purge,
|
34
|
+
:short => "-P",
|
35
|
+
:long => "--purge",
|
36
|
+
:boolean => true,
|
37
|
+
:default => false,
|
38
|
+
:description => "Destroy corresponding node and client on the Chef Server, in addition to destroying the HP node itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
|
39
|
+
|
40
|
+
option :chef_node_name,
|
41
|
+
:short => "-N NAME",
|
42
|
+
:long => "--node-name NAME",
|
43
|
+
:description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
|
44
|
+
|
45
|
+
# Extracted from Chef::Knife.delete_object, because it has a
|
46
|
+
# confirmation step built in... By specifying the '--purge'
|
47
|
+
# flag (and also explicitly confirming the server destruction!)
|
48
|
+
# the user is already making their intent known. It is not
|
49
|
+
# necessary to make them confirm two more times.
|
50
|
+
def destroy_item(klass, name, type_name)
|
51
|
+
begin
|
52
|
+
object = klass.load(name)
|
53
|
+
object.destroy
|
54
|
+
ui.warn("Deleted #{type_name} #{name}")
|
55
|
+
rescue Net::HTTPServerException
|
56
|
+
ui.warn("Could not find a #{type_name} named #{name} to delete!")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def run
|
61
|
+
|
62
|
+
validate!
|
63
|
+
|
64
|
+
@name_args.each do |instance_id|
|
65
|
+
begin
|
66
|
+
server = connection.servers.get(instance_id)
|
67
|
+
addresses = connection.addresses
|
68
|
+
|
69
|
+
msg_pair("Instance ID", server.id)
|
70
|
+
msg_pair("Instance Name", server.name)
|
71
|
+
msg_pair("Flavor", server.flavor['id'])
|
72
|
+
msg_pair("Image", server.image['id'])
|
73
|
+
msg_pair("Public IP Address", server.public_ip_address)
|
74
|
+
msg_pair("Private IP Address", server.private_ip_address)
|
75
|
+
|
76
|
+
puts "\n"
|
77
|
+
confirm("Do you really want to delete this server")
|
78
|
+
|
79
|
+
server.destroy
|
80
|
+
|
81
|
+
#HP doesn't free allocated IPs when servers are deleted
|
82
|
+
#if the address is a floating, it's the first entry in the private addresses(?)
|
83
|
+
float = server.addresses['private'][0]['addr']
|
84
|
+
Chef::Log.debug("hp_server_delete: float:#{float}")
|
85
|
+
addresses.each do |address|
|
86
|
+
if !(address.fixed_ip.nil?) && (address.fixed_ip == float)
|
87
|
+
msg_pair("Deleted Floating IP Address", float)
|
88
|
+
address.destroy
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
ui.warn("Deleted server #{server.id}")
|
93
|
+
|
94
|
+
if config[:purge]
|
95
|
+
thing_to_delete = config[:chef_node_name] || instance_id
|
96
|
+
destroy_item(Chef::Node, thing_to_delete, "node")
|
97
|
+
destroy_item(Chef::ApiClient, thing_to_delete, "client")
|
98
|
+
else
|
99
|
+
ui.warn("Corresponding node and client for the #{instance_id} server were not deleted and remain registered with the Chef Server")
|
100
|
+
end
|
101
|
+
|
102
|
+
rescue NoMethodError
|
103
|
+
ui.error("Could not locate server '#{instance_id}'.")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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/hp_base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class HpServerList < Knife
|
24
|
+
|
25
|
+
include Knife::HpBase
|
26
|
+
|
27
|
+
banner "knife hp server list (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
$stdout.sync = true
|
31
|
+
|
32
|
+
validate!
|
33
|
+
|
34
|
+
server_list = [
|
35
|
+
ui.color('Instance ID', :bold),
|
36
|
+
ui.color('Name', :bold),
|
37
|
+
ui.color('Public IP', :bold),
|
38
|
+
ui.color('Private IP', :bold),
|
39
|
+
ui.color('Flavor', :bold),
|
40
|
+
ui.color('Image', :bold),
|
41
|
+
ui.color('Key Pair', :bold),
|
42
|
+
ui.color('State', :bold)
|
43
|
+
]
|
44
|
+
connection.servers.all.sort_by(&:id).each do |server|
|
45
|
+
Chef::Log.debug("Server: #{server.to_yaml}")
|
46
|
+
server_list << server.id.to_s
|
47
|
+
server_list << server.name
|
48
|
+
server_list << (server.public_ip_address or "")
|
49
|
+
server_list << (server.private_ip_address or "")
|
50
|
+
server_list << server.flavor['id'].to_s
|
51
|
+
server_list << server.image['id'].to_s
|
52
|
+
server_list << (server.key_name or "")
|
53
|
+
server_list << begin
|
54
|
+
state = server.state.to_s.downcase
|
55
|
+
case state
|
56
|
+
when 'shutting-down','terminated','stopping','stopped','active(deleting)','build(deleting)'
|
57
|
+
ui.color(state, :red)
|
58
|
+
when 'pending','build(scheduling)','build(spawning)','build(networking)'
|
59
|
+
ui.color(state, :yellow)
|
60
|
+
else
|
61
|
+
ui.color(state, :green)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
puts ui.list(server_list, :uneven_columns_across, 8)
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-hp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Ray
|
9
|
+
- Adam Jacob
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fog
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.4'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.4'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: chef
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.10.10
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.10.10
|
47
|
+
description: HP Cloud Services Cloud support for Chef's Knife command
|
48
|
+
email:
|
49
|
+
- adam@opscode.com
|
50
|
+
- matt@opscode.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files:
|
54
|
+
- README.md
|
55
|
+
- LICENSE
|
56
|
+
files:
|
57
|
+
- .gitignore
|
58
|
+
- CHANGELOG.md
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- knife-hp.gemspec
|
64
|
+
- lib/chef/knife/hp_base.rb
|
65
|
+
- lib/chef/knife/hp_flavor_list.rb
|
66
|
+
- lib/chef/knife/hp_image_list.rb
|
67
|
+
- lib/chef/knife/hp_server_create.rb
|
68
|
+
- lib/chef/knife/hp_server_delete.rb
|
69
|
+
- lib/chef/knife/hp_server_list.rb
|
70
|
+
- lib/knife-hp/version.rb
|
71
|
+
homepage: https://github.com/opscode/knife-hp
|
72
|
+
licenses: []
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.24
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: HP Cloud Services Cloud support for Chef's Knife command
|
95
|
+
test_files: []
|