dev-lxc 2.3.0 → 2.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80dd5ce814277d70504316af75ab5a801489356a
4
- data.tar.gz: 62c7bb81010529e775615c8e31da47b1360686c4
3
+ metadata.gz: 380d44e7d8a00e55126697a912e6137dfa5fdd07
4
+ data.tar.gz: 51efc2c299e10e4ebd8df1e8ac2f0407ce122c72
5
5
  SHA512:
6
- metadata.gz: b4ce050e1637a22d0dc990560ebf43b39527600bdacf6a048b01a37e8aa45505c327255f59c45f4829576d07c45ea8cf74dd15497e243a638cc90d71eec91c69
7
- data.tar.gz: 62b58c1d3956bed13dd7c08a819ac73abaced1cf76e8c7dbe82f055bd3af2e485523b62dfeac5e8f6816b1b79d9d810f2d55cf9131c1cffb87da9acc546ca36f
6
+ metadata.gz: cb04423d93d681ea9830d5b11bb5ed3c4cbbc9f1dc5e9c3f85d91683b5110c0fa1d630a7bb8dfb9dbe9e26a0ced508c6675c9369405c122a4cce8e0cb733d28d
7
+ data.tar.gz: f7ad42408a5123e111f622ba7c138af98c9e3c00d05e6b627aed85a8cde85e0ac35d49c673c3a5f203bc5922c1c02c4cdacccd270a1310088537d18f26648ae5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # dev-lxc Change Log
2
2
 
3
+ ## 2.3.1 (2016-11-28)
4
+
5
+ * Create DevLXC::Cluster.abort_up to help with code clarity
6
+ * Shutdown container gracefully instead of doing a hard stop
7
+ * Skip container start if it is already running
8
+ * Refactor DevLXC.assign_ip_address to DevLXC::Server.assign_static_ip_address
9
+ * Change DevLXC::Server.deregister_from_dhcp to DevLXC::Server.remove_static_ip_address
10
+ * Remove dhcp release post-stop hook since it is not the most reliable solution
11
+ * Remove lingering DHCP IP addresses before starting a server
12
+ * Remove lingering DHCP IP addresses after destroying or shutting down a server
13
+ * Comment out data_collector config in a node's client.rb
14
+ * Add a clarifying comment to DevLXC::Cluster.up
15
+
3
16
  ## 2.3.0 (2016-11-22)
4
17
 
5
18
  * Create DNS records for all servers before starting a server
data/lib/dev-lxc/cli.rb CHANGED
@@ -343,7 +343,7 @@ nodes:
343
343
  print_elapsed_time(Time.now - start_time)
344
344
  end
345
345
 
346
- desc "halt [SERVER_NAME_REGEX]", "Stop servers"
346
+ desc "halt [SERVER_NAME_REGEX]", "Shutdown servers"
347
347
  option :config, :desc => "Specify a cluster's YAML config file. `./dev-lxc.yml` will be used by default"
348
348
  def halt(server_name_regex=nil)
349
349
  start_time = Time.now
@@ -315,7 +315,7 @@ module DevLXC
315
315
 
316
316
  def halt(server_name_regex=nil)
317
317
  servers = get_sorted_servers(server_name_regex)
318
- servers.reverse_each { |s| s.stop; puts }
318
+ servers.reverse_each { |s| s.shutdown; puts }
319
319
  delete_dns_records unless get_sorted_servers.any? { |s| s.container.state != :stopped }
320
320
  end
321
321
 
@@ -325,9 +325,68 @@ module DevLXC
325
325
  end
326
326
 
327
327
  def up(server_name_regex=nil)
328
- abort_up = false
329
328
  configured_servers = Array.new
330
329
  servers = get_sorted_servers(server_name_regex)
