dev-lxc 0.1.2
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +275 -0
- data/Rakefile +1 -0
- data/bin/dev-lxc +6 -0
- data/dev-lxc.gemspec +25 -0
- data/files/configs/ha.yaml +31 -0
- data/files/configs/open-source.yaml +10 -0
- data/files/configs/standalone.yaml +13 -0
- data/files/configs/tier.yaml +21 -0
- data/files/create_users/create_users.rb +53 -0
- data/files/create_users/default.rb +261 -0
- data/files/create_users/knife.rb.erb +15 -0
- data/lib/dev-lxc/chef-cluster.rb +127 -0
- data/lib/dev-lxc/chef-server.rb +234 -0
- data/lib/dev-lxc/cli.rb +137 -0
- data/lib/dev-lxc/container.rb +62 -0
- data/lib/dev-lxc/version.rb +3 -0
- data/lib/dev-lxc.rb +79 -0
- metadata +132 -0
data/.gitignore
ADDED
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,275 @@
|
|
1
|
+
# dev-lxc
|
2
|
+
|
3
|
+
A tool for creating Chef server clusters using LXC containers.
|
4
|
+
|
5
|
+
Using [ruby-lxc](https://github.com/lxc/ruby-lxc) it builds a standalone server or
|
6
|
+
tier cluster composed of a backend and multiple frontends with round-robin DNS resolution.
|
7
|
+
|
8
|
+
The dev-lxc tool is well suited as a tool for support related work, customized
|
9
|
+
cluster builds for demo purposes, as well as general experimentation and exploration.
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
1. LXC 1.0 Containers - Resource efficient servers with fast start/stop times and standard init
|
14
|
+
2. Btrfs - Storage efficient container backend provides fast container cloning
|
15
|
+
3. Dnsmasq - DHCP networking and DNS resolution
|
16
|
+
4. Base platforms - Containers that are built to resemble a traditional server
|
17
|
+
5. ruby-lxc - Ruby bindings for LXC
|
18
|
+
6. YAML - Simple, customizable definition of clusters; No more setting ENV variables
|
19
|
+
7. Build process closely models the docs instructions
|
20
|
+
|
21
|
+
Its containers, standard init, networking and build process are designed to be similar
|
22
|
+
to what you would build if you follow the product installation documentation so the end
|
23
|
+
result is a cluster that is relatively similar to a more traditionally built cluster.
|
24
|
+
|
25
|
+
The Btrfs backed clones provides a quick clean slate which is so helpful especially
|
26
|
+
for experimenting and troubleshooting. Or it can be used to build a customized cluster
|
27
|
+
for demo purposes and be able to bring it up quickly and reliably.
|
28
|
+
|
29
|
+
While most of the plumbing is already in place for an HA cluster it actually can't be
|
30
|
+
used since I haven't been able to get DRBD working inside containers yet.
|
31
|
+
|
32
|
+
If you aren't familiar with using containers please read this introduction.
|
33
|
+
|
34
|
+
[LXC 1.0 Introduction](https://www.stgraber.org/2013/12/20/lxc-1-0-blog-post-series/)
|
35
|
+
|
36
|
+
## Requirements
|
37
|
+
|
38
|
+
The dev-lxc tool is designed to be used in platform built by the
|
39
|
+
[dev-lxc-platform](https://github.com/jeremiahsnapp/dev-lxc-platform) cookbook.
|
40
|
+
|
41
|
+
Please follow the dev-lxc-platform usage instructions to create a suitable platform.
|
42
|
+
|
43
|
+
The cookbook will automatically install this dev-lxc tool.
|
44
|
+
|
45
|
+
### Mounts and Packages (batteries not included)
|
46
|
+
|
47
|
+
As described below `dev-lxc` uses a YAML config file for each cluster.
|
48
|
+
|
49
|
+
This config file describes what directories get mounted from the Vagrant VM host into
|
50
|
+
each container. You need to make sure that you configure the mount entries to be
|
51
|
+
appropriate for your environment.
|
52
|
+
|
53
|
+
The same goes for the paths to each package. The paths that are provided in the default
|
54
|
+
configs are just examples. You need to make sure that you have each package you want to
|
55
|
+
use downloaded to appropriate directories that will be available to the container when
|
56
|
+
it is started.
|
57
|
+
|
58
|
+
I recommend downloading the packages to a directory on your workstation.
|
59
|
+
Then configure the `dev-lxc-platform` `Vagrantfile` to mount that directory in the
|
60
|
+
Vagrant VM. Finally, configure the cluster's YAML config mount entries to mount the Vagrant
|
61
|
+
VM directory into each container.
|
62
|
+
|
63
|
+
## Upgrade dev-lxc gem
|
64
|
+
|
65
|
+
To upgrade the dev-lxc gem at any time you can run `gem uninstall -x dev-lxc` inside
|
66
|
+
the Vagrant VM and then reprovision the VM using `vagrant provision`.
|
67
|
+
|
68
|
+
## Usage
|
69
|
+
|
70
|
+
### Shorter Commands are Faster (to type that is :)
|
71
|
+
|
72
|
+
I like to create an alias for `dev-lxc` for ease of use but for the purpose of these
|
73
|
+
instructions I will use `dev-lxc`.
|
74
|
+
|
75
|
+
echo 'alias dl=dev-lxc' >> ~/.bashrc && source ~/.bashrc
|
76
|
+
|
77
|
+
You only have to type enough of a `dev-lxc` subcommand to make it unique.
|
78
|
+
|
79
|
+
The following commands are equivalent:
|
80
|
+
|
81
|
+
dev-lxc cluster init tier
|
82
|
+
dl cl i
|
83
|
+
|
84
|
+
dev-lxc cluster start
|
85
|
+
dl cl start
|
86
|
+
|
87
|
+
dev-lxc cluster destroy
|
88
|
+
dl cl d
|
89
|
+
|
90
|
+
### Base Servers
|
91
|
+
|
92
|
+
One of the key things this tool uses is the concept of "base" servers.
|
93
|
+
It creates servers with "b-" prepended to the name to signify it as a base server.
|
94
|
+
Base servers are then snapshot cloned using the btrfs filesystem to provide very
|
95
|
+
quick, lightweight duplicates of the base server that are either used to build
|
96
|
+
another base server or a usable server.
|
97
|
+
|
98
|
+
The initial creation of base servers for the various platforms can take awhile so
|
99
|
+
let's go ahead and start creating an Ubuntu 12.04 base server now.
|
100
|
+
|
101
|
+
dev-lxc create b-ubuntu-1204
|
102
|
+
|
103
|
+
You can see a menu of base servers this tool can create by using the following command.
|
104
|
+
|
105
|
+
dev-lxc create
|
106
|
+
|
107
|
+
### Cluster Config Files
|
108
|
+
|
109
|
+
dev-lxc uses a yaml configuration file to define a cluster.
|
110
|
+
|
111
|
+
The following command generates sample config files for various cluster topologies.
|
112
|
+
|
113
|
+
dev-lxc cluster init
|
114
|
+
|
115
|
+
`dev-lxc cluster init tier` generates the following file:
|
116
|
+
|
117
|
+
base_platform: b-ubuntu-1204
|
118
|
+
topology: tier
|
119
|
+
api_fqdn: chef-tier.lxc
|
120
|
+
mounts:
|
121
|
+
- /dev-shared dev-shared
|
122
|
+
packages:
|
123
|
+
server: /dev-shared/chef-packages/ec/private-chef_11.1.2-1.ubuntu.12.04_amd64.deb
|
124
|
+
# reporting: /dev-shared/chef-packages/ec/reporting/opscode-reporting_1.1.0-1.ubuntu.12.04_amd64.deb
|
125
|
+
# push-jobs-server: /dev-shared/chef-packages/ec/push-jobs-server/opscode-push-jobs-server_1.1.0-1.ubuntu.12.04_amd64.deb
|
126
|
+
# manage: /dev-shared/chef-packages/ec/manage/opscode-manage_1.1.1-1.ubuntu.12.04_amd64.deb
|
127
|
+
servers:
|
128
|
+
be-tier.lxc:
|
129
|
+
role: backend
|
130
|
+
ipaddress: 10.0.3.202
|
131
|
+
bootstrap: true
|
132
|
+
fe1-tier.lxc:
|
133
|
+
role: frontend
|
134
|
+
ipaddress: 10.0.3.203
|
135
|
+
# fe2-tier.lxc:
|
136
|
+
# role: frontend
|
137
|
+
# ipaddress: 10.0.3.204
|
138
|
+
|
139
|
+
This config defines a tier cluster consisting of a single backend and a single frontend.
|
140
|
+
A second frontend is commented out to conserve resources.
|
141
|
+
|
142
|
+
If you uncomment the second frontend then both frontends will be created and dnsmasq will
|
143
|
+
resolve the `api_fqdn` [chef-tier.lxc](chef-tier.lxc) to both frontends using a round-robin policy.
|
144
|
+
|
145
|
+
The config file is very customizable. You can add or remove mounts, packages or servers,
|
146
|
+
change ip addresses, change server names, change the base_platform and more.
|
147
|
+
|
148
|
+
Make sure the mounts and packages represent paths that are available in your environment.
|
149
|
+
|
150
|
+
### Managing Multiple Clusters
|
151
|
+
|
152
|
+
By default, `dev-lxc` looks for a `dev-lxc.yaml` file in the present working directory.
|
153
|
+
You can also specify a particular config file as an option for most dev-lxc commands.
|
154
|
+
|
155
|
+
I use the following to avoid specifying each cluster's config file while managing multiple clusters.
|
156
|
+
|
157
|
+
mkdir -p ~/clusters/{clusterA,clusterB}
|
158
|
+
dev-lxc cluster init tier > ~/clusters/clusterA/dev-lxc.yaml
|
159
|
+
dev-lxc cluster init standalone > ~/clusters/clusterB/dev-lxc.yaml
|
160
|
+
cd ~/clusters/clusterA && dev-lxc cluster start # starts clusterA
|
161
|
+
cd ~/clusters/clusterB && dev-lxc cluster start # starts clusterB
|
162
|
+
|
163
|
+
### Maintain Uniqueness Across Multiple Clusters
|
164
|
+
|
165
|
+
The default cluster configs are already designed to be unique from each other but as you build
|
166
|
+
more clusters you have to maintain uniqueness across the YAML config files for the following items.
|
167
|
+
|
168
|
+
1. Server names and `api_fqdn`
|
169
|
+
|
170
|
+
Server names should really be unique across all clusters.
|
171
|
+
|
172
|
+
Even when cluster A is shutdown, if cluster B uses the same server names when it is created it
|
173
|
+
will use the already existing servers from cluster A.
|
174
|
+
|
175
|
+
`api_fqdn` uniqueness only matters when clusters with the same `api_fqdn` are running.
|
176
|
+
|
177
|
+
If cluster B is started with the same `api_fqdn` as an already running cluster A, then cluster B
|
178
|
+
will overwrite cluster A's DNS resolution of `api_fqdn`.
|
179
|
+
|
180
|
+
It is easy to provide uniqueness. For example, you can use the following command to replace `-tier`
|
181
|
+
with `-1234` in a tier cluster's config.
|
182
|
+
|
183
|
+
sed -i 's/-tier/-1234/' dev-lxc.yaml
|
184
|
+
|
185
|
+
2. IP Addresses
|
186
|
+
|
187
|
+
IP addresses uniqueness only matters when clusters with the same IP's are running.
|
188
|
+
|
189
|
+
If cluster B is started with the same IP's as an already running cluster A, then cluster B
|
190
|
+
will overwrite cluster A's DHCP reservation of the IP's but dnsmasq will still refuse to
|
191
|
+
assign the IP's to cluster B because they already in use by cluster A. dnsmasq then assigns
|
192
|
+
random IP's from the DHCP pool to cluster B leaving it in an unexpected state.
|
193
|
+
|
194
|
+
The `dev-lxc-platform` creates the IP range 10.0.3.150 - 254 for DHCP reserved IP's.
|
195
|
+
|
196
|
+
Use unique IP's from that range when configuring clusters.
|
197
|
+
|
198
|
+
### Create and Manage a Cluster
|
199
|
+
|
200
|
+
The following instructions will use a tier cluster for demonstration purposes.
|
201
|
+
The size of this cluster uses about 3GB ram and takes a long time for the first
|
202
|
+
build of the servers. Feel free to try the standalone config first.
|
203
|
+
|
204
|
+
The following command saves a predefined config to dev-lxc.yaml.
|
205
|
+
|
206
|
+
dev-lxc cluster init tier > dev-lxc.yaml
|
207
|
+
|
208
|
+
Starting the cluster the first time takes awhile since it has a lot to build.
|
209
|
+
|
210
|
+
The tool automatically creates snapshot clones at appropriate times so future
|
211
|
+
creation of the cluster's servers is very quick.
|
212
|
+
|
213
|
+
dev-lxc cluster start
|
214
|
+
|
215
|
+
[https://chef-tier.lxc](https://chef-tier.lxc) resolves to the frontend.
|
216
|
+
|
217
|
+
Ponyville and wonderbolts orgs, users, knife.rb and keys are automatically created in
|
218
|
+
the bootstrap backend server in /srv/piab/users for testing purposes.
|
219
|
+
|
220
|
+
Show the status of the cluster.
|
221
|
+
|
222
|
+
dev-cluster status
|
223
|
+
|
224
|
+
Stop the cluster's servers.
|
225
|
+
|
226
|
+
dev-lxc cluster stop
|
227
|
+
|
228
|
+
Clones of the servers as they existed immediately after initial installation and configuration
|
229
|
+
are available so you can destroy the cluster and "rebuild" it within seconds effectively starting
|
230
|
+
with a clean slate.
|
231
|
+
|
232
|
+
dev-lxc cluster destroy
|
233
|
+
dev-lxc cluster start
|
234
|
+
|
235
|
+
The abspath subcommand can be used to prepend each server's rootfs path to a particular file.
|
236
|
+
|
237
|
+
For example, to edit each server's private-chef.rb file you can use the following command.
|
238
|
+
|
239
|
+
emacs $(dev-lxc cluster abspath /etc/opscode/private-chef.rb)
|
240
|
+
|
241
|
+
After modifying the private-chef.rb you could use the run_command subcommand to tell each server
|
242
|
+
to run `private-chef-ctl reconfigure`.
|
243
|
+
|
244
|
+
dev-lxc cluster run_command 'private-chef-ctl reconfigure'
|
245
|
+
|
246
|
+
Use the following command to destroy the cluster's servers and also destroy their corresponding
|
247
|
+
base servers so you can build them from scratch.
|
248
|
+
|
249
|
+
dev-lxc cluster destroy -b
|
250
|
+
|
251
|
+
You can also run most of these commands against individual servers by using the server subcommand.
|
252
|
+
|
253
|
+
dev-lxc server ...
|
254
|
+
|
255
|
+
### Using the dev-lxc library
|
256
|
+
|
257
|
+
dev-lxc can also be used as a library if preferred.
|
258
|
+
|
259
|
+
irb(main):001:0> require 'yaml'
|
260
|
+
irb(main):002:0> require 'dev-lxc'
|
261
|
+
irb(main):003:0> cluster = DevLXC::ChefCluster.new(YAML.load(IO.read('dev-lxc.yaml')))
|
262
|
+
irb(main):004:0> cluster.start
|
263
|
+
irb(main):005:0> server = DevLXC::ChefServer.new("fe1-tier.lxc", YAML.load(IO.read('dev-lxc.yaml')))
|
264
|
+
irb(main):006:0> server.stop
|
265
|
+
irb(main):007:0> server.start
|
266
|
+
irb(main):008:0> server.run_command("private-chef-ctl reconfigure")
|
267
|
+
irb(main):009:0> cluster.destroy
|
268
|
+
|
269
|
+
## Contributing
|
270
|
+
|
271
|
+
1. Fork it
|
272
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
273
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
274
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
275
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/dev-lxc
ADDED
data/dev-lxc.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dev-lxc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dev-lxc"
|
8
|
+
spec.version = DevLXC::VERSION
|
9
|
+
spec.authors = ["Jeremiah Snapp"]
|
10
|
+
spec.email = ["jeremiah@getchef.com"]
|
11
|
+
spec.description = %q{A tool for creating Chef server clusters using LXC containers}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.licenses = "Apache2"
|
14
|
+
spec.homepage = "https://github.com/jeremiahsnapp/dev-lxc"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
spec.add_runtime_dependency "thor", "~> 0"
|
24
|
+
spec.add_runtime_dependency "ruby-lxc", "~> 1.0.1"
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
base_platform: b-ubuntu-1204
|
2
|
+
topology: ha
|
3
|
+
api_fqdn: chef-ha.lxc
|
4
|
+
mounts:
|
5
|
+
- /dev-shared dev-shared
|
6
|
+
packages:
|
7
|
+
server: /dev-shared/chef-packages/ec/private-chef_11.1.2-1.ubuntu.12.04_amd64.deb
|
8
|
+
# reporting: /dev-shared/chef-packages/ec/reporting/opscode-reporting_1.1.0-1.ubuntu.12.04_amd64.deb
|
9
|
+
# push-jobs-server: /dev-shared/chef-packages/ec/push-jobs-server/opscode-push-jobs-server_1.1.0-1.ubuntu.12.04_amd64.deb
|
10
|
+
# manage: /dev-shared/chef-packages/ec/manage/opscode-manage_1.1.1-1.ubuntu.12.04_amd64.deb
|
11
|
+
servers:
|
12
|
+
be1-ha.lxc:
|
13
|
+
role: backend
|
14
|
+
ipaddress: 10.0.3.206
|
15
|
+
bootstrap: true
|
16
|
+
cluster_ipaddress: 192.168.0.5
|
17
|
+
be2-ha.lxc:
|
18
|
+
role: backend
|
19
|
+
ipaddress: 10.0.3.207
|
20
|
+
cluster_ipaddress: 192.168.0.6
|
21
|
+
fe1-ha.lxc:
|
22
|
+
role: frontend
|
23
|
+
ipaddress: 10.0.3.208
|
24
|
+
# fe2-ha.lxc:
|
25
|
+
# role: frontend
|
26
|
+
# ipaddress: 10.0.3.209
|
27
|
+
backend_vip:
|
28
|
+
be-ha.lxc:
|
29
|
+
ipaddress: 10.0.3.210
|
30
|
+
device: eth0
|
31
|
+
heartbeat_device: eth1
|
@@ -0,0 +1,10 @@
|
|
1
|
+
base_platform: b-ubuntu-1204
|
2
|
+
topology: open-source
|
3
|
+
api_fqdn: chef-osc.lxc
|
4
|
+
mounts:
|
5
|
+
- /dev-shared dev-shared
|
6
|
+
packages:
|
7
|
+
server: /dev-shared/chef-packages/osc/chef-server_11.0.10-1.ubuntu.12.04_amd64.deb
|
8
|
+
servers:
|
9
|
+
chef-osc.lxc:
|
10
|
+
ipaddress: 10.0.3.205
|
@@ -0,0 +1,13 @@
|
|
1
|
+
base_platform: b-ubuntu-1204
|
2
|
+
topology: standalone
|
3
|
+
api_fqdn: chef-standalone.lxc
|
4
|
+
mounts:
|
5
|
+
- /dev-shared dev-shared
|
6
|
+
packages:
|
7
|
+
server: /dev-shared/chef-packages/ec/private-chef_11.1.2-1.ubuntu.12.04_amd64.deb
|
8
|
+
# reporting: /dev-shared/chef-packages/ec/reporting/opscode-reporting_1.1.0-1.ubuntu.12.04_amd64.deb
|
9
|
+
# push-jobs-server: /dev-shared/chef-packages/ec/push-jobs-server/opscode-push-jobs-server_1.1.0-1.ubuntu.12.04_amd64.deb
|
10
|
+
# manage: /dev-shared/chef-packages/ec/manage/opscode-manage_1.1.1-1.ubuntu.12.04_amd64.deb
|
11
|
+
servers:
|
12
|
+
chef-standalone.lxc:
|
13
|
+
ipaddress: 10.0.3.201
|
@@ -0,0 +1,21 @@
|
|
1
|
+
base_platform: b-ubuntu-1204
|
2
|
+
topology: tier
|
3
|
+
api_fqdn: chef-tier.lxc
|
4
|
+
mounts:
|
5
|
+
- /dev-shared dev-shared
|
6
|
+
packages:
|
7
|
+
server: /dev-shared/chef-packages/ec/private-chef_11.1.2-1.ubuntu.12.04_amd64.deb
|
8
|
+
# reporting: /dev-shared/chef-packages/ec/reporting/opscode-reporting_1.1.0-1.ubuntu.12.04_amd64.deb
|
9
|
+
# push-jobs-server: /dev-shared/chef-packages/ec/push-jobs-server/opscode-push-jobs-server_1.1.0-1.ubuntu.12.04_amd64.deb
|
10
|
+
# manage: /dev-shared/chef-packages/ec/manage/opscode-manage_1.1.1-1.ubuntu.12.04_amd64.deb
|
11
|
+
servers:
|
12
|
+
be-tier.lxc:
|
13
|
+
role: backend
|
14
|
+
ipaddress: 10.0.3.202
|
15
|
+
bootstrap: true
|
16
|
+
fe1-tier.lxc:
|
17
|
+
role: frontend
|
18
|
+
ipaddress: 10.0.3.203
|
19
|
+
# fe2-tier.lxc:
|
20
|
+
# role: frontend
|
21
|
+
# ipaddress: 10.0.3.204
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Authors
|
2
|
+
# Seth Chisamore
|
3
|
+
# Seth Falcon
|
4
|
+
# Jeremiah Snapp
|
5
|
+
|
6
|
+
require 'chef/mixin/shell_out'
|
7
|
+
include Chef::Mixin::ShellOut
|
8
|
+
|
9
|
+
class PiabHelper
|
10
|
+
|
11
|
+
VALID_OMNIBUS_ROOTS = %w{
|
12
|
+
/opt/opscode
|
13
|
+
/opt/chef-server
|
14
|
+
}
|
15
|
+
|
16
|
+
def self.omnibus_root
|
17
|
+
@@root_path ||= begin
|
18
|
+
root_path = VALID_OMNIBUS_ROOTS.detect{|path| File.exists?(path) }
|
19
|
+
raise "Could not locate one of #{VALID_OMNIBUS_ROOTS.join(', ')}" unless root_path
|
20
|
+
root_path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.omnibus_bin_path
|
25
|
+
self.omnibus_root + "/embedded/bin"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.private_chef_ha?
|
29
|
+
File.exists?("/etc/opscode/private-chef.rb") && File.read("/etc/opscode/private-chef.rb") =~ /topology\s+.*ha/
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.private_chef?
|
33
|
+
File.exists?("/opt/opscode/bin/private-chef-ctl")
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.open_source_chef?
|
37
|
+
File.exists?("/opt/chef-server/bin/chef-server-ctl")
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.existing_config
|
41
|
+
config_files = {
|
42
|
+
"private_chef" => "/etc/opscode/chef-server-running.json",
|
43
|
+
"chef_server" => "/etc/chef-server/chef-server-running.json"
|
44
|
+
}
|
45
|
+
config_files.each do |key, path|
|
46
|
+
if ::File.exists?(path)
|
47
|
+
return Chef::JSONCompat.from_json(IO.read(path))[key]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
raise "No existing config found"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|