knife-topo 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +201 -0
- data/README.md +308 -0
- data/knife-topo.gemspec +21 -0
- data/lib/chef/knife/topo/version.rb +5 -0
- data/lib/chef/knife/topo_bootstrap.rb +114 -0
- data/lib/chef/knife/topo_cookbook_create.rb +178 -0
- data/lib/chef/knife/topo_cookbook_upload.rb +84 -0
- data/lib/chef/knife/topo_create.rb +110 -0
- data/lib/chef/knife/topo_export.rb +137 -0
- data/lib/chef/knife/topo_import.rb +100 -0
- data/lib/chef/knife/topo_update.rb +110 -0
- data/lib/chef/knife/topology_helper.rb +280 -0
- data/test-repo/.chef/dummy.pem +27 -0
- data/test-repo/.chef/knife.rb +13 -0
- data/test-repo/Berksfile +4 -0
- data/test-repo/Instructions.txt +48 -0
- data/test-repo/Vagrantfile +67 -0
- data/test-repo/cookbooks/README.md +54 -0
- data/test-repo/cookbooks/testapp/CHANGELOG.md +10 -0
- data/test-repo/cookbooks/testapp/README.md +26 -0
- data/test-repo/cookbooks/testapp/files/default/index.html +13 -0
- data/test-repo/cookbooks/testapp/files/default/package.json +14 -0
- data/test-repo/cookbooks/testapp/files/default/server.js +42 -0
- data/test-repo/cookbooks/testapp/metadata.rb +9 -0
- data/test-repo/cookbooks/testapp/recipes/appserver.rb +8 -0
- data/test-repo/cookbooks/testapp/recipes/db.rb +9 -0
- data/test-repo/cookbooks/testapp/recipes/default.rb +11 -0
- data/test-repo/cookbooks/testapp/recipes/deploy.rb +50 -0
- data/test-repo/cookbooks/testapp/templates/default/nodejs.upstart.conf.erb +9 -0
- data/test-repo/multipletopology.json +117 -0
- data/test-repo/topology.json +99 -0
- metadata +78 -0
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 2014 ThirdWave Insights, LLC
|
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,308 @@
|
|
1
|
+
knife topo
|
2
|
+
==========
|
3
|
+
|
4
|
+
This Chef Knife plugin is provided by ThirdWave Insights LLC.
|
5
|
+
It allows you to use knife to create and update topologies consisting of
|
6
|
+
multiple nodes.
|
7
|
+
|
8
|
+
# Installation #
|
9
|
+
|
10
|
+
Copy the contents of lib/chef/knife into your plugin directory, e.g.:
|
11
|
+
|
12
|
+
$ mkdir -p ~/.chef/knife/plugins
|
13
|
+
$ cp lib/chef/knife/* ~/.chef/knife/plugins
|
14
|
+
|
15
|
+
or install knife-topo as a gem
|
16
|
+
|
17
|
+
$ sudo gem install knife-topo
|
18
|
+
|
19
|
+
This plugin has been tested with Chef Version 11.12 on Ubuntu 14.04 LTS.
|
20
|
+
|
21
|
+
# Usage #
|
22
|
+
|
23
|
+
Define one or more *topologies* in a [*topology file*](#markdown-header-topology-file).
|
24
|
+
|
25
|
+
Import the topology file into your local chef repo using
|
26
|
+
[knife topo import](#markdown-header-knife-topo-import). Create and optionally
|
27
|
+
bootstrap a topology on the Chef server using
|
28
|
+
[knife topo create](#markdown-header-knife-topo-create), and update it
|
29
|
+
using [knife topo update](#markdown-header-knife-topo-update).
|
30
|
+
|
31
|
+
# Getting Started #
|
32
|
+
|
33
|
+
Try out this plugin using a [test repo](knife-topo/src/master/test-repo) which you can
|
34
|
+
download from Github or is included in the installed gem. See the
|
35
|
+
[Instructions](knife-topo/src/master/test-repo/Instructions.txt) for how to use the test repo.
|
36
|
+
|
37
|
+
The instructions assume you have
|
38
|
+
[chefDK](http://www.getchef.com/downloads/chef-dk/)
|
39
|
+
or equivalent installed and working with Vagrant and VirtualBox, but
|
40
|
+
chefDK is not a requirement for this plugin.
|
41
|
+
|
42
|
+
# Topology File #
|
43
|
+
|
44
|
+
See the [example topology file](knife-topo/src/master/test-repo/topology.json)
|
45
|
+
|
46
|
+
The topology file contains a single topology, or an array of topologies.
|
47
|
+
Each topology has some overall properties, an array of nodes and
|
48
|
+
an array defining topology cookbook attributes.
|
49
|
+
|
50
|
+
## Overall Properties
|
51
|
+
|
52
|
+
```json
|
53
|
+
{
|
54
|
+
"name": "test1",
|
55
|
+
"chef_environment": "test",
|
56
|
+
"tags": ["system_sys1", "phase_test" ],
|
57
|
+
"normal": {
|
58
|
+
"owner": {
|
59
|
+
"name": "Christine Draper"
|
60
|
+
}
|
61
|
+
},
|
62
|
+
"nodes" : [
|
63
|
+
...
|
64
|
+
],
|
65
|
+
"cookbook_attributes" : [
|
66
|
+
]
|
67
|
+
},
|
68
|
+
```
|
69
|
+
The `name` is how you will refer to the topology in the
|
70
|
+
`knife topo` subcommands.
|
71
|
+
|
72
|
+
The `chef-environment` and `normal` attributes defined
|
73
|
+
here will be applied to all nodes in the topology, unless alternative
|
74
|
+
values are provided for a specific node. The `tags`
|
75
|
+
will be added to each node. The normal attributes may either be
|
76
|
+
specified using the dot notation, as shown above, or may be expanded as
|
77
|
+
a JSON structure, i.e., the above is equivalent to:
|
78
|
+
```json
|
79
|
+
{
|
80
|
+
"normal": {
|
81
|
+
"topo": {
|
82
|
+
"blueprint": "blah"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
## Node List
|
88
|
+
Each topology contains a list of `nodes`.
|
89
|
+
|
90
|
+
```json
|
91
|
+
"{
|
92
|
+
"name": "test1",
|
93
|
+
...,
|
94
|
+
"nodes": {
|
95
|
+
"buildserver": {
|
96
|
+
"name": "buildserver01",
|
97
|
+
"ssh_host": "127.0.0.1",
|
98
|
+
"ssh_port": "8241",
|
99
|
+
"chef_environment": "dev",
|
100
|
+
"run_list": ["role[base-ubuntu]", "ypo::db", "recipe[ypo::appserver]"],
|
101
|
+
"normal": {
|
102
|
+
"topo.node_type": "buildserver",
|
103
|
+
"another": "Value 1"
|
104
|
+
},
|
105
|
+
"tags": ["build"]
|
106
|
+
},
|
107
|
+
...
|
108
|
+
}
|
109
|
+
}
|
110
|
+
},
|
111
|
+
...
|
112
|
+
]}
|
113
|
+
```
|
114
|
+
Within `nodes`, the `name` field is the node name that will be used in Chef.
|
115
|
+
The fields `chef_environment`, `run_list`, `tags` and the attributes
|
116
|
+
within `normal` will also be applied to the node in Chef. All of these
|
117
|
+
fields are optional.
|
118
|
+
|
119
|
+
The `ssh_host` and `ssh_port` are optional fields that are used to
|
120
|
+
bootstrap a node.
|
121
|
+
|
122
|
+
## Topology Cookbook Attributes
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
# Subcommands #
|
128
|
+
|
129
|
+
The main subcommands for `knife topo` are:
|
130
|
+
|
131
|
+
* `knife topo import` - Import one or more into your workspace/local repo
|
132
|
+
* `knife topo create` - Create and optionally bootstrap a topology of nodes
|
133
|
+
* `knife topo update` - Update a topology of nodes
|
134
|
+
|
135
|
+
The additional subcommands can also be useful, depending on your
|
136
|
+
workflow:
|
137
|
+
|
138
|
+
* `knife topo bootstrap` - Bootstraps a topology of nodes
|
139
|
+
* `knife topo cookbook create` - Generate the topology cookbooks
|
140
|
+
* `knife topo cookbook upload` - Upload the topology cookbooks
|
141
|
+
* `knife export` - Export data from a topology (or from nodes that you want in a topology)
|
142
|
+
|
143
|
+
The topologies are data bag items in the 'topologies' data bag, so
|
144
|
+
you can also use knife commands such as:
|
145
|
+
|
146
|
+
* `knife data bag show topologies` - List the topologies
|
147
|
+
* `knife data bag show topologies test1` - Show details of the test1 topology
|
148
|
+
* `knife data bag delete topologies test1` - Delete the test1 topology
|
149
|
+
|
150
|
+
### Common Options:
|
151
|
+
|
152
|
+
The knife topo subcommands support the following common options.
|
153
|
+
|
154
|
+
Option | Description
|
155
|
+
------------ | -----------
|
156
|
+
-D, --data-bag DATA_BAG | The data bag to use for the topologies. Defaults to 'topologies'.
|
157
|
+
|
158
|
+
## knife topo bootstrap
|
159
|
+
|
160
|
+
knife topo bootstrap TOPOLOGY
|
161
|
+
|
162
|
+
Runs the `knife bootstrap` command for each node in the topology that
|
163
|
+
has the `ssh_host` attribute. Specified options will be passed through
|
164
|
+
to `knife bootstrap` and applied to each node.
|
165
|
+
|
166
|
+
### Options:
|
167
|
+
|
168
|
+
The knife topo bootstrap subcommand supports the following additional options.
|
169
|
+
|
170
|
+
Option | Description
|
171
|
+
------------ | -----------
|
172
|
+
See [knife bootstrap](http://docs.opscode.com/knife_bootstrap.html) | Options supported by `knife bootstrap` are passed through to the bootstrap command
|
173
|
+
|
174
|
+
|
175
|
+
### Examples:
|
176
|
+
The following will bootstrap nodes in the test1 topology, using a
|
177
|
+
user name of vagrant, password of vagrant, and running using sudo.
|
178
|
+
|
179
|
+
$ knife topo bootstrap sys1_test test1 -x vagrant -P vagrant --sudo
|
180
|
+
|
181
|
+
## knife topo cookbook create
|
182
|
+
|
183
|
+
knife topo cookbook create TOPOLOGY
|
184
|
+
|
185
|
+
Generates the topology cookbook attribute files and attributes described in the
|
186
|
+
'cookbook_attributes' property.
|
187
|
+
|
188
|
+
### Examples:
|
189
|
+
The following will generate the topology cookbook attribute files for
|
190
|
+
topology test1.
|
191
|
+
|
192
|
+
$ knife topo cookbook create test1
|
193
|
+
|
194
|
+
## knife topo create
|
195
|
+
|
196
|
+
knife topo create TOPOLOGY
|
197
|
+
|
198
|
+
Creates the specified topology in the chef server as an item in the
|
199
|
+
system environment data bag. Creates the chef environment associated
|
200
|
+
with the system environment, if it does not already exist. Uploads any
|
201
|
+
topology cookbooks. Creates or
|
202
|
+
updates nodes identified in the topology, using information
|
203
|
+
specified in the system environment and for the specific node.
|
204
|
+
|
205
|
+
### Options:
|
206
|
+
|
207
|
+
The knife topo create subcommand supports the following additional options.
|
208
|
+
|
209
|
+
Option | Description
|
210
|
+
------------ | -----------
|
211
|
+
--bootstrap | Bootstrap the topology (see [topo bootstrap](#markdown-header-knife-topo-bootstrap))
|
212
|
+
See [knife bootstrap](http://docs.opscode.com/knife_bootstrap.html) | Options supported by `knife bootstrap` are passed through to the bootstrap command
|
213
|
+
--no-upload | Do not upload topology cookbooks
|
214
|
+
|
215
|
+
### Examples:
|
216
|
+
The following will create the 'test1' topology, and bootstrap it.
|
217
|
+
|
218
|
+
$ knife topo create test1 --bootstrap
|
219
|
+
|
220
|
+
The following will create the 'test1' topology but will not bootstrap it
|
221
|
+
or upload topology cookbooks.
|
222
|
+
|
223
|
+
$ knife topo create test1 --no-upload
|
224
|
+
|
225
|
+
## knife topo export
|
226
|
+
|
227
|
+
knife topo export [ TOPOLOGY [ NODE ... ]
|
228
|
+
|
229
|
+
Exports the specified topology as JSON. If the topology does not already exist,
|
230
|
+
an outline for a new topology will be exported. The exported JSON
|
231
|
+
can be used as the basis for a new topology definition.
|
232
|
+
|
233
|
+
If nodes are specified, these will be added into the export in addition
|
234
|
+
to any nodes that are in the topology.
|
235
|
+
|
236
|
+
If no topology is specified, all existing topologies in that environment
|
237
|
+
will be exported.
|
238
|
+
|
239
|
+
### Examples:
|
240
|
+
The following will export all topologies to a file called 'sys1_test.json'.
|
241
|
+
|
242
|
+
$ knife topo export sys1_test > sys1_test.json
|
243
|
+
|
244
|
+
The following will create an outline for a new topology called 'christine_test':
|
245
|
+
|
246
|
+
$ knife topo export christine_test > christine_test.json
|
247
|
+
|
248
|
+
|
249
|
+
## knife topo import
|
250
|
+
|
251
|
+
knife topo import [ TOPOLOGY_FILE [ TOPOLOGY ... ]]
|
252
|
+
|
253
|
+
Imports the system environment and topologies from a
|
254
|
+
[topology file](#Topology File) into the local repo. If no topology
|
255
|
+
file is specified, attempts to read from a file called 'topology.json'
|
256
|
+
in the current directory. Generates the topology cookbook attribute
|
257
|
+
files and attributes described in the 'cookbook_attributes' property.
|
258
|
+
|
259
|
+
### Examples:
|
260
|
+
The following will import all topologies defined in the 'topology.json' file.
|
261
|
+
|
262
|
+
$ knife topo import topology.json
|
263
|
+
|
264
|
+
The following will import the 'test1' topology
|
265
|
+
defined in the 'topology.json' file.
|
266
|
+
|
267
|
+
$ knife topo import topology.json test1
|
268
|
+
|
269
|
+
## knife topo update
|
270
|
+
|
271
|
+
knife topo update [ TOPOLOGY ]
|
272
|
+
|
273
|
+
Updates the specified topology. Creates or updates nodes
|
274
|
+
identified in the topology, using information specified in the
|
275
|
+
topology for the specific node.
|
276
|
+
|
277
|
+
If no topology is specified, all existing topologies in that environment
|
278
|
+
will be updated.
|
279
|
+
|
280
|
+
### Examples:
|
281
|
+
The following will update the 'test1' topology.
|
282
|
+
|
283
|
+
$ knife topo update test1
|
284
|
+
|
285
|
+
The following will update all topologies in the 'topologies' data bag.
|
286
|
+
|
287
|
+
$ knife topo update
|
288
|
+
|
289
|
+
|
290
|
+
# License #
|
291
|
+
|
292
|
+
Author:: Christine Draper (christine_draper@thirdwaveinsights.com)
|
293
|
+
|
294
|
+
Copyright:: Copyright (c) 2014 ThirdWave Insights, LLC
|
295
|
+
|
296
|
+
License:: Apache License, Version 2.0
|
297
|
+
|
298
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
299
|
+
you may not use this file except in compliance with the License.
|
300
|
+
You may obtain a copy of the License at
|
301
|
+
|
302
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
303
|
+
|
304
|
+
Unless required by applicable law or agreed to in writing, software
|
305
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
306
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
307
|
+
See the License for the specific language governing permissions and
|
308
|
+
limitations under the License.
|
data/knife-topo.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chef/knife/topo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "knife-topo"
|
8
|
+
spec.version = Knife::Topo::VERSION
|
9
|
+
spec.authors = ["Christine Draper"]
|
10
|
+
spec.email = ["christine_draper@thirdwaveinsights.com"]
|
11
|
+
spec.summary = "Knife plugin that to manage topologies of nodes"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/christinedraper/knife-topo"
|
14
|
+
spec.license = "Apache License (2.0)"
|
15
|
+
|
16
|
+
spec.files = Dir.glob("{lib,test-repo}/**/*") +
|
17
|
+
Dir.glob("test-repo/.chef/*") +
|
18
|
+
['LICENSE', 'README.md', __FILE__]
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Christine Draper (<christine_draper@thirdwaveinsights.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 ThirdWave Insights LLC
|
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
|
+
|
20
|
+
require_relative 'topology_helper'
|
21
|
+
require 'chef/knife/bootstrap'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class TopoBootstrap < Chef::Knife
|
26
|
+
|
27
|
+
deps do
|
28
|
+
Chef::Knife::Bootstrap.load_deps
|
29
|
+
end
|
30
|
+
|
31
|
+
banner "knife topo bootstrap TOPOLOGY (options)"
|
32
|
+
|
33
|
+
option :data_bag,
|
34
|
+
:short => '-D DATA_BAG',
|
35
|
+
:long => "--data-bag DATA_BAG",
|
36
|
+
:description => "The data bag the topologies are stored in"
|
37
|
+
|
38
|
+
# Make the base bootstrap options available on topo bootstrap
|
39
|
+
self.options = (Chef::Knife::Bootstrap.options).merge(self.options)
|
40
|
+
|
41
|
+
def initialize (args)
|
42
|
+
super
|
43
|
+
@bootstrap_args = initialize_cmd_args(args, [ 'bootstrap', '' ])
|
44
|
+
|
45
|
+
# All called commands need to accept union of options
|
46
|
+
Chef::Knife::Bootstrap.options = options
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def run
|
51
|
+
if !@name_args[0]
|
52
|
+
show_usage
|
53
|
+
ui.fatal("You must specify the name of a topology")
|
54
|
+
exit 1
|
55
|
+
end
|
56
|
+
|
57
|
+
@bag_name = topo_bag_name(config[:data_bag])
|
58
|
+
@topo_name = @name_args[0]
|
59
|
+
|
60
|
+
# get the node names for the topology
|
61
|
+
unless topo = load_from_server(@bag_name, @topo_name )
|
62
|
+
ui.fatal("Topology #{@bag_name}/#{@topo_name} does not exist on the server - use 'knife topo create' first")
|
63
|
+
exit(1)
|
64
|
+
end
|
65
|
+
|
66
|
+
# load and bootstrap each node that has a ssh_host
|
67
|
+
nodes = merge_topo_properties(topo['nodes'], topo)
|
68
|
+
@failed = []
|
69
|
+
skipped = 0
|
70
|
+
succeeded = 0
|
71
|
+
if nodes.length > 0
|
72
|
+
nodes.each do |node_data|
|
73
|
+
if node_data['ssh_host']
|
74
|
+
run_bootstrap(node_data)
|
75
|
+
succeeded += 1
|
76
|
+
else
|
77
|
+
ui.info "Node #{node_data['name']} does not have ssh_host specified - skipping bootstrap"
|
78
|
+
skipped += 1
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
ui.info "Successfully bootstrapped #{nodes.length - (@failed.length + skipped)} nodes and skipped #{skipped} nodes of #{nodes.length} in topology #{@bag_name}/#{@topo_name}"
|
83
|
+
ui.warn "#{@failed.length} nodes [ #{@failed.join(', ')} ] failed to bootstrap" if @failed.length > 0
|
84
|
+
else
|
85
|
+
ui.info "No nodes found for topology #{@topo_name}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Setup the bootstrap args and run the bootstrap command
|
90
|
+
def run_bootstrap(node_data)
|
91
|
+
node_name = node_data['name']
|
92
|
+
args = @bootstrap_args
|
93
|
+
args += ['-N', node_name] if(node_name)
|
94
|
+
args += ['-E', node_data['chef_environment']] if(node_data['chef_environment'])
|
95
|
+
args[1] = node_data['ssh_host']
|
96
|
+
args += [ '--ssh-port', node_data['ssh_port']] if node_data['ssh_port']
|
97
|
+
args += [ '--run-list' , node_data['run_list'].join(',')] if node_data['run_list']
|
98
|
+
|
99
|
+
ui.info "Bootstrapping node #{node_name}"
|
100
|
+
begin
|
101
|
+
run_cmd(Chef::Knife::Bootstrap, args)
|
102
|
+
rescue Exception => e
|
103
|
+
raise if Chef::Config[:verbosity] == 2
|
104
|
+
@failed << node_name
|
105
|
+
ui.warn "bootstrap of node #{node_name} exited with error"
|
106
|
+
humanize_exception(e)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
include Chef::Knife::TopologyHelper
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|