330
+ exit 1 if abort_up(servers)
331
+ prep_product_cache(servers)
332
+ servers.each do |server|
333
+ clone_from_base_container(server) unless server.container.defined?
334
+ end
335
+ # get_sorted_servers is called again in order to ensure the container objects are initialized properly in case they were just cloned from the base container
336
+ servers = get_sorted_servers(server_name_regex)
337
+ create_dns_records unless servers.empty?
338
+ servers.each do |server|
339
+ if %w(build-nodes runners).include?(@server_configs[server.name][:server_type])
340
+ next if @server_configs[server.name][:required_products]["chefdk"] && @server_configs[server.name][:required_products].length == 1
341
+ end
342
+ install_products(server) unless @server_configs[server.name][:required_products].empty?
343
+ end
344
+ servers.each do |server|
345
+ if server.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: completed") }.empty?
346
+ if server.name == @config["chef-backend"][:bootstrap_frontend]
347
+ running_backends = Array.new
348
+ @config["chef-backend"][:backends].reverse_each do |server_name|
349
+ backend = get_server(server_name)
350
+ if backend.container.defined? && backend.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: backend cluster configured but frontend not bootstrapped") }.empty?
351
+ if backend.container.running?
352
+ running_backends << backend.name
353
+ backend.shutdown
354
+ end
355
+ backend.snapshot("dev-lxc build: backend cluster configured but frontend not bootstrapped")
356
+ snapshot = backend.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: completed") }.first
357
+ backend.snapshot_destroy(snapshot.first) if snapshot
358
+ end
359
+ end
360
+ @config["chef-backend"][:backends].each do |server_name|
361
+ if running_backends.include?(server_name)
362
+ get_server(server_name).start
363
+ configured_servers << server_name unless configured_servers.include?(server_name)
364
+ end
365
+ end
366
+ end
367
+ configure_products(server)
368
+ configured_servers << server.name
369
+ end
370
+ if server.container.running?
371
+ puts "Container '#{server.name}' is already running"
372
+ puts
373
+ else
374
+ server.start
375
+ end
376
+ end
377
+ configured_servers.reverse_each do |server_name|
378
+ server = get_server(server_name)
379
+ server.shutdown if server.container.running?
380
+ server.snapshot("dev-lxc build: completed")
381
+ end
382
+ configured_servers.each do |server_name|
383
+ server = get_server(server_name)
384
+ server.start if server.container.defined?
385
+ end
386
+ end
387
+
388
+ def abort_up(servers)
389
+ abort_up = false
331
390
  servers.each do |server|
332
391
  next if server.container.defined?
333
392
  if (@config['chef-server'][:frontends] && @config['chef-server'][:frontends].include?(server.name)) || server.name == @config['analytics'][:bootstrap_backend]
@@ -424,56 +483,7 @@ module DevLXC
424
483
  end
425
484
  end
426
485
  end
427
- exit 1 if abort_up
428
- prep_product_cache(servers)
429
- servers.each do |server|
430
- clone_from_base_container(server) unless server.container.defined?
431
- end
432
- servers = get_sorted_servers(server_name_regex)
433
- create_dns_records unless servers.empty?
434
- servers.each do |server|
435
- if %w(build-nodes runners).include?(@server_configs[server.name][:server_type])
436
- next if @server_configs[server.name][:required_products]["chefdk"] && @server_configs[server.name][:required_products].length == 1
437
- end
438
- install_products(server) unless @server_configs[server.name][:required_products].empty?
439
- end
440
- servers.each do |server|
441
- if server.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: completed") }.empty?
442
- if server.name == @config["chef-backend"][:bootstrap_frontend]
443
- running_backends = Array.new
444
- @config["chef-backend"][:backends].reverse_each do |server_name|
445
- backend = get_server(server_name)
446
- if backend.container.defined? && backend.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: backend cluster configured but frontend not bootstrapped") }.empty?
447
- if backend.container.running?
448
- running_backends << backend.name
449
- backend.stop
450
- end
451
- backend.snapshot("dev-lxc build: backend cluster configured but frontend not bootstrapped")
452
- snapshot = backend.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: completed") }.first
453
- backend.snapshot_destroy(snapshot.first) if snapshot
454
- end
455
- end
456
- @config["chef-backend"][:backends].each do |server_name|
457
- if running_backends.include?(server_name)
458
- get_server(server_name).start
459
- configured_servers << server_name unless configured_servers.include?(server_name)
460
- end
461
- end
462
- end
463
- configure_products(server)
464
- configured_servers << server.name
465
- end
466
- server.start unless server.container.running?
467
- end
468
- configured_servers.reverse_each do |server_name|
469
- server = get_server(server_name)
470
- server.stop if server.container.running?
471
- server.snapshot("dev-lxc build: completed")
472
- end
473
- configured_servers.each do |server_name|
474
- server = get_server(server_name)
475
- server.start if server.container.defined?
476
- end
486
+ return abort_up
477
487
  end
