dev-lxc 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.gitignore +17 -17
- data/CHANGELOG.md +352 -342
- data/Gemfile +4 -4
- data/LICENSE +201 -201
- data/README.md +235 -233
- data/Rakefile +1 -1
- data/bin/dl +9 -9
- data/dev-lxc.gemspec +26 -26
- data/docs/adhoc_clusters.md +17 -20
- data/docs/base_containers.md +44 -44
- data/docs/byobu_keybindings.md +22 -22
- data/docs/configuration.md +277 -235
- data/docs/dev-lxc_version_2.md +10 -10
- data/docs/manage_multiple_clusters.md +30 -30
- data/docs/mitmproxy.md +7 -7
- data/docs/usage.md +213 -213
- data/example-clusters/README.md +165 -35
- data/example-clusters/automate_dev-lxc.yml +98 -98
- data/example-clusters/chef-backend_dev-lxc.yml +81 -81
- data/example-clusters/conf-files/chef-server/elasticsearch-partial.rb +38 -0
- data/example-clusters/conf-files/chef-server/ldap-partial.rb +10 -0
- data/example-clusters/conf-files/chef-server/postgres-partial.rb +14 -0
- data/example-clusters/external_dev-lxc.yml +60 -0
- data/example-clusters/tier_dev-lxc.yml +88 -88
- data/lib/dev-lxc/cli.rb +542 -537
- data/lib/dev-lxc/cluster.rb +1310 -1215
- data/lib/dev-lxc/container.rb +128 -123
- data/lib/dev-lxc/server.rb +197 -197
- data/lib/dev-lxc/version.rb +3 -3
- data/lib/dev-lxc.rb +118 -118
- metadata +7 -2
data/lib/dev-lxc/cli.rb
CHANGED
@@ -1,537 +1,542 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require "yaml"
|
3
|
-
require 'dev-lxc'
|
4
|
-
require 'thor'
|
5
|
-
|
6
|
-
module DevLXC::CLI
|
7
|
-
class DevLXC < Thor
|
8
|
-
|
9
|
-
no_commands{
|
10
|
-
def get_cluster(config_file=nil)
|
11
|
-
config_file ||= "dev-lxc.yml"
|
12
|
-
if ! File.exists?(config_file)
|
13
|
-
puts "ERROR: Cluster config file '#{config_file}' does not exist."
|
14
|
-
puts " Create a `./dev-lxc.yml` file or specify the path using `--config`."
|
15
|
-
exit 1
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
option :
|
56
|
-
option :
|
57
|
-
option :
|
58
|
-
option :
|
59
|
-
option :
|
60
|
-
option :
|
61
|
-
option :
|
62
|
-
option :
|
63
|
-
option :
|
64
|
-
option :
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#
|
81
|
-
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
#memory_per_server
|
86
|
-
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
#
|
93
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
<%- unless product_versions['
|
119
|
-
|
120
|
-
channel: <%= product_versions['
|
121
|
-
version: <%= product_versions['
|
122
|
-
<%- end -%>
|
123
|
-
<%- unless product_versions['
|
124
|
-
|
125
|
-
channel: <%= product_versions['
|
126
|
-
version: <%= product_versions['
|
127
|
-
<%- end -%>
|
128
|
-
<%- unless product_versions['
|
129
|
-
|
130
|
-
channel: <%= product_versions['
|
131
|
-
version: <%= product_versions['
|
132
|
-
<%- end -%>
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
<%-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
<%-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
<%- unless product_versions['
|
187
|
-
|
188
|
-
channel: <%= product_versions['
|
189
|
-
version: <%= product_versions['
|
190
|
-
<%- end -%>
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
<%- unless product_versions['
|
218
|
-
|
219
|
-
channel: <%= product_versions['
|
220
|
-
version: <%= product_versions['
|
221
|
-
<%- end -%>
|
222
|
-
<%- unless product_versions['
|
223
|
-
|
224
|
-
channel: <%= product_versions['
|
225
|
-
version: <%= product_versions['
|
226
|
-
<%- end -%>
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
<%-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
<%- unless product_versions['
|
237
|
-
|
238
|
-
channel: <%= product_versions['
|
239
|
-
version: <%= product_versions['
|
240
|
-
<%- end -%>
|
241
|
-
<%- unless product_versions['
|
242
|
-
|
243
|
-
channel: <%= product_versions['
|
244
|
-
version: <%= product_versions['
|
245
|
-
<%- end -%>
|
246
|
-
<%- unless product_versions['
|
247
|
-
|
248
|
-
channel: <%= product_versions['
|
249
|
-
version: <%= product_versions['
|
250
|
-
<%- end -%>
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
puts "ERROR:
|
403
|
-
puts "
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
puts "
|
409
|
-
exit 1
|
410
|
-
end
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
end
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
end
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
1
|
+
require 'erb'
|
2
|
+
require "yaml"
|
3
|
+
require 'dev-lxc'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module DevLXC::CLI
|
7
|
+
class DevLXC < Thor
|
8
|
+
|
9
|
+
no_commands{
|
10
|
+
def get_cluster(config_file=nil)
|
11
|
+
config_file ||= "dev-lxc.yml"
|
12
|
+
if ! File.exists?(config_file)
|
13
|
+
puts "ERROR: Cluster config file '#{config_file}' does not exist."
|
14
|
+
puts " Create a `./dev-lxc.yml` file or specify the path using `--config`."
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
begin
|
18
|
+
cluster_config = YAML.load(IO.read(config_file))
|
19
|
+
rescue Psych::SyntaxError => e
|
20
|
+
puts "ERROR: A YAML syntax error was found at line #{e.line} column #{e.column}"
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
::DevLXC::Cluster.new(cluster_config)
|
24
|
+
end
|
25
|
+
|
26
|
+
def print_elapsed_time(elapsed_time)
|
27
|
+
printf "dev-lxc is finished. (%im %.2fs)\n", elapsed_time / 60, elapsed_time % 60
|
28
|
+
end
|
29
|
+
}
|
30
|
+
|
31
|
+
desc "show-config", "Show calculated configuration"
|
32
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
33
|
+
option :include_products, :type => :boolean, :desc => "Calculate required products"
|
34
|
+
def show_config
|
35
|
+
get_cluster(options[:config]).show_config(options[:include_products])
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "create-base-container [BASE_CONTAINER_NAME]", "Create a base container"
|
39
|
+
option :options, :aliases => "-o", :desc => "Specify additional options for the lxc create"
|
40
|
+
def create_base_container(base_container_name=nil)
|
41
|
+
start_time = Time.now
|
42
|
+
base_container_names = %w(b-ubuntu-1204 b-ubuntu-1404 b-ubuntu-1604 b-centos-5 b-centos-6 b-centos-7)
|
43
|
+
if base_container_name.nil? || ! base_container_names.include?(base_container_name)
|
44
|
+
base_container_names_with_index = base_container_names.map.with_index{ |a, i| [i+1, *a]}
|
45
|
+
print_table base_container_names_with_index
|
46
|
+
selection = ask("Which base container do you want to create?", :limited_to => base_container_names_with_index.map{|c| c[0].to_s})
|
47
|
+
base_container_name = base_container_names[selection.to_i - 1]
|
48
|
+
end
|
49
|
+
::DevLXC.create_base_container(base_container_name, options[:options])
|
50
|
+
puts
|
51
|
+
print_elapsed_time(Time.now - start_time)
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "init", "Provide a cluster config file"
|
55
|
+
option :chef, :type => :boolean, :desc => "Standalone Chef Server"
|
56
|
+
option :chef_tier, :type => :boolean, :desc => "Chef Server using Tier topology with one backend"
|
57
|
+
option :chef_backend, :type => :boolean, :desc => "Chef Server using Chef Backend HA topology with three backends"
|
58
|
+
option :nodes, :type => :boolean, :desc => "Node Servers"
|
59
|
+
option :analytics, :type => :boolean, :desc => "Analytics Server"
|
60
|
+
option :compliance, :type => :boolean, :desc => "Compliance Server"
|
61
|
+
option :supermarket, :type => :boolean, :desc => "Supermarket Server"
|
62
|
+
option :automate, :type => :boolean, :desc => "Automate Server"
|
63
|
+
option :build_nodes, :type => :boolean, :desc => "Build Nodes"
|
64
|
+
option :runners, :type => :boolean, :desc => "Runners"
|
65
|
+
option :adhoc, :type => :boolean, :desc => "Adhoc Servers"
|
66
|
+
option :base_container, :default => 'b-ubuntu-1404', :desc => "Specify the base container name"
|
67
|
+
option :product_versions, :type => :hash, :default => {}, :desc => "Specify channel and version (default 'latest') for products [product:channel,version ...]; [product:none] removes the product from the config"
|
68
|
+
option :append, :aliases => "-a", :type => :boolean, :desc => "Do not generate the global config header"
|
69
|
+
option :filename, :aliases => "-f", :desc => "Write generated content to FILE rather than standard output."
|
70
|
+
def init
|
71
|
+
product_versions = Hash.new { |hash, key| hash[key] = { channel: 'stable', version: 'latest' } }
|
72
|
+
options[:product_versions].keys.each do |product|
|
73
|
+
product_versions[product][:channel], product_versions[product][:version] = options[:product_versions][product].to_s.split(',', 2)
|
74
|
+
product_versions[product][:version] ||= 'latest'
|
75
|
+
end
|
76
|
+
|
77
|
+
dev_lxc_template = %Q(<% unless options[:append] -%>
|
78
|
+
# enable_build_snapshots automatically makes container snapshots at key times during the build process
|
79
|
+
# default value is `true`
|
80
|
+
#enable_build_snapshots: true
|
81
|
+
|
82
|
+
# base_container must be the name of an existing container
|
83
|
+
base_container: <%= options[:base_container] %>
|
84
|
+
|
85
|
+
# memory_per_server sets the maximum amount of user memory (including file cache) for each server.
|
86
|
+
# dev-lxc will set the `memory.limit_in_bytes` cgroup for each server to apply this limit.
|
87
|
+
# If no units are specified, the value is interpreted as bytes.
|
88
|
+
# You can use suffixes to represent larger units - k or K for kilobytes, m or M for megabytes, and g or G for gigabytes.
|
89
|
+
# The default behavior is that no limit is set.
|
90
|
+
#memory_per_server: 4G
|
91
|
+
|
92
|
+
# list any host directories you want mounted into the servers
|
93
|
+
#mounts:
|
94
|
+
# - /root/clusters root/clusters
|
95
|
+
|
96
|
+
# list any SSH public keys you want added to /home/dev-lxc/.ssh/authorized_keys
|
97
|
+
#ssh-keys:
|
98
|
+
# - /root/clusters/id_rsa.pub
|
99
|
+
|
100
|
+
# DHCP reserved (static) IPs must be selected from the IP range 10.0.3.150 - 254
|
101
|
+
<% end -%>
|
102
|
+
<% if options[:chef] -%>
|
103
|
+
|
104
|
+
chef-server:
|
105
|
+
users: # a user's password will be the same as its username
|
106
|
+
- mary-admin
|
107
|
+
- joe-user
|
108
|
+
orgs:
|
109
|
+
demo:
|
110
|
+
admins:
|
111
|
+
- mary-admin
|
112
|
+
non-admins:
|
113
|
+
- joe-user
|
114
|
+
servers:
|
115
|
+
chef.lxc:
|
116
|
+
ipaddress: 10.0.3.203
|
117
|
+
products:
|
118
|
+
<%- unless product_versions['chef-server'][:channel] == 'none' -%>
|
119
|
+
chef-server:
|
120
|
+
channel: <%= product_versions['chef-server'][:channel] %>
|
121
|
+
version: <%= product_versions['chef-server'][:version] %>
|
122
|
+
<%- end -%>
|
123
|
+
<%- unless product_versions['manage'][:channel] == 'none' -%>
|
124
|
+
manage:
|
125
|
+
channel: <%= product_versions['manage'][:channel] %>
|
126
|
+
version: <%= product_versions['manage'][:version] %>
|
127
|
+
<%- end -%>
|
128
|
+
<%- unless product_versions['push-jobs-server'][:channel] == 'none' -%>
|
129
|
+
push-jobs-server:
|
130
|
+
channel: <%= product_versions['push-jobs-server'][:channel] %>
|
131
|
+
version: <%= product_versions['push-jobs-server'][:version] %>
|
132
|
+
<%- end -%>
|
133
|
+
<%- unless product_versions['reporting'][:channel] == 'none' -%>
|
134
|
+
reporting:
|
135
|
+
channel: <%= product_versions['reporting'][:channel] %>
|
136
|
+
version: <%= product_versions['reporting'][:version] %>
|
137
|
+
<%- end -%>
|
138
|
+
<% end -%>
|
139
|
+
<% if options[:chef_backend] -%>
|
140
|
+
|
141
|
+
chef-backend:
|
142
|
+
api_fqdn: chef-ha.lxc
|
143
|
+
users: # a user's password will be the same as its username
|
144
|
+
- mary-admin
|
145
|
+
- joe-user
|
146
|
+
orgs:
|
147
|
+
demo:
|
148
|
+
admins:
|
149
|
+
- mary-admin
|
150
|
+
non-admins:
|
151
|
+
- joe-user
|
152
|
+
servers:
|
153
|
+
chef-backend1.lxc:
|
154
|
+
ipaddress: 10.0.3.208
|
155
|
+
role: backend
|
156
|
+
leader: true
|
157
|
+
products:
|
158
|
+
<%- unless product_versions['chef-backend'][:channel] == 'none' -%>
|
159
|
+
chef-backend:
|
160
|
+
channel: <%= product_versions['chef-backend'][:channel] %>
|
161
|
+
version: <%= product_versions['chef-backend'][:version] %>
|
162
|
+
<%- end -%>
|
163
|
+
chef-backend2.lxc:
|
164
|
+
ipaddress: 10.0.3.209
|
165
|
+
role: backend
|
166
|
+
products:
|
167
|
+
<%- unless product_versions['chef-backend'][:channel] == 'none' -%>
|
168
|
+
chef-backend:
|
169
|
+
channel: <%= product_versions['chef-backend'][:channel] %>
|
170
|
+
version: <%= product_versions['chef-backend'][:version] %>
|
171
|
+
<%- end -%>
|
172
|
+
chef-backend3.lxc:
|
173
|
+
ipaddress: 10.0.3.210
|
174
|
+
role: backend
|
175
|
+
products:
|
176
|
+
<%- unless product_versions['chef-backend'][:channel] == 'none' -%>
|
177
|
+
chef-backend:
|
178
|
+
channel: <%= product_versions['chef-backend'][:channel] %>
|
179
|
+
version: <%= product_versions['chef-backend'][:version] %>
|
180
|
+
<%- end -%>
|
181
|
+
chef-frontend1.lxc:
|
182
|
+
ipaddress: 10.0.3.211
|
183
|
+
role: frontend
|
184
|
+
bootstrap: true
|
185
|
+
products:
|
186
|
+
<%- unless product_versions['chef-server'][:channel] == 'none' -%>
|
187
|
+
chef-server:
|
188
|
+
channel: <%= product_versions['chef-server'][:channel] %>
|
189
|
+
version: <%= product_versions['chef-server'][:version] %>
|
190
|
+
<%- end -%>
|
191
|
+
<%- unless product_versions['manage'][:channel] == 'none' -%>
|
192
|
+
manage:
|
193
|
+
channel: <%= product_versions['manage'][:channel] %>
|
194
|
+
version: <%= product_versions['manage'][:version] %>
|
195
|
+
<%- end -%>
|
196
|
+
<% end -%>
|
197
|
+
<% if options[:chef_tier] -%>
|
198
|
+
|
199
|
+
chef-server:
|
200
|
+
topology: tier
|
201
|
+
api_fqdn: chef-tier.lxc
|
202
|
+
users: # a user's password will be the same as its username
|
203
|
+
- mary-admin
|
204
|
+
- joe-user
|
205
|
+
orgs:
|
206
|
+
demo:
|
207
|
+
admins:
|
208
|
+
- mary-admin
|
209
|
+
non-admins:
|
210
|
+
- joe-user
|
211
|
+
servers:
|
212
|
+
chef-be.lxc:
|
213
|
+
ipaddress: 10.0.3.201
|
214
|
+
role: backend
|
215
|
+
bootstrap: true
|
216
|
+
products:
|
217
|
+
<%- unless product_versions['chef-server'][:channel] == 'none' -%>
|
218
|
+
chef-server:
|
219
|
+
channel: <%= product_versions['chef-server'][:channel] %>
|
220
|
+
version: <%= product_versions['chef-server'][:version] %>
|
221
|
+
<%- end -%>
|
222
|
+
<%- unless product_versions['push-jobs-server'][:channel] == 'none' -%>
|
223
|
+
push-jobs-server:
|
224
|
+
channel: <%= product_versions['push-jobs-server'][:channel] %>
|
225
|
+
version: <%= product_versions['push-jobs-server'][:version] %>
|
226
|
+
<%- end -%>
|
227
|
+
<%- unless product_versions['reporting'][:channel] == 'none' -%>
|
228
|
+
reporting:
|
229
|
+
channel: <%= product_versions['reporting'][:channel] %>
|
230
|
+
version: <%= product_versions['reporting'][:version] %>
|
231
|
+
<%- end -%>
|
232
|
+
chef-fe1.lxc:
|
233
|
+
ipaddress: 10.0.3.202
|
234
|
+
role: frontend
|
235
|
+
products:
|
236
|
+
<%- unless product_versions['chef-server'][:channel] == 'none' -%>
|
237
|
+
chef-server:
|
238
|
+
channel: <%= product_versions['chef-server'][:channel] %>
|
239
|
+
version: <%= product_versions['chef-server'][:version] %>
|
240
|
+
<%- end -%>
|
241
|
+
<%- unless product_versions['manage'][:channel] == 'none' -%>
|
242
|
+
manage:
|
243
|
+
channel: <%= product_versions['manage'][:channel] %>
|
244
|
+
version: <%= product_versions['manage'][:version] %>
|
245
|
+
<%- end -%>
|
246
|
+
<%- unless product_versions['push-jobs-server'][:channel] == 'none' -%>
|
247
|
+
push-jobs-server:
|
248
|
+
channel: <%= product_versions['push-jobs-server'][:channel] %>
|
249
|
+
version: <%= product_versions['push-jobs-server'][:version] %>
|
250
|
+
<%- end -%>
|
251
|
+
<%- unless product_versions['reporting'][:channel] == 'none' -%>
|
252
|
+
reporting:
|
253
|
+
channel: <%= product_versions['reporting'][:channel] %>
|
254
|
+
version: <%= product_versions['reporting'][:version] %>
|
255
|
+
<%- end -%>
|
256
|
+
<% end -%>
|
257
|
+
<% if options[:compliance] -%>
|
258
|
+
|
259
|
+
compliance:
|
260
|
+
admin_user: admin # the password will be the same as the username
|
261
|
+
servers:
|
262
|
+
compliance.lxc:
|
263
|
+
ipaddress: 10.0.3.205
|
264
|
+
products:
|
265
|
+
<%- unless product_versions['compliance'][:channel] == 'none' -%>
|
266
|
+
compliance:
|
267
|
+
channel: <%= product_versions['compliance'][:channel] %>
|
268
|
+
version: <%= product_versions['compliance'][:version] %>
|
269
|
+
<%- end -%>
|
270
|
+
<% end -%>
|
271
|
+
<% if options[:supermarket] -%>
|
272
|
+
|
273
|
+
supermarket:
|
274
|
+
servers:
|
275
|
+
supermarket.lxc:
|
276
|
+
ipaddress: 10.0.3.206
|
277
|
+
products:
|
278
|
+
<%- unless product_versions['supermarket'][:channel] == 'none' -%>
|
279
|
+
supermarket:
|
280
|
+
channel: <%= product_versions['supermarket'][:channel] %>
|
281
|
+
version: <%= product_versions['supermarket'][:version] %>
|
282
|
+
<%- end -%>
|
283
|
+
<% end -%>
|
284
|
+
<% if options[:automate] -%>
|
285
|
+
|
286
|
+
automate:
|
287
|
+
servers:
|
288
|
+
automate.lxc:
|
289
|
+
ipaddress: 10.0.3.200
|
290
|
+
products:
|
291
|
+
<%- unless product_versions['automate'][:channel] == 'none' -%>
|
292
|
+
automate:
|
293
|
+
channel: <%= product_versions['automate'][:channel] %>
|
294
|
+
version: <%= product_versions['automate'][:version] %>
|
295
|
+
<%- end -%>
|
296
|
+
license_path: ../delivery.license
|
297
|
+
chef_org: delivery
|
298
|
+
enterprise_name: demo-ent
|
299
|
+
<% end -%>
|
300
|
+
<% if options[:build_nodes] -%>
|
301
|
+
|
302
|
+
build-nodes:
|
303
|
+
servers:
|
304
|
+
build-node-1.lxc:
|
305
|
+
products:
|
306
|
+
<%- unless product_versions['chefdk'][:channel] == 'none' -%>
|
307
|
+
chefdk: # downloaded only
|
308
|
+
channel: <%= product_versions['chefdk'][:channel] %>
|
309
|
+
version: <%= product_versions['chefdk'][:version] %>
|
310
|
+
<%- end -%>
|
311
|
+
<% end -%>
|
312
|
+
<% if options[:runners] -%>
|
313
|
+
|
314
|
+
runners:
|
315
|
+
servers:
|
316
|
+
runner-1.lxc:
|
317
|
+
products:
|
318
|
+
<%- unless product_versions['chefdk'][:channel] == 'none' -%>
|
319
|
+
chefdk: # downloaded only
|
320
|
+
channel: <%= product_versions['chefdk'][:channel] %>
|
321
|
+
version: <%= product_versions['chefdk'][:version] %>
|
322
|
+
<%- end -%>
|
323
|
+
<% end -%>
|
324
|
+
<% if options[:nodes] -%>
|
325
|
+
|
326
|
+
nodes:
|
327
|
+
chef_server_url: https://chef.lxc/organizations/demo
|
328
|
+
validation_client_name: demo-validator
|
329
|
+
# comment out or remove the validation_key path to use chef-server keys generated by dev-lxc
|
330
|
+
validation_key: # /path/for/ORG-validator.pem
|
331
|
+
servers:
|
332
|
+
node-1.lxc:
|
333
|
+
products:
|
334
|
+
<%- unless product_versions['chef'][:channel] == 'none' -%>
|
335
|
+
chef:
|
336
|
+
channel: <%= product_versions['chef'][:channel] %>
|
337
|
+
version: <%= product_versions['chef'][:version] %>
|
338
|
+
<%- end -%>
|
339
|
+
<% end -%>
|
340
|
+
<% if options[:analytics] -%>
|
341
|
+
|
342
|
+
analytics:
|
343
|
+
servers:
|
344
|
+
analytics.lxc:
|
345
|
+
ipaddress: 10.0.3.204
|
346
|
+
products:
|
347
|
+
<%- unless product_versions['analytics'][:channel] == 'none' -%>
|
348
|
+
analytics:
|
349
|
+
channel: <%= product_versions['analytics'][:channel] %>
|
350
|
+
version: <%= product_versions['analytics'][:version] %>
|
351
|
+
<%- end -%>
|
352
|
+
<% end -%>
|
353
|
+
<% if options[:adhoc] -%>
|
354
|
+
|
355
|
+
adhoc:
|
356
|
+
servers:
|
357
|
+
adhoc.lxc:
|
358
|
+
ipaddress: 10.0.3.207
|
359
|
+
<% end -%>
|
360
|
+
)
|
361
|
+
|
362
|
+
dev_lxc_config = ERB.new(dev_lxc_template, nil, '-').result(binding)
|
363
|
+
if options[:filename]
|
364
|
+
mode = options[:append] ? 'a' : 'w'
|
365
|
+
IO.write(options[:filename], dev_lxc_config, mode: mode)
|
366
|
+
else
|
367
|
+
puts dev_lxc_config
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
desc "status [SERVER_NAME_REGEX]", "Show status of servers"
|
372
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
373
|
+
def status(server_name_regex=nil)
|
374
|
+
cluster = get_cluster(options[:config])
|
375
|
+
if cluster.config['chef-server'][:topology] == "tier" && cluster.config['chef-server'][:fqdn]
|
376
|
+
printf "Chef Server FQDN: %s\n\n", cluster.config['chef-server'][:fqdn]
|
377
|
+
end
|
378
|
+
if cluster.config['chef-backend'][:fqdn]
|
379
|
+
printf "Chef Server FQDN: %s\n\n", cluster.config['chef-backend'][:fqdn]
|
380
|
+
end
|
381
|
+
if cluster.config['analytics'][:topology] == "tier" && cluster.config['analytics'][:fqdn]
|
382
|
+
printf "Analytics FQDN: %s\n\n", cluster.config['analytics'][:fqdn]
|
383
|
+
end
|
384
|
+
servers = Array.new
|
385
|
+
cluster.get_sorted_servers(server_name_regex).map { |s| servers << s.status }
|
386
|
+
max_server_name_length = servers.max_by { |s| s['name'].length }['name'].length unless servers.empty?
|
387
|
+
servers.each_with_index do |s, server_index|
|
388
|
+
printf "%-#{max_server_name_length}s %-15s %s\n", s['name'], s['state'].upcase, s['ip_addresses']
|
389
|
+
server = cluster.get_server(s['name'])
|
390
|
+
server.snapshot_list.each do |snapname, snaptime, snap_comment|
|
391
|
+
printf " |_ %s %s %s\n", snapname, snaptime, snap_comment
|
392
|
+
end
|
393
|
+
puts if server_index + 1 < servers.length
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
desc "attach [SERVER_NAME_REGEX]", "Attach the terminal to a single server"
|
398
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
399
|
+
def attach(server_name_regex)
|
400
|
+
servers = get_cluster(options[:config]).get_sorted_servers(server_name_regex)
|
401
|
+
if servers.length > 1
|
402
|
+
puts "ERROR: The following servers matched '#{server_name_regex}'"
|
403
|
+
servers.map { |s| puts " #{s.name}" }
|
404
|
+
puts " Please specify a single server to attach to"
|
405
|
+
exit 1
|
406
|
+
elsif servers.empty?
|
407
|
+
puts "ERROR: No servers matched '#{server_name_regex}'"
|
408
|
+
puts " Please specify a single server to attach to"
|
409
|
+
exit 1
|
410
|
+
end
|
411
|
+
container = servers.first.container
|
412
|
+
if !container.defined? || !container.running?
|
413
|
+
puts "ERROR: Server '#{container.name}' is not running"
|
414
|
+
exit 1
|
415
|
+
end
|
416
|
+
attach_opts = {
|
417
|
+
wait: true,
|
418
|
+
env_policy: LXC::LXC_ATTACH_CLEAR_ENV,
|
419
|
+
extra_env_vars: ["LANG=en_US.UTF-8", "TERM=linux", "HOME=#{ENV['HOME']}"]
|
420
|
+
}
|
421
|
+
shell = ENV['SHELL']
|
422
|
+
container.attach(attach_opts) { system(shell) }
|
423
|
+
end
|
424
|
+
|
425
|
+
desc "chef-repo", "Creates a '.chef' directory in the current directory using files from the cluster's backend /root/chef-repo/.chef"
|
426
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
427
|
+
option :force, :aliases => "-f", :type => :boolean, :desc => "Overwrite any existing knife.rb or pivotal.rb files"
|
428
|
+
option :pivotal, :aliases => "-p", :type => :boolean, :desc => "Also copy pivotal.rb and pivotal.pem"
|
429
|
+
def chef_repo
|
430
|
+
get_cluster(options[:config]).chef_repo(options[:force], options[:pivotal])
|
431
|
+
end
|
432
|
+
|
433
|
+
desc "print-automate-credentials", "Print Automate credentials"
|
434
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
435
|
+
def print_automate_credentials
|
436
|
+
get_cluster(options[:config]).print_automate_credentials
|
437
|
+
end
|
438
|
+
|
439
|
+
desc "run-command [SERVER_NAME_REGEX] [COMMAND]", "Runs a command in each server"
|
440
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
441
|
+
def run_command(server_name_regex=nil, command)
|
442
|
+
start_time = Time.now
|
443
|
+
get_cluster(options[:config]).get_sorted_servers(server_name_regex).each { |s| s.run_command(command); puts }
|
444
|
+
print_elapsed_time(Time.now - start_time)
|
445
|
+
end
|
446
|
+
|
447
|
+
desc "prepare-product-cache [SERVER_NAME_REGEX]", "Download required product packages to cache"
|
448
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
449
|
+
def prepare_product_cache(server_name_regex=nil)
|
450
|
+
start_time = Time.now
|
451
|
+
cluster = get_cluster(options[:config])
|
452
|
+
servers = cluster.get_sorted_servers(server_name_regex)
|
453
|
+
cluster.prep_product_cache(servers, true)
|
454
|
+
print_elapsed_time(Time.now - start_time)
|
455
|
+
end
|
456
|
+
|
457
|
+
desc "up [SERVER_NAME_REGEX]", "Start servers - This is the default if no subcommand is given"
|
458
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
459
|
+
def up(server_name_regex=nil)
|
460
|
+
start_time = Time.now
|
461
|
+
get_cluster(options[:config]).up(server_name_regex)
|
462
|
+
print_elapsed_time(Time.now - start_time)
|
463
|
+
end
|
464
|
+
|
465
|
+
desc "halt [SERVER_NAME_REGEX]", "Shutdown servers"
|
466
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
467
|
+
def halt(server_name_regex=nil)
|
468
|
+
start_time = Time.now
|
469
|
+
get_cluster(options[:config]).halt(server_name_regex)
|
470
|
+
print_elapsed_time(Time.now - start_time)
|
471
|
+
end
|
472
|
+
|
473
|
+
desc "snapshot [SERVER_NAME_REGEX]", "Manage a cluster's snapshots"
|
474
|
+
option :comment, :aliases => "-c", :desc => "Add snapshot comment"
|
475
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
476
|
+
option :destroy, :aliases => "-d", :desc => "Destroy snapshot - use ALL to destroy all snapshots"
|
477
|
+
option :list, :aliases => "-l", :type => :boolean, :desc => "List snapshots"
|
478
|
+
option :restore, :aliases => "-r", :desc => "Restore snapshots"
|
479
|
+
def snapshot(server_name_regex=nil)
|
480
|
+
start_time = Time.now
|
481
|
+
servers = get_cluster(options[:config]).get_sorted_servers(server_name_regex)
|
482
|
+
if options[:list]
|
483
|
+
servers.each_with_index do |s, server_index|
|
484
|
+
puts s.name
|
485
|
+
s.snapshot_list.each do |snapname, snaptime, snap_comment|
|
486
|
+
printf " |_ %s %s %s\n", snapname, snaptime, snap_comment
|
487
|
+
end
|
488
|
+
puts if server_index + 1 < servers.length
|
489
|
+
end
|
490
|
+
return
|
491
|
+
elsif options[:destroy]
|
492
|
+
snapname = options[:destroy] == 'destroy' ? "LAST" : options[:destroy]
|
493
|
+
servers.each { |s| s.snapshot_destroy(snapname); puts }
|
494
|
+
elsif options[:restore]
|
495
|
+
running_servers = Array.new
|
496
|
+
servers.each do |s|
|
497
|
+
running_servers << s.name if s.container.running?
|
498
|
+
end
|
499
|
+
unless running_servers.empty?
|
500
|
+
puts "ERROR: Aborting snapshot restore because the following servers are running"
|
501
|
+
puts running_servers
|
502
|
+
exit 1
|
503
|
+
end
|
504
|
+
snapname = options[:restore] == 'restore' ? "LAST" : options[:restore]
|
505
|
+
servers.each { |s| s.snapshot_restore(snapname); puts }
|
506
|
+
else
|
507
|
+
running_servers = Array.new
|
508
|
+
servers.each do |s|
|
509
|
+
running_servers << s.name if s.container.running?
|
510
|
+
end
|
511
|
+
unless running_servers.empty?
|
512
|
+
puts "ERROR: Aborting snapshot because the following servers are running"
|
513
|
+
puts running_servers
|
514
|
+
exit 1
|
515
|
+
end
|
516
|
+
servers.each { |s| s.snapshot(options[:comment]); puts }
|
517
|
+
end
|
518
|
+
print_elapsed_time(Time.now - start_time)
|
519
|
+
end
|
520
|
+
|
521
|
+
desc "destroy [SERVER_NAME_REGEX]", "Destroy servers"
|
522
|
+
option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
|
523
|
+
option :force, :aliases => "-f", :type => :boolean, :desc => "Destroy servers without confirmation"
|
524
|
+
def destroy(server_name_regex=nil)
|
525
|
+
servers = get_cluster(options[:config]).get_sorted_servers(server_name_regex)
|
526
|
+
if servers.empty?
|
527
|
+
puts "No matching server names were found"
|
528
|
+
exit
|
529
|
+
end
|
530
|
+
unless options[:force]
|
531
|
+
confirmation_string = String.new
|
532
|
+
servers.reverse_each { |s| confirmation_string += "#{s.name}\n" }
|
533
|
+
confirmation_string += "Are you sure you want to destroy these servers? (y/N)\n"
|
534
|
+
return unless yes?(confirmation_string)
|
535
|
+
end
|
536
|
+
start_time = Time.now
|
537
|
+
get_cluster(options[:config]).destroy(server_name_regex)
|
538
|
+
print_elapsed_time(Time.now - start_time)
|
539
|
+
end
|
540
|
+
|
541
|
+
end
|
542
|
+
end
|