knife-oca 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/LICENSE +201 -0
- data/README.rdoc +271 -0
- data/knife-oca.gemspec +24 -0
- data/lib/chef/knife/oca_base.rb +99 -0
- data/lib/chef/knife/oca_server_delete.rb +105 -0
- data/lib/chef/knife/oca_server_list.rb +76 -0
- data/lib/chef/knife/oca_template_instantiate.rb +334 -0
- data/lib/chef/knife/oca_template_list.rb +54 -0
- data/lib/knife-oca/version.rb +6 -0
- metadata +89 -0
data/.gitignore
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,271 @@
|
|
1
|
+
= knife-oca
|
2
|
+
|
3
|
+
Knife plugin for OCA (OpenNebula Cloud API)
|
4
|
+
|
5
|
+
== Requirements
|
6
|
+
|
7
|
+
* The oca gem is needed for oca provider in fog.
|
8
|
+
* The net-scp is optional and needed if you use 'knife oca template instantiate' with the '--is-chef-server' option.
|
9
|
+
|
10
|
+
gem install oca net-scp
|
11
|
+
|
12
|
+
1. Clone the official <tt>fog</tt> gem source (and checkout version 1.5.0):
|
13
|
+
2. Checkout <tt>eaaf335870436499fe61c62fe42f44cd9e1584d0</tt> (it's a dev commit after 1.5.0 release, you might want to skip this step if you know what you are doing :) )
|
14
|
+
3. Install <tt>fog</tt> merged with my oca branch: <tt>https://github.com/Reverand221/fog/tree/oca</tt>
|
15
|
+
4. Pull my fog oca provider
|
16
|
+
5. Build the <tt>fog</tt> gem
|
17
|
+
6. Install the <tt>fog</tt> gem
|
18
|
+
|
19
|
+
git clone git://github.com/fog/fog.git
|
20
|
+
cd fog
|
21
|
+
git checkout eaaf335870436499fe61c62fe42f44cd9e1584d0
|
22
|
+
git remote add fog-oca git://github.com/Reverand221/fog.git
|
23
|
+
git pull fog-oca oca
|
24
|
+
gem build fog.gemspec
|
25
|
+
gem install fog-1.5.0.gem
|
26
|
+
|
27
|
+
== Assumptions
|
28
|
+
|
29
|
+
* You have a OpenNebula 3.2+ private cloud instance running and its XML-RPC endpoint visible from your workstation.
|
30
|
+
* You have two types of Virtual Machine Images prepared and uploaded to your OpenNebula cloud as templates:
|
31
|
+
* chef-server: A *nix installation with a chef server and a ssh daemon preinstalled and setup to start operation on VM boot.
|
32
|
+
* naked: Some basic *nix installation with a ssh daemon preinstalled and setup to start operation on VM boot.
|
33
|
+
* The VM IP Adresses have DNS names and are registered in the reverse domain.
|
34
|
+
|
35
|
+
== Installation
|
36
|
+
|
37
|
+
See requirements above !!!
|
38
|
+
|
39
|
+
gem install knife-oca
|
40
|
+
|
41
|
+
== Usage Example
|
42
|
+
|
43
|
+
Setup a directory structure as following:
|
44
|
+
|
45
|
+
demo
|
46
|
+
|-- cookbooks
|
47
|
+
|-- knife.rb
|
48
|
+
|-- roles
|
49
|
+
|
50
|
+
Put your cookbooks and roles into the corresponding subdirectories.
|
51
|
+
|
52
|
+
The knife.rb file should contain the following:
|
53
|
+
|
54
|
+
oca_one_auth 'user:passwd'
|
55
|
+
oca_xml_rpc_endpoint 'http://frontend.opennebula.example:2633/RPC2'
|
56
|
+
ssh_password 'sshP4Ssw0Rd'
|
57
|
+
ssh_user 'sshuser'
|
58
|
+
|
59
|
+
The values should be replaced with the credentials to your OpenNebula cloud frontend and the ssh daemons on your VMs.
|
60
|
+
|
61
|
+
> knife oca template list
|
62
|
+
ID Name Architecture CPUs Memory
|
63
|
+
11 debian64-6.0.5-chef-server-10.12 x86_64 2 5632
|
64
|
+
12 debian64-6.0.5-naked x86_64 1 2816
|
65
|
+
|
66
|
+
Instantiate a Chef server. Template No 11 has a preinstalled chef server which starts operation on bootup.
|
67
|
+
|
68
|
+
> knife oca template instantiate 11 --is-chef-server
|
69
|
+
Instance ID: 175
|
70
|
+
Template: debian64-6.0.5-chef-server-10.12
|
71
|
+
# CPUs: 2
|
72
|
+
Memory: 5632
|
73
|
+
Architecture: x86_64
|
74
|
+
|
75
|
+
Waiting for server.............................................................done
|
76
|
+
Public DNS Name: vm-0059.cloud.example.com
|
77
|
+
Public IP Address: 10.17.0.89
|
78
|
+
|
79
|
+
Waiting for sshd......done
|
80
|
+
Downloading file vm-0059.cloud.example.com:/etc/chef/validation.pem to /demo ...
|
81
|
+
Downloading file vm-0059.cloud.example.com:/etc/chef/webui.pem to /demo ...
|
82
|
+
done
|
83
|
+
Creating initial API user...
|
84
|
+
Created client[someuser]
|
85
|
+
Configuration file written to /demo/knife.rb
|
86
|
+
|
87
|
+
Instance ID: 175
|
88
|
+
Template: debian64-6.0.5-chef-server-10.12
|
89
|
+
# CPUs: 2
|
90
|
+
Memory: 5632
|
91
|
+
Architecture: x86_64
|
92
|
+
Public DNS Name: vm-0059.cloud.example.com
|
93
|
+
Public IP Address: 10.17.0.89
|
94
|
+
Environment: _default
|
95
|
+
|
96
|
+
Knife config generated: /demo/knife.rb
|
97
|
+
|
98
|
+
This command launched the chef server template and fully configured our workstation knife for the use with this new chef server. Let's have a look into the <tt>knife.rb</tt> file:
|
99
|
+
|
100
|
+
log_level :info
|
101
|
+
log_location STDOUT
|
102
|
+
node_name 'someuser'
|
103
|
+
client_key '/demo/someuser.pem'
|
104
|
+
validation_client_name 'chef-validator'
|
105
|
+
validation_key '/demo/validation.pem'
|
106
|
+
chef_server_url 'https://vm-0059.cloud.example.com:443'
|
107
|
+
cache_type 'BasicFile'
|
108
|
+
cache_options( :path => '/demo/checksums' )
|
109
|
+
cookbook_path [ '/demo/cookbooks' ]
|
110
|
+
|
111
|
+
oca_one_auth 'user:passwd'
|
112
|
+
oca_xml_rpc_endpoint 'http://frontend.opennebula.example:2633/RPC2'
|
113
|
+
ssh_password 'sshP4Ssw0Rd'
|
114
|
+
ssh_user 'sshuser'
|
115
|
+
|
116
|
+
A <tt>knife status</tt> will show the chef server node itself if you are running a <tt>chef-client</tt>.
|
117
|
+
|
118
|
+
> knife status
|
119
|
+
8 minutes ago, vm-0059.cloud.example.com, vm-0059.cloud.example.com, 10.17.0.89, debian 6.0.5.
|
120
|
+
|
121
|
+
<tt>knife oca server list</tt> will list the corresponding virtual machines in OpenNebula.
|
122
|
+
|
123
|
+
> knife oca server list
|
124
|
+
ID Public IP Public DNS Name State CPUs Memory Template
|
125
|
+
175 10.17.0.89 vm-0059.cloud.example.com runn 2 5632 debian64-6.0.5-chef-server-10.12
|
126
|
+
|
127
|
+
You can upload your cookbooks and roles now with <tt>knife cookbook upload</tt> and <tt>knife role from file</tt>.
|
128
|
+
|
129
|
+
Now we want to launch naked VMs and bootstrap them with a chef-client. Optionally you can directly pass a run list with the command, e.g. <tt>knife oca template instantiate 12 --run-list 'role[samplerole]'</tt>
|
130
|
+
|
131
|
+
> knife oca template instantiate 12
|
132
|
+
Instance ID: 176
|
133
|
+
Template: debian64-6.0.5-naked
|
134
|
+
# CPUs: 1
|
135
|
+
Memory: 2816
|
136
|
+
Architecture: x86_64
|
137
|
+
|
138
|
+
Waiting for server...............................done
|
139
|
+
Public DNS Name: vm-005a.cloud.example.com
|
140
|
+
Public IP Address: 10.17.0.90
|
141
|
+
|
142
|
+
Waiting for sshd.....done
|
143
|
+
Bootstrapping Chef on vm-005a.cloud.example.com
|
144
|
+
vm-005a.cloud.example.com --2012-09-11 16:56:46-- http://opscode.com/chef/install.sh
|
145
|
+
vm-005a.cloud.example.com Resolving opscode.com...
|
146
|
+
vm-005a.cloud.example.com 184.106.28.82
|
147
|
+
vm-005a.cloud.example.com Connecting to opscode.com|184.106.28.82|:80...
|
148
|
+
vm-005a.cloud.example.com connected.
|
149
|
+
vm-005a.cloud.example.com HTTP request sent, awaiting response...
|
150
|
+
vm-005a.cloud.example.com 301 Moved Permanently
|
151
|
+
vm-005a.cloud.example.com Location: http://www.opscode.com/chef/install.sh [following]
|
152
|
+
vm-005a.cloud.example.com --2012-09-11 16:56:51-- http://www.opscode.com/chef/install.sh
|
153
|
+
vm-005a.cloud.example.com Resolving www.opscode.com...
|
154
|
+
vm-005a.cloud.example.com 184.106.28.82
|
155
|
+
vm-005a.cloud.example.com Reusing existing connection to opscode.com:80.
|
156
|
+
vm-005a.cloud.example.com HTTP request sent, awaiting response...
|
157
|
+
vm-005a.cloud.example.com 200 OK
|
158
|
+
vm-005a.cloud.example.com Length: 5801 (5.7K) [application/x-sh]
|
159
|
+
vm-005a.cloud.example.com Saving to: “STDOUT”
|
160
|
+
vm-005a.cloud.example.com
|
161
|
+
0% [ ] 0 --.-K/s
|
162
|
+
100%[======================================>] 5,801 --.-K/s in 0.1s
|
163
|
+
vm-005a.cloud.example.com
|
164
|
+
vm-005a.cloud.example.com 2012-09-11 16:56:57 (51.8 KB/s) - written to stdout [5801/5801]
|
165
|
+
vm-005a.cloud.example.com
|
166
|
+
vm-005a.cloud.example.com Downloading Chef 10.12.0 for debian...
|
167
|
+
vm-005a.cloud.example.com Installing Chef 10.12.0
|
168
|
+
vm-005a.cloud.example.com Selecting previously deselected package chef.
|
169
|
+
vm-005a.cloud.example.com (Reading database ...
|
170
|
+
(Reading database ... 65%
|
171
|
+
(Reading database ... 70%
|
172
|
+
(Reading database ... 75%
|
173
|
+
(Reading database ... 80%
|
174
|
+
(Reading database ... 85%
|
175
|
+
(Reading database ... 90%
|
176
|
+
(Reading database ... 95%
|
177
|
+
(Reading database ... 22593 files and directories currently installed.)
|
178
|
+
vm-005a.cloud.example.com Unpacking chef (from /tmp/chef_10.12.0_amd64.deb) ...
|
179
|
+
vm-005a.cloud.example.com Setting up chef (10.12.0-1.debian.6.0.4) ...
|
180
|
+
vm-005a.cloud.example.com Thank you for installing Chef!
|
181
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:43 +0200] INFO: *** Chef 10.12.0 ***
|
182
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:45 +0200] INFO: Client key /etc/chef/client.pem is not present - registering
|
183
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: HTTP Request Returned 404 Not Found: Cannot load node vm-005a.cloud.example.com
|
184
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Setting the run_list to [] from JSON
|
185
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Run List is []
|
186
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Run List expands to []
|
187
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Starting Chef Run for vm-005a.cloud.example.com
|
188
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Running start handlers
|
189
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Start handlers complete.
|
190
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Loading cookbooks []
|
191
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] WARN: Node vm-005a.cloud.example.com has an empty run list.
|
192
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Chef Run complete in 0.3328068 seconds
|
193
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Running report handlers
|
194
|
+
vm-005a.cloud.example.com [Tue, 11 Sep 2012 16:57:46 +0200] INFO: Report handlers complete
|
195
|
+
|
196
|
+
Instance ID: 176
|
197
|
+
Template: debian64-6.0.5-naked
|
198
|
+
# CPUs: 1
|
199
|
+
Memory: 2816
|
200
|
+
Architecture: x86_64
|
201
|
+
Public DNS Name: vm-005a.cloud.example.com
|
202
|
+
Public IP Address: 10.17.0.90
|
203
|
+
Environment: _default
|
204
|
+
|
205
|
+
The new node will be registered with the chef server
|
206
|
+
|
207
|
+
> knife status
|
208
|
+
25 minutes ago, vm-0059.cloud.example.com, vm-0059.cloud.example.com, 10.17.0.89, debian 6.0.5.
|
209
|
+
11 minutes ago, vm-005a.cloud.example.com, vm-005a.cloud.example.com, 10.17.0.90, debian 6.0.5.
|
210
|
+
|
211
|
+
and with OpenNebula.
|
212
|
+
|
213
|
+
> knife oca server list
|
214
|
+
ID Public IP Public DNS Name State CPUs Memory Template
|
215
|
+
175 10.17.0.89 vm-0059.cloud.example.com runn 2 5632 debian64-6.0.5-chef-server-10.12
|
216
|
+
176 10.17.0.90 vm-005a.cloud.example.com runn 1 2816 debian64-6.0.5-naked
|
217
|
+
|
218
|
+
We might decide to delete a node eventually. <tt>--purge</tt> will delete the node also on the chef server::
|
219
|
+
|
220
|
+
> knife oca server delete 176 --purge -y
|
221
|
+
ID: 176
|
222
|
+
Public IP: 10.17.0.90
|
223
|
+
Public DNS Name: vm-005a.cloud.example.com
|
224
|
+
Template: debian64-6.0.5-naked
|
225
|
+
|
226
|
+
WARNING: Deleted server 176
|
227
|
+
WARNING: Deleted node vm-005a.cloud.example.com
|
228
|
+
WARNING: Deleted client vm-005a.cloud.example.com
|
229
|
+
|
230
|
+
> knife status
|
231
|
+
29 minutes ago, vm-0059.cloud.example.com, vm-0059.cloud.example.com, 10.17.0.89, debian 6.0.5.
|
232
|
+
|
233
|
+
> knife oca server list
|
234
|
+
ID Public IP Public DNS Name State CPUs Memory Template
|
235
|
+
175 10.17.0.89 vm-0059.cloud.example.com runn 2 5632 debian64-6.0.5-chef-server-10.12
|
236
|
+
|
237
|
+
== Reference Documentation
|
238
|
+
|
239
|
+
[knife oca server list]
|
240
|
+
|
241
|
+
[knife oca server delete ID [ID ...]] <tt>--purge</tt> to delete node on chef server too
|
242
|
+
|
243
|
+
[knife oca template list]
|
244
|
+
|
245
|
+
[knife oca template instantiate ID] <tt>--is-chef-server</tt> to not bootstrap and configure knife
|
246
|
+
<tt>--run-list</tt> to supply the initial run list
|
247
|
+
|
248
|
+
In-depth documentation of all the available options can be listed by appending --help to the above commands.
|
249
|
+
|
250
|
+
== License
|
251
|
+
|
252
|
+
# Author:: Dennis Klein (<d.klein@gsi.de>)
|
253
|
+
# Copyright:: Copyright (c) 2012 GSI Helmholtz Centre for Heavy Ion Research.
|
254
|
+
#
|
255
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
256
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
257
|
+
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
258
|
+
#
|
259
|
+
# License:: Apache License, Version 2.0
|
260
|
+
#
|
261
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
262
|
+
# you may not use this file except in compliance with the License.
|
263
|
+
# You may obtain a copy of the License at
|
264
|
+
#
|
265
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
266
|
+
#
|
267
|
+
# Unless required by applicable law or agreed to in writing, software
|
268
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
269
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
270
|
+
# See the License for the specific language governing permissions and
|
271
|
+
# limitations under the License.
|
data/knife-oca.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "knife-oca/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "knife-oca"
|
7
|
+
s.version = Knife::OCA::VERSION
|
8
|
+
s.has_rdoc = true
|
9
|
+
s.authors = ["Dennis Klein"]
|
10
|
+
s.email = ["d.klein@gsi.de"]
|
11
|
+
s.homepage = "http://www.github.com/Reverand221/knife-oca"
|
12
|
+
s.summary = "OCA Support for Chef's Knife Command"
|
13
|
+
s.description = s.summary
|
14
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
# s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.add_dependency "fog", "~> 1.3"
|
20
|
+
s.add_dependency "chef", ">= 0.10.10"
|
21
|
+
# %w(rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem }
|
22
|
+
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Dennis Klein (<d.klein@gsi.de>)
|
3
|
+
# Copyright:: Copyright (c) 2012 GSI Helmholtz Centre for Heavy Ion Research.
|
4
|
+
#
|
5
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
6
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
7
|
+
# License:: Apache License, Version 2.0
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'chef/knife'
|
23
|
+
require 'resolv'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
module OcaBase
|
28
|
+
|
29
|
+
# :nodoc:
|
30
|
+
# Would prefer to do this in a rational way, but can't be done b/c of
|
31
|
+
# Mixlib::CLI's design :(
|
32
|
+
def self.included(includer)
|
33
|
+
includer.class_eval do
|
34
|
+
|
35
|
+
deps do
|
36
|
+
require 'fog'
|
37
|
+
require 'readline'
|
38
|
+
require 'chef/json_compat'
|
39
|
+
end
|
40
|
+
|
41
|
+
option :oca_one_auth,
|
42
|
+
:short => "-K ONE_AUTH",
|
43
|
+
:long => "--oca-one-auth ONE_AUTH",
|
44
|
+
:description => "Your OCA OpenNebula username:password credentials",
|
45
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:oca_one_auth] = key }
|
46
|
+
|
47
|
+
option :oca_xml_rpc_endpoint,
|
48
|
+
:short => "-C ENDPOINT",
|
49
|
+
:long => "--oca-xml-rpc-endpoint ENDPOINT",
|
50
|
+
:description => "Your OCA OpenNebula XML-RPC endpoint, e.g. http://host:port/RPC2",
|
51
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:oca_xml_rpc_endpoint] = key }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def connection
|
56
|
+
@connection ||= begin
|
57
|
+
connection = Fog::Compute.new(
|
58
|
+
:provider => 'oca',
|
59
|
+
:oca_one_auth => Chef::Config[:oca_one_auth],
|
60
|
+
:oca_xml_rpc_endpoint => Chef::Config[:oca_xml_rpc_endpoint],
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def locate_config_value(key)
|
66
|
+
key = key.to_sym
|
67
|
+
config[key] || Chef::Config[:knife][key]
|
68
|
+
end
|
69
|
+
|
70
|
+
def msg_pair(label, value, color=:cyan)
|
71
|
+
if value && !value.to_s.empty?
|
72
|
+
puts "#{ui.color(label, color)}: #{value}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def validate!(keys=[:oca_one_auth, :oca_xml_rpc_endpoint])
|
77
|
+
errors = []
|
78
|
+
|
79
|
+
keys.each do |k|
|
80
|
+
pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(oca)/i) ? w.upcase : w.capitalize }
|
81
|
+
if Chef::Config[k].nil? && Chef::Config[:knife][k].nil?
|
82
|
+
errors << "You did not provide a valid '#{pretty_key}' value."
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if errors.each{|e| ui.error(e)}.any?
|
87
|
+
exit 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def dns_reverse_lookup(ip)
|
92
|
+
Resolv::DNS.new.getname(ip.to_s).to_s
|
93
|
+
rescue Resolv::ResolvError => e
|
94
|
+
'-not available-'
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Dennis Klein (<d.klein@gsi.de>)
|
3
|
+
# Copyright:: Copyright (c) 2012 GSI Helmholtz Centre for Heavy Ion Research.
|
4
|
+
#
|
5
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
6
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
7
|
+
# Copyright:: Copyright (c) 2009-2011 Opscode, Inc.
|
8
|
+
# License:: Apache License, Version 2.0
|
9
|
+
#
|
10
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
# you may not use this file except in compliance with the License.
|
12
|
+
# You may obtain a copy of the License at
|
13
|
+
#
|
14
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
#
|
16
|
+
# Unless required by applicable law or agreed to in writing, software
|
17
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
# See the License for the specific language governing permissions and
|
20
|
+
# limitations under the License.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'chef/knife/oca_base'
|
24
|
+
|
25
|
+
# These two are needed for the '--purge' deletion case
|
26
|
+
require 'chef/node'
|
27
|
+
require 'chef/api_client'
|
28
|
+
|
29
|
+
class Chef
|
30
|
+
class Knife
|
31
|
+
class OcaServerDelete < Knife
|
32
|
+
|
33
|
+
include Knife::OcaBase
|
34
|
+
|
35
|
+
banner "knife oca server delete SERVER [SERVER] (options)"
|
36
|
+
|
37
|
+
attr_reader :server
|
38
|
+
|
39
|
+
option :purge,
|
40
|
+
:short => "-P",
|
41
|
+
:long => "--purge",
|
42
|
+
:boolean => true,
|
43
|
+
:default => false,
|
44
|
+
:description => "Destroy corresponding node and client on the Chef Server, in addition to destroying the OCA node itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
|
45
|
+
|
46
|
+
option :chef_node_name,
|
47
|
+
:short => "-N NAME",
|
48
|
+
:long => "--node-name NAME",
|
49
|
+
: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."
|
50
|
+
|
51
|
+
# Extracted from Chef::Knife.delete_object, because it has a
|
52
|
+
# confirmation step built in... By specifying the '--purge'
|
53
|
+
# flag (and also explicitly confirming the server destruction!)
|
54
|
+
# the user is already making their intent known. It is not
|
55
|
+
# necessary to make them confirm two more times.
|
56
|
+
def destroy_item(klass, name, type_name)
|
57
|
+
begin
|
58
|
+
object = klass.load(name)
|
59
|
+
object.destroy
|
60
|
+
ui.warn("Deleted #{type_name} #{name}")
|
61
|
+
rescue Net::HTTPServerException
|
62
|
+
ui.warn("Could not find a #{type_name} named #{name} to delete!")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def run
|
67
|
+
|
68
|
+
validate!
|
69
|
+
|
70
|
+
@name_args.each do |instance_id|
|
71
|
+
|
72
|
+
begin
|
73
|
+
@server = connection.virtual_machines.get(instance_id.to_s)
|
74
|
+
|
75
|
+
fqdn = dns_reverse_lookup(@server.template['NIC']['IP'].to_s)
|
76
|
+
|
77
|
+
msg_pair("ID", @server.id.to_s)
|
78
|
+
msg_pair("Public IP", @server.template['NIC']['IP'].to_s)
|
79
|
+
msg_pair("Public DNS Name", fqdn)
|
80
|
+
msg_pair("Template", connection.templates.get(@server.template['TEMPLATE_ID']).name.to_s)
|
81
|
+
|
82
|
+
puts "\n"
|
83
|
+
confirm("Do you really want to delete this server")
|
84
|
+
|
85
|
+
@server.finalize
|
86
|
+
|
87
|
+
ui.warn("Deleted server #{@server.id}")
|
88
|
+
|
89
|
+
if config[:purge]
|
90
|
+
thing_to_delete = config[:chef_node_name] || fqdn
|
91
|
+
destroy_item(Chef::Node, thing_to_delete, "node")
|
92
|
+
destroy_item(Chef::ApiClient, thing_to_delete, "client")
|
93
|
+
else
|
94
|
+
ui.warn("Corresponding node and client for the #{instance_id} server were not deleted and remain registered with the Chef Server")
|
95
|
+
end
|
96
|
+
|
97
|
+
rescue NoMethodError
|
98
|
+
ui.error("Could not locate server '#{instance_id}'.")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Dennis Klein (<d.klein@gsi.de>)
|
3
|
+
# Copyright:: Copyright (c) 2012 GSI Helmholtz Centre for Heavy Ion Research.
|
4
|
+
#
|
5
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
6
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
7
|
+
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
8
|
+
# License:: Apache License, Version 2.0
|
9
|
+
#
|
10
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
# you may not use this file except in compliance with the License.
|
12
|
+
# You may obtain a copy of the License at
|
13
|
+
#
|
14
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
#
|
16
|
+
# Unless required by applicable law or agreed to in writing, software
|
17
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
# See the License for the specific language governing permissions and
|
20
|
+
# limitations under the License.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'chef/knife/oca_base'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
class OcaServerList < Knife
|
28
|
+
|
29
|
+
include Knife::OcaBase
|
30
|
+
|
31
|
+
banner "knife oca server list (options)"
|
32
|
+
|
33
|
+
def run
|
34
|
+
$stdout.sync = true
|
35
|
+
|
36
|
+
validate!
|
37
|
+
|
38
|
+
server_list = [
|
39
|
+
ui.color('ID', :bold),
|
40
|
+
ui.color('Public IP', :bold),
|
41
|
+
ui.color('Public DNS Name', :bold),
|
42
|
+
ui.color('State', :bold),
|
43
|
+
ui.color('CPUs', :bold),
|
44
|
+
ui.color('Memory', :bold),
|
45
|
+
ui.color('Template', :bold)
|
46
|
+
]
|
47
|
+
connection.virtual_machines.all('m').each do |server|
|
48
|
+
server_list << server.id.to_s
|
49
|
+
server_list << server.template['NIC']['IP'].to_s
|
50
|
+
server_list << dns_reverse_lookup(server.template['NIC']['IP'].to_s)
|
51
|
+
server_list << begin
|
52
|
+
state = server.lcm_state.to_i
|
53
|
+
state = 1 if state == 0
|
54
|
+
state = Fog::Compute::OCA::VirtualMachine::LCM_STATE[state]
|
55
|
+
case state
|
56
|
+
when 'SHUTDOWN', 'CANCEL', 'FAILURE', 'UNKNOWN'
|
57
|
+
ui.color(Fog::Compute::OCA::VirtualMachine::SHORT_LCM_STATES[state], :red)
|
58
|
+
when 'LCM_INIT', 'PROLOG', 'BOOT'
|
59
|
+
ui.color(Fog::Compute::OCA::VirtualMachine::SHORT_LCM_STATES[state], :yellow)
|
60
|
+
else
|
61
|
+
ui.color(Fog::Compute::OCA::VirtualMachine::SHORT_LCM_STATES[state], :green)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
server_list << server.template['VCPU'].to_s
|
65
|
+
server_list << server.template['MEMORY'].to_s
|
66
|
+
server_list << begin
|
67
|
+
template = connection.templates.get(server.template['TEMPLATE_ID'])
|
68
|
+
template.name.to_s
|
69
|
+
end
|
70
|
+
end
|
71
|
+
puts ui.list(server_list, :uneven_columns_across, 7)
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,334 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Dennis Klein (<d.klein@gsi.de>)
|
3
|
+
# Copyright:: Copyright (c) 2012 GSI Helmholtz Centre for Heavy Ion Research.
|
4
|
+
#
|
5
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
6
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
7
|
+
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
8
|
+
#
|
9
|
+
# License:: Apache License, Version 2.0
|
10
|
+
#
|
11
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
+
# you may not use this file except in compliance with the License.
|
13
|
+
# You may obtain a copy of the License at
|
14
|
+
#
|
15
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
#
|
17
|
+
# Unless required by applicable law or agreed to in writing, software
|
18
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
+
# See the License for the specific language governing permissions and
|
21
|
+
# limitations under the License.
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'chef/knife/oca_base'
|
25
|
+
require 'net/scp'
|
26
|
+
|
27
|
+
class Chef
|
28
|
+
class Knife
|
29
|
+
class OcaTemplateInstantiate < Knife
|
30
|
+
|
31
|
+
include Knife::OcaBase
|
32
|
+
|
33
|
+
deps do
|
34
|
+
require 'fog'
|
35
|
+
require 'readline'
|
36
|
+
require 'chef/json_compat'
|
37
|
+
require 'chef/knife/bootstrap'
|
38
|
+
Chef::Knife::Bootstrap.load_deps
|
39
|
+
end
|
40
|
+
|
41
|
+
banner "knife oca template instantiate ID (options)"
|
42
|
+
|
43
|
+
attr_accessor :initial_sleep_delay
|
44
|
+
attr_reader :server
|
45
|
+
|
46
|
+
option :tags,
|
47
|
+
:short => "-T T=V[,T=V,...]",
|
48
|
+
:long => "--tags Tag=Value[,Tag=Value...]",
|
49
|
+
:description => "The tags for this server",
|
50
|
+
:proc => Proc.new { |tags| tags.split(',') }
|
51
|
+
|
52
|
+
option :chef_node_name,
|
53
|
+
:short => "-N NAME",
|
54
|
+
:long => "--node-name NAME",
|
55
|
+
:description => "The Chef node name for your new node"
|
56
|
+
|
57
|
+
option :ssh_user,
|
58
|
+
:short => "-x USERNAME",
|
59
|
+
:long => "--ssh-user USERNAME",
|
60
|
+
:description => "The ssh username",
|
61
|
+
:default => "root"
|
62
|
+
|
63
|
+
option :ssh_password,
|
64
|
+
:short => "-P PASSWORD",
|
65
|
+
:long => "--ssh-password PASSWORD",
|
66
|
+
:description => "The ssh password"
|
67
|
+
|
68
|
+
option :ssh_port,
|
69
|
+
:short => "-p PORT",
|
70
|
+
:long => "--ssh-port PORT",
|
71
|
+
:description => "The ssh port",
|
72
|
+
:default => "22",
|
73
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
|
74
|
+
|
75
|
+
option :identity_file,
|
76
|
+
:short => "-i IDENTITY_FILE",
|
77
|
+
:long => "--identity-file IDENTITY_FILE",
|
78
|
+
:description => "The SSH identity file used for authentication"
|
79
|
+
|
80
|
+
option :prerelease,
|
81
|
+
:long => "--prerelease",
|
82
|
+
:description => "Install the pre-release chef gems"
|
83
|
+
|
84
|
+
option :bootstrap_version,
|
85
|
+
:long => "--bootstrap-version VERSION",
|
86
|
+
:description => "The version of Chef to install",
|
87
|
+
:proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
|
88
|
+
|
89
|
+
option :distro,
|
90
|
+
:short => "-d DISTRO",
|
91
|
+
:long => "--distro DISTRO",
|
92
|
+
:description => "Bootstrap a distro using a template; default is 'chef-full'",
|
93
|
+
:proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
|
94
|
+
:default => "chef-full"
|
95
|
+
|
96
|
+
option :template_file,
|
97
|
+
:long => "--template-file TEMPLATE",
|
98
|
+
:description => "Full path to location of a knife bootstrap template to use",
|
99
|
+
:proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
|
100
|
+
:default => false
|
101
|
+
|
102
|
+
option :run_list,
|
103
|
+
:short => "-r RUN_LIST",
|
104
|
+
:long => "--run-list RUN_LIST",
|
105
|
+
:description => "Comma separated list of roles/recipes to apply",
|
106
|
+
:proc => lambda { |o| o.split(/[\s,]+/) },
|
107
|
+
:default => []
|
108
|
+
|
109
|
+
option :json_attributes,
|
110
|
+
:short => "-j JSON",
|
111
|
+
:long => "--json-attributes JSON",
|
112
|
+
:description => "A JSON string to be added to the first run of chef-client",
|
113
|
+
:proc => lambda { |o| JSON.parse(o) },
|
114
|
+
:default => {}
|
115
|
+
|
116
|
+
option :host_key_verify,
|
117
|
+
:long => "--[no-]host-key-verify",
|
118
|
+
:description => "Verify host key, disabled by default.",
|
119
|
+
:boolean => true,
|
120
|
+
:default => false
|
121
|
+
|
122
|
+
option :is_chef_server,
|
123
|
+
:long => "--is-chef-server",
|
124
|
+
:description => "Do not bootstrap, assume chef server is already installed, retrieve keys and configure knife",
|
125
|
+
:boolean => true,
|
126
|
+
:default => false
|
127
|
+
|
128
|
+
option :chef_server_url_template,
|
129
|
+
:long => "--chef-server-url-template",
|
130
|
+
:description => "Some chef servers are proxied, therefor you can specify a url template. The default is 'https://FQDN:443'. FQDN gets replaced with the full qualified domain name of the node.",
|
131
|
+
:default => "https://FQDN:443"
|
132
|
+
|
133
|
+
option :retrieve_files,
|
134
|
+
:long => "--retrieve-files",
|
135
|
+
:description => "Comma-seperated list of files to be scped from the node into the current working directory, defaults are ['/etc/chef/validation.pem', '/etc/chef/webui.pem']. Is only performed if --is-chef-server is set!",
|
136
|
+
:proc => lambda { |o| o.split(/[\s,]+/) },
|
137
|
+
:default => ['/etc/chef/validation.pem', '/etc/chef/webui.pem']
|
138
|
+
|
139
|
+
option :repository,
|
140
|
+
:short => "-r REPO",
|
141
|
+
:long => "--repository REPO",
|
142
|
+
:description => "The path to your chef-repo, default is the current working directory.",
|
143
|
+
:default => Dir.pwd
|
144
|
+
|
145
|
+
def tcp_test_ssh(hostname)
|
146
|
+
tcp_socket = TCPSocket.new(hostname, config[:ssh_port])
|
147
|
+
readable = IO.select([tcp_socket], nil, nil, 5)
|
148
|
+
if readable
|
149
|
+
Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
|
150
|
+
yield
|
151
|
+
true
|
152
|
+
else
|
153
|
+
false
|
154
|
+
end
|
155
|
+
rescue SocketError
|
156
|
+
sleep 2
|
157
|
+
false
|
158
|
+
rescue Errno::ETIMEDOUT
|
159
|
+
false
|
160
|
+
rescue Errno::EPERM
|
161
|
+
false
|
162
|
+
rescue Errno::ECONNREFUSED
|
163
|
+
sleep 2
|
164
|
+
false
|
165
|
+
# This happens on EC2 quite often
|
166
|
+
rescue Errno::EHOSTUNREACH
|
167
|
+
sleep 2
|
168
|
+
false
|
169
|
+
# This happens on EC2 sometimes
|
170
|
+
rescue Errno::ENETUNREACH
|
171
|
+
sleep 2
|
172
|
+
false
|
173
|
+
ensure
|
174
|
+
tcp_socket && tcp_socket.close
|
175
|
+
end
|
176
|
+
|
177
|
+
def run
|
178
|
+
$stdout.sync = true
|
179
|
+
|
180
|
+
validate!
|
181
|
+
|
182
|
+
template_id = @name_args.first
|
183
|
+
@template = connection.templates.get(template_id)
|
184
|
+
instance_id = @template.instantiate
|
185
|
+
@server = connection.virtual_machines.get(instance_id.to_s)
|
186
|
+
|
187
|
+
hashed_tags={}
|
188
|
+
tags.map{ |t| key,val=t.split('='); hashed_tags[key]=val} unless tags.nil?
|
189
|
+
|
190
|
+
# Always set the Name tag
|
191
|
+
unless hashed_tags.keys.include? "Name"
|
192
|
+
hashed_tags["Name"] = locate_config_value(:chef_node_name) || @server.id
|
193
|
+
end
|
194
|
+
|
195
|
+
#hashed_tags.each_pair do |key,val|
|
196
|
+
# connection.tags.create :key => key, :value => val, :resource_id => @server.id
|
197
|
+
#end
|
198
|
+
|
199
|
+
msg_pair("Instance ID", @server.id)
|
200
|
+
msg_pair("Template", @template.name)
|
201
|
+
msg_pair("# CPUs", @template.template['VCPU'])
|
202
|
+
msg_pair("Memory", @template.template['MEMORY'])
|
203
|
+
msg_pair("Architecture", @template.template['OS']['ARCH'])
|
204
|
+
|
205
|
+
print "\n#{ui.color("Waiting for server", :magenta)}"
|
206
|
+
|
207
|
+
# wait for it to be ready to do stuff
|
208
|
+
@server.wait_for { print "."; ready? }
|
209
|
+
|
210
|
+
puts("done\n")
|
211
|
+
|
212
|
+
fqdn = dns_reverse_lookup(@server.template['NIC']['IP'])
|
213
|
+
|
214
|
+
msg_pair("Public DNS Name", fqdn)
|
215
|
+
msg_pair("Public IP Address", @server.template['NIC']['IP'])
|
216
|
+
|
217
|
+
print "\n#{ui.color("Waiting for sshd", :magenta)}"
|
218
|
+
|
219
|
+
print(".") until tcp_test_ssh(fqdn) {
|
220
|
+
sleep @initial_sleep_delay ||= 10
|
221
|
+
puts("done")
|
222
|
+
}
|
223
|
+
|
224
|
+
if config[:is_chef_server] then
|
225
|
+
retrieve_files(fqdn, config[:retrieve_files])
|
226
|
+
configure_knife(fqdn)
|
227
|
+
else
|
228
|
+
bootstrap_for_node(@server,fqdn).run
|
229
|
+
end
|
230
|
+
|
231
|
+
puts "\n"
|
232
|
+
msg_pair("Instance ID", @server.id)
|
233
|
+
msg_pair("Template", @template.name)
|
234
|
+
msg_pair("# CPUs", @template.template['VCPU'])
|
235
|
+
msg_pair("Memory", @template.template['MEMORY'])
|
236
|
+
msg_pair("Architecture", @template.template['OS']['ARCH'])
|
237
|
+
msg_pair("Public DNS Name", fqdn)
|
238
|
+
msg_pair("Public IP Address", @server.template['NIC']['IP'])
|
239
|
+
msg_pair("Environment", config[:environment] || '_default')
|
240
|
+
msg_pair("Run List", config[:run_list].join(', '))
|
241
|
+
msg_pair("JSON Attributes",config[:json_attributes]) unless config[:json_attributes].empty?
|
242
|
+
puts "\n" if config[:is_chef_server]
|
243
|
+
msg_pair("Knife config generated", config[:config_file]) if config[:is_chef_server]
|
244
|
+
end
|
245
|
+
|
246
|
+
def retrieve_files(fqdn, files)
|
247
|
+
options = Hash.new
|
248
|
+
options[:password] = Chef::Config[:ssh_password]
|
249
|
+
options[:paranoid] = config[:host_key_verify]
|
250
|
+
options[:port] = Chef::Config[:ssh_port] unless Chef::Config[:ssh_port].nil?
|
251
|
+
Net::SCP.start(fqdn, Chef::Config[:ssh_user], options) do |scp|
|
252
|
+
synch = Array.new
|
253
|
+
files.each do |file|
|
254
|
+
puts ui.color("Downloading file ", :magenta) << "#{fqdn}:#{file}" << ui.color(" to ", :magenta) << "#{Dir.pwd}" << ui.color(" ...", :magenta)
|
255
|
+
synch << scp.download(file, Dir.pwd)
|
256
|
+
end
|
257
|
+
synch.each { |d| d.wait }
|
258
|
+
puts('done')
|
259
|
+
end
|
260
|
+
rescue => e
|
261
|
+
puts ui.error("Downloading some files from the node failed. Error: #{e}")
|
262
|
+
exit 1
|
263
|
+
end
|
264
|
+
|
265
|
+
def configure_knife(fqdn)
|
266
|
+
additional_config = IO.read(config[:config_file])
|
267
|
+
|
268
|
+
configure = Chef::Knife::Configure.new
|
269
|
+
configure.config[:defaults] = true
|
270
|
+
configure.config[:initial] = true
|
271
|
+
configure.config[:node_name] = Etc.getlogin
|
272
|
+
configure.config[:client_key] = File.join(File.dirname(config[:config_file]), "#{Etc.getlogin}.pem")
|
273
|
+
configure.config[:chef_server_url] = config[:chef_server_url_template].sub(/FQDN/, fqdn)
|
274
|
+
configure.config[:admin_client_name] = 'chef-webui'
|
275
|
+
configure.config[:admin_client_key] = File.join(Dir.pwd, 'webui.pem')
|
276
|
+
configure.config[:validation_client_name] = 'chef-validator'
|
277
|
+
configure.config[:validation_key] = File.join(Dir.pwd, 'validation.pem')
|
278
|
+
configure.config[:repository] = config[:repository]
|
279
|
+
configure.config[:config_file] = config[:config_file]
|
280
|
+
# monkey patch Chef::Knife::Configure to not ask anything
|
281
|
+
class << configure
|
282
|
+
define_method(:ask_user_for_config_path) {}
|
283
|
+
define_method(:ask_user_for_config) do
|
284
|
+
@chef_server = config[:chef_server_url]
|
285
|
+
@new_client_name = config[:node_name]
|
286
|
+
@admin_client_name = config[:admin_client_name]
|
287
|
+
@admin_client_key = config[:admin_client_key]
|
288
|
+
@validation_client_name = config[:validation_client_name]
|
289
|
+
@validation_key = config[:validation_key]
|
290
|
+
@new_client_key = config[:client_key]
|
291
|
+
@chef_repo = config[:repository]
|
292
|
+
end
|
293
|
+
end
|
294
|
+
configure.run
|
295
|
+
|
296
|
+
open(config[:config_file], 'a') { |f| f << "\n#{additional_config}\n" }
|
297
|
+
end
|
298
|
+
|
299
|
+
def bootstrap_for_node(server,fqdn)
|
300
|
+
bootstrap = Chef::Knife::Bootstrap.new
|
301
|
+
bootstrap.name_args = [fqdn]
|
302
|
+
bootstrap.config[:run_list] = config[:run_list]
|
303
|
+
bootstrap.config[:ssh_user] = Chef::Config[:ssh_user] || config[:ssh_user]
|
304
|
+
bootstrap.config[:ssh_port] = Chef::Config[:ssh_port] || config[:ssh_port]
|
305
|
+
if Chef::Config[:identity_file].nil? && config[:identity_file].nil? then
|
306
|
+
bootstrap.config[:ssh_password] = Chef::Config[:ssh_password] || config[:ssh_password]
|
307
|
+
else
|
308
|
+
bootstrap.config[:identity_file] = Chef::Config[:identity_file] || config[:identity_file]
|
309
|
+
end
|
310
|
+
bootstrap.config[:chef_node_name] = config[:chef_node_name] || fqdn
|
311
|
+
bootstrap.config[:prerelease] = config[:prerelease]
|
312
|
+
bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version)
|
313
|
+
bootstrap.config[:first_boot_attributes] = config[:json_attributes]
|
314
|
+
bootstrap.config[:distro] = locate_config_value(:distro)
|
315
|
+
bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root'
|
316
|
+
bootstrap.config[:template_file] = locate_config_value(:template_file)
|
317
|
+
bootstrap.config[:environment] = config[:environment]
|
318
|
+
# may be needed for vpc_mode
|
319
|
+
bootstrap.config[:host_key_verify] = config[:host_key_verify]
|
320
|
+
bootstrap
|
321
|
+
end
|
322
|
+
|
323
|
+
def tags
|
324
|
+
tags = locate_config_value(:tags)
|
325
|
+
if !tags.nil? and tags.length != tags.to_s.count('=')
|
326
|
+
ui.error("Tags should be entered in a key = value pair")
|
327
|
+
exit 1
|
328
|
+
end
|
329
|
+
tags
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Dennis Klein (<d.klein@gsi.de>)
|
3
|
+
# Copyright:: Copyright (c) 2012 GSI Helmholtz Centre for Heavy Ion Research.
|
4
|
+
#
|
5
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
6
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
7
|
+
# License:: Apache License, Version 2.0
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'chef/knife/oca_base'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Knife
|
26
|
+
class OcaTemplateList < Knife
|
27
|
+
|
28
|
+
include Knife::OcaBase
|
29
|
+
|
30
|
+
banner "knife oca template list (options)"
|
31
|
+
|
32
|
+
def run
|
33
|
+
|
34
|
+
validate!
|
35
|
+
|
36
|
+
flavor_list = [
|
37
|
+
ui.color('ID', :bold),
|
38
|
+
ui.color('Name', :bold),
|
39
|
+
ui.color('Architecture', :bold),
|
40
|
+
ui.color('CPUs', :bold),
|
41
|
+
ui.color('Memory', :bold)
|
42
|
+
]
|
43
|
+
connection.templates.all.each do |template|
|
44
|
+
flavor_list << template.id.to_s
|
45
|
+
flavor_list << template.name.to_s
|
46
|
+
flavor_list << template.template['OS']['ARCH']
|
47
|
+
flavor_list << template.template['VCPU']
|
48
|
+
flavor_list << template.template['MEMORY']
|
49
|
+
end
|
50
|
+
puts ui.list(flavor_list, :uneven_columns_across, 5)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-oca
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dennis Klein
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fog
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: chef
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.10.10
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.10.10
|
46
|
+
description: OCA Support for Chef's Knife Command
|
47
|
+
email:
|
48
|
+
- d.klein@gsi.de
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.rdoc
|
53
|
+
- LICENSE
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- LICENSE
|
57
|
+
- README.rdoc
|
58
|
+
- knife-oca.gemspec
|
59
|
+
- lib/chef/knife/oca_base.rb
|
60
|
+
- lib/chef/knife/oca_server_delete.rb
|
61
|
+
- lib/chef/knife/oca_server_list.rb
|
62
|
+
- lib/chef/knife/oca_template_instantiate.rb
|
63
|
+
- lib/chef/knife/oca_template_list.rb
|
64
|
+
- lib/knife-oca/version.rb
|
65
|
+
homepage: http://www.github.com/Reverand221/knife-oca
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.24
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: OCA Support for Chef's Knife Command
|
89
|
+
test_files: []
|