478
488
 
479
489
  def create_dns_records
@@ -498,9 +508,6 @@ module DevLXC
498
508
  server.container.load_config
499
509
  puts "Deleting SSH Server Host Keys"
500
510
  FileUtils.rm_f(Dir.glob("#{server.container.config_item('lxc.rootfs')}/etc/ssh/ssh_host*_key*"))
501
- puts "Adding lxc.hook.post-stop hook"
502
- server.container.set_config_item("lxc.hook.post-stop", "/usr/local/share/lxc/hooks/post-stop-dhcp-release")
503
- server.container.save_config
504
511
  end
505
512
 
506
513
  def get_product_download_info(server, product_name, product_options)
@@ -605,14 +612,14 @@ module DevLXC
605
612
  next if %w(build-nodes runners).include?(@server_configs[server.name][:server_type]) && product_name == "chefdk"
606
613
  server.install_package(package_source)
607
614
  end
608
- server.stop
615
+ server.shutdown
609
616
  server.snapshot("dev-lxc build: products installed")
610
617
  server.start if server_was_running
611
618
  end
612
619
 
613
620
  def configure_products(server)
614
621
  puts "Configuring container '#{server.name}'"
615
- server.start unless server.container.running?
622
+ server.start
616
623
  required_products = @server_configs[server.name][:required_products].keys if @server_configs[server.name][:required_products]
617
624
  required_products ||= Array.new
618
625
  server_type = @server_configs[server.name][:server_type]
@@ -770,8 +777,8 @@ ssl_verify_mode :verify_none
770
777
  automate_server_name = @server_configs.select {|name, config| config[:server_type] == 'automate'}.keys.first
771
778
  if automate_server_name
772
779
  client_rb += %Q(
773
- data_collector.server_url "https://#{automate_server_name}/data-collector/v0/"
774
- data_collector.token "93a49a4f2482c64126f7b6015e6b0f30284287ee4054ff8807fb63d9cbd1c506"
780
+ # data_collector.server_url "https://#{automate_server_name}/data-collector/v0/"
781
+ # data_collector.token "93a49a4f2482c64126f7b6015e6b0f30284287ee4054ff8807fb63d9cbd1c506"
775
782
  )
776
783
  end
777
784
 
@@ -31,14 +31,14 @@ module DevLXC
31
31
  end
32
32
  end
33
33
 
34
- def stop
35
- puts "Stopping container '#{self.name}'"
34
+ def shutdown
35
+ puts "Shutting down container '#{self.name}'"
36
36
  super
37
- wait("STOPPED", 3)
37
+ wait(:stopped, 3)
38
38
  end
39
39
 
40
40
  def destroy
41
- stop if running?
41
+ shutdown if running?
42
42
  puts "Destroying container '#{self.name}'"
43
43
  super if self.defined?
44
44
  end
@@ -35,18 +35,21 @@ module DevLXC
35
35
  end
36
36
 
37
37
  def start
38
+ return if @container.running?
38
39
  hwaddr = @container.config_item("lxc.network.0.hwaddr")
39
- DevLXC.assign_ip_address(@ipaddress, @container.name, hwaddr) if @ipaddress
40
+ release_lingering_dhcp_ip_addresses(hwaddr)
41
+ assign_static_ip_address(hwaddr) if @ipaddress
40
42
  @container.sync_mounts(@mounts)
41
43
  @container.start
42
44
  @container.sync_ssh_keys(@ssh_keys)
43
45
  puts
44
46
  end
45
47
 
46
- def stop
48
+ def shutdown
47
49
  hwaddr = @container.config_item("lxc.network.0.hwaddr") if @container.defined?
48
- @container.stop
49
- deregister_from_dhcp(hwaddr)
50
+ @container.shutdown
51
+ remove_static_ip_address(hwaddr)
52
+ release_lingering_dhcp_ip_addresses(hwaddr)
50
53
  end
51
54
 
52
55
  def snapshot(comment=nil)
@@ -145,10 +148,38 @@ module DevLXC
145
148
  @container.snapshot_list.each { |snapshot| @container.snapshot_destroy(snapshot.first) }
146
149
  end
147
150
  @container.destroy
148
- deregister_from_dhcp(hwaddr)
151
+ remove_static_ip_address(hwaddr)
152
+ release_lingering_dhcp_ip_addresses(hwaddr)
149
153
  end
150
154
 
151
- def deregister_from_dhcp(hwaddr)
155
+ def release_lingering_dhcp_ip_addresses(hwaddr)
156
+ dhcp_leases = IO.readlines('/var/lib/misc/dnsmasq.lxcbr0.leases')
157
+ dhcp_leases.each do |dhcp_lease|
158
+ if m = dhcp_lease.match(/ #{hwaddr} (\d+\.\d+\.\d+\.\d+) /)
159
+ mac_addr = hwaddr
160
+ ip_addr = m[1]
161
+ elsif m = dhcp_lease.match(/ (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w) #{@ipaddress} /)
162
+ mac_addr = m[1]
163
+ ip_addr = @ipaddress
164
+ elsif m = dhcp_lease.match(/ (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w) (\d+\.\d+\.\d+\.\d+) #{@container.name.sub(/\.lxc$/, '')} /)
165
+ mac_addr = m[1]
166
+ ip_addr = m[2]
167
+ end
168
+ if mac_addr && ip_addr
169
+ puts "Releasing lingering DHCP lease: #{dhcp_lease}"
170
+ system("dhcp_release lxcbr0 #{ip_addr} #{mac_addr}")
171
+ end
172
+ end
173
+ end
174
+
175
+ def assign_static_ip_address(hwaddr)
176
+ puts "Assigning IP address #{@ipaddress} to '#{@container.name}' container's lxc.network.hwaddr #{hwaddr}"
177
+ DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /(^#{hwaddr}|,#{@ipaddress}$)/)
178
+ DevLXC.append_line_to_file("/etc/lxc/dhcp-hosts.conf", "#{hwaddr},#{@ipaddress}\n")
179
+ DevLXC.reload_dnsmasq
180
+ end
181
+
182
+ def remove_static_ip_address(hwaddr)
152
183
  if @ipaddress
153
184
  DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /,#{@ipaddress}$/)
154
185
  end
@@ -1,3 +1,3 @@
1
1
  module DevLXC
2
- VERSION = "2.3.0"
2
+ VERSION = "2.3.1"
3
3
  end
data/lib/dev-lxc.rb CHANGED
@@ -93,17 +93,10 @@ module DevLXC
93
93
 
94
94
  IO.write("#{base_container.config_item('lxc.rootfs')}/etc/sudoers.d/dev-lxc", "dev-lxc ALL=NOPASSWD:ALL\n")
95
95
  FileUtils.chmod(0440, "#{base_container.config_item('lxc.rootfs')}/etc/sudoers.d/dev-lxc")
96
- base_container.stop
96
+ base_container.shutdown
97
97
  return base_container
98
98
  end
99
99
 
100
- def self.assign_ip_address(ipaddress, container_name, hwaddr)
101
- puts "Assigning IP address #{ipaddress} to '#{container_name}' container's lxc.network.hwaddr #{hwaddr}"
102
- search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /(^#{hwaddr}|,#{ipaddress}$)/)
103
- append_line_to_file("/etc/lxc/dhcp-hosts.conf", "#{hwaddr},#{ipaddress}\n")
104
- reload_dnsmasq
105
- end
106
-
107
100
  def self.reload_dnsmasq
108
101
  system("pkill -HUP dnsmasq")
109
102
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev-lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremiah Snapp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-22 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler