dev-lxc 2.3.3 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3d3622dc2cfc2449d736e692894efcf01e38dea
4
- data.tar.gz: f10be9851cc3d1d2c15babe6fc9198916da6da0c
3
+ metadata.gz: c4d56770910d2c693b886f65c3b233d8aeca752a
4
+ data.tar.gz: b0e22969f25e6e3def0807322f5041ca51482bb8
5
5
  SHA512:
6
- metadata.gz: 85143d71647be27a0bbd80639561988b42c7e05ce4c4df58ae9498813fcddfeb099976a0cba4c5f6860fdbe8062572865a3a72e6ff47bc1ef872a2703169fcad
7
- data.tar.gz: cf90cd2fcf4303422cee16f5a927e8d63a73ae3df96dc9a634476aab685211ccda1573e6db9b3499d3b320ca7bbf633fcdd649628ec6ca29a0becec0dc2d2898
6
+ metadata.gz: b216fc333e7b71c654ae83ee247169be68cdb75dd072bb72f2e0bcf5e1a8f4fa66d1ebfcb26647ac80af92720d352c7cd6d880fd5f9560ba94c913b229b02946
7
+ data.tar.gz: 2520dc769f5320ec1fecf416ad0b223d0553c0f1b44591288e5efac1e860e0258534ddd0097d1bbd71a4d0ae824f98bab8e9b21db7caf44654693b04d5be64da
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # dev-lxc Change Log
2
2
 
3
+ ## 2.4.0 (2017-02-03)
4
+
5
+ * Refactor DHCP address management
6
+ * Add enable_build_snapshots config option
7
+ * Skip abort test if server exists AND "build: completed" snapshot exists
8
+ * Add auto-integration of Compliance and standalone Chef Server
9
+ * Remove period from sha256sum error message
10
+ * Reword message when base container already exists
11
+ * Update prerequisites.md
12
+
3
13
  ## 2.3.3 (2016-12-19)
4
14
 
5
15
  * Remove debug output from "dpkg -i"
@@ -14,6 +14,10 @@ dev-lxc init --chef --automate --supermarket --runners --nodes > dev-lxc.yml
14
14
  The contents of `dev-lxc.yml` should look like this.
15
15
 
16
16
  ```
17
+ # enable_build_snapshots automatically makes container snapshots at key times during the build process
18
+ # default value is `true`
19
+ #enable_build_snapshots: true
20
+
17
21
  # base_container must be the name of an existing container
18
22
  base_container: b-ubuntu-1404
19
23
 
@@ -92,7 +96,7 @@ As you can see there are four server types represented by five servers.
92
96
 
93
97
  #### Global Settings
94
98
 
95
- The global settings used by each of the server types are the `base_container`, a list of `mounts` and
99
+ The global settings used by each of the server types are `enable_build_snapshots`, the `base_container`, a list of `mounts` and
96
100
  a list of `ssh-keys`. These settings are described in the config comments.
97
101
 
98
102
  Be sure to set `base_container` in the `dev-lxc.yml` to an existing container's name.
@@ -102,7 +106,7 @@ If you don't already have a container to use as a `base_container` then you can
102
106
 
103
107
  #### Server Specific Settings
104
108
 
105
- It is possible to define different values for `base_container`, `mounts` or `ssh-keys` for a particular server type or even for a particular server as you can see in the following snippet.
109
+ It is possible to define different values for `enable_build_snapshots`, `base_container`, `mounts` or `ssh-keys` for a particular server type or even for a particular server as you can see in the following snippet.
106
110
 
107
111
  ```
108
112
  nodes:
@@ -11,7 +11,9 @@ Install the vagrant-persistent-storage plugin.
11
11
  vagrant plugin install vagrant-persistent-storage
12
12
  ```
13
13
 
14
- Download and install [ChefDK](http://downloads.chef.io/chef-dk/).
14
+ Download and install [ChefDK](http://downloads.chef.io/).
15
+
16
+ Run `chef shell-init` to read its usage docs. Then run the appropriate command for your shell.
15
17
 
16
18
  #### Download dev-lxc-platform
17
19
 
data/lib/dev-lxc.rb CHANGED
@@ -9,7 +9,7 @@ module DevLXC
9
9
  def self.create_base_container(base_container_name, base_container_options)
10
10
  base_container = DevLXC::Container.new(base_container_name)
11
11
  if base_container.defined?
12
- puts "Using existing base container '#{base_container.name}'"
12
+ puts "Base container '#{base_container.name}' already exists"
13
13
  return base_container
14
14
  end
15
15
  puts "Creating base container '#{base_container.name}'"
data/lib/dev-lxc/cli.rb CHANGED
@@ -60,7 +60,11 @@ module DevLXC::CLI
60
60
  option :append, :aliases => "-a", :type => :boolean, :desc => "Do not generate the global config header"
61
61
  option :filename, :aliases => "-f", :desc => "Write generated content to FILE rather than standard output."
62
62
  def init
63
- header = %Q(# base_container must be the name of an existing container
63
+ header = %Q(# enable_build_snapshots automatically makes container snapshots at key times during the build process
64
+ # default value is `true`
65
+ #enable_build_snapshots: true
66
+
67
+ # base_container must be the name of an existing container
64
68
  base_container: b-ubuntu-1404
65
69
 
66
70
  # list any host directories you want mounted into the servers
@@ -21,6 +21,11 @@ module DevLXC
21
21
  products = server_config['products']
22
22
  products ||= Hash.new
23
23
 
24
+ enable_build_snapshots = cluster_config[server_type]["enable_build_snapshots"]
25
+ enable_build_snapshots = cluster_config["enable_build_snapshots"] if enable_build_snapshots.nil?
26
+ enable_build_snapshots = server_config["enable_build_snapshots"] if server_config.key?("enable_build_snapshots")
27
+ enable_build_snapshots = true if enable_build_snapshots.nil?
28
+
24
29
  mounts = ["/var/dev-lxc var/dev-lxc"]
25
30
  if cluster_config[server_type]["mounts"]
26
31
  mounts.concat(cluster_config[server_type]["mounts"])
@@ -42,6 +47,8 @@ module DevLXC
42
47
  products: products,
43
48
  ipaddress: server_config['ipaddress'],
44
49
  additional_fqdn: nil,
50
+ enable_build_snapshots: enable_build_snapshots,
51
+ first_run: false,
45
52
  mounts: mounts,
46
53
  ssh_keys: ssh_keys,
47
54
  base_container_name: base_container_name
@@ -318,14 +325,18 @@ module DevLXC
318
325
  configured_servers = Array.new
319
326
  servers = get_sorted_servers(server_name_regex)
320
327
  exit 1 if abort_up(servers)
321
- prep_product_cache(servers)
322
328
  servers.each do |server|
323
- clone_from_base_container(server) unless server.container.defined?
329
+ unless server.container.defined?
330
+ clone_from_base_container(server)
331
+ @server_configs[server.name][:first_run] = true
332
+ end
324
333
  end
334
+ prep_product_cache(servers)
325
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
326
336
  servers = get_sorted_servers(server_name_regex)
327
337
  create_dns_records unless servers.empty?
328
338
  servers.each do |server|
339
+ next if ! @server_configs[server.name][:enable_build_snapshots] && ! @server_configs[server.name][:first_run]
329
340
  if %w(build-nodes runners).include?(@server_configs[server.name][:server_type])
330
341
  next if @server_configs[server.name][:required_products]["chefdk"] && @server_configs[server.name][:required_products].length == 1
331
342
  end
@@ -336,6 +347,7 @@ module DevLXC
336
347
  if server.name == @config["chef-backend"][:bootstrap_frontend]
337
348
  running_backends = Array.new
338
349
  @config["chef-backend"][:backends].reverse_each do |server_name|
350
+ next unless @server_configs[server_name][:enable_build_snapshots]
339
351
  backend = get_server(server_name)
340
352
  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?
341
353
  if backend.container.running?
@@ -348,14 +360,17 @@ module DevLXC
348
360
  end
349
361
  end
350
362
  @config["chef-backend"][:backends].each do |server_name|
363
+ next unless @server_configs[server_name][:enable_build_snapshots]
351
364
  if running_backends.include?(server_name)
352
365
  get_server(server_name).start
353
366
  configured_servers << server_name unless configured_servers.include?(server_name)
354
367
  end
355
368
  end
356
369
  end
357
- configure_products(server)
358
- configured_servers << server.name
370
+ if @server_configs[server.name][:enable_build_snapshots] || @server_configs[server.name][:first_run]
371
+ configure_products(server)
372
+ configured_servers << server.name
373
+ end
359
374
  end
360
375
  if server.container.running?
361
376
  puts "Container '#{server.name}' is already running"
@@ -365,11 +380,13 @@ module DevLXC
365
380
  end
366
381
  end
367
382
  configured_servers.reverse_each do |server_name|
383
+ next unless @server_configs[server_name][:enable_build_snapshots]
368
384
  server = get_server(server_name)
369
385
  server.shutdown if server.container.running?
370
386
  server.snapshot("dev-lxc build: completed")
371
387
  end
372
388
  configured_servers.each do |server_name|
389
+ next unless @server_configs[server_name][:enable_build_snapshots]
373
390
  server = get_server(server_name)
374
391
  server.start if server.container.defined?
375
392
  end
@@ -378,7 +395,17 @@ module DevLXC
378
395
  def abort_up(servers)
379
396
  abort_up = false
380
397
  servers.each do |server|
381
- next if server.container.defined?
398
+ next if server.container.defined? && !server.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: completed") }.empty?
399
+ next if ! @server_configs[server.name][:enable_build_snapshots] && ! @server_configs[server.name][:first_run]
400
+ if @server_configs[server.name][:server_type] == 'compliance' && @config["chef-server"][:topology] == "standalone"
401
+ if @config['chef-server'][:bootstrap_backend].nil?
402
+ puts "ERROR: '#{server.name}' requires a Chef Server bootstrap backend to be configured first."
403
+ abort_up = true
404
+ elsif !get_server(@config['chef-server'][:bootstrap_backend]).container.running? && servers.select { |s| s.name == @config['chef-server'][:bootstrap_backend] }.empty?
405
+ puts "ERROR: '#{server.name}' requires '#{@config['chef-server'][:bootstrap_backend]}' to be running first."
406
+ abort_up = true
407
+ end
408
+ end
382
409
  if (@config['chef-server'][:frontends] && @config['chef-server'][:frontends].include?(server.name)) || server.name == @config['analytics'][:bootstrap_backend]
383
410
  if @config['chef-server'][:bootstrap_backend].nil?
384
411
  puts "ERROR: '#{server.name}' requires a Chef Server bootstrap backend to be configured first."
@@ -545,6 +572,9 @@ module DevLXC
545
572
  elsif !force && !server.snapshot_list.select { |sn| sn[2].to_s.start_with?("dev-lxc build: completed") }.empty?
546
573
  # Skipping product cache preparation for container because it has a 'build: completed' snapshot
547
574
  next
575
+ elsif ! @server_configs[server.name][:enable_build_snapshots] && ! @server_configs[server.name][:first_run]
576
+ # Skipping product cache preparation for container because it build snapshots are disabled and this is not the container's first run
577
+ next
548
578
  end
549
579
  products.each do |product_name, product_options|
550
580
  if product_options && product_options['package_source']
@@ -574,7 +604,7 @@ module DevLXC
574
604
  open(package_source) { |url| File.open(product_cache_path, 'wb') { |f| f.write(url.read) } }
575
605
  end
576
606
  if package_sha256 != Digest::SHA256.file(product_cache_path).hexdigest
577
- puts "ERROR: Incorrect SHA256 for #{product_cache_path}."
607
+ puts "ERROR: Incorrect SHA256 for #{product_cache_path}"
578
608
  exit 1
579
609
  end
580
610
  elsif !File.exist?(package_source)
@@ -602,9 +632,11 @@ module DevLXC
602
632
  next if %w(build-nodes runners).include?(@server_configs[server.name][:server_type]) && product_name == "chefdk"
603
633
  server.install_package(package_source)
604
634
  end
605
- server.shutdown
606
- server.snapshot("dev-lxc build: products installed")
607
- server.start if server_was_running
635
+ if @server_configs[server.name][:enable_build_snapshots]
636
+ server.shutdown
637
+ server.snapshot("dev-lxc build: products installed")
638
+ server.start if server_was_running
639
+ end
608
640
  end
609
641
 
610
642
  def configure_products(server)
@@ -894,6 +926,31 @@ ssl_verify_mode :verify_none
894
926
  server.run_command("chef-compliance-ctl user-create #{admin_user} #{admin_user}")
895
927
  server.run_command("chef-compliance-ctl restart core")
896
928
  end
929
+
930
+ if @config["chef-server"][:topology] == "standalone"
931
+ chef_server = get_server(@config['chef-server'][:bootstrap_backend])
932
+ FileUtils.mkdir_p("#{chef_server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server")
933
+ FileUtils.mkdir_p("#{server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server")
934
+ IO.write("#{server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server/prepare-chef-compliance",
935
+ "chef-compliance-ctl connect chef-server --non-interactive true --chef-app-id 'compliance_server' --auth-id 'Chef Server' --insecure true --compliance-url 'https://#{server.name}'"
936
+ )
937
+ server.run_command("bash /root/integrate-compliance-with-chef-server/prepare-chef-compliance", "#{server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server/prepare-chef-compliance-output")
938
+ server.run_command("chef-compliance-ctl reconfigure")
939
+ server.run_command("chef-compliance-ctl restart core")
940
+ prepare_chef_compliance_output = IO.read("#{server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server/prepare-chef-compliance-output")
941
+ delimited_chef_server_command = prepare_chef_compliance_output.match(/\n---\n(.+)\n---/m)
942
+ if delimited_chef_server_command
943
+ IO.write("#{chef_server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server/configure-chef-server", delimited_chef_server_command[1])
944
+ chef_server.run_command("bash /root/integrate-compliance-with-chef-server/configure-chef-server", "#{chef_server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server/configure-chef-server-output")
945
+ end
946
+ configure_chef_server_output = IO.read("#{chef_server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server/configure-chef-server-output")
947
+ compliance_command = configure_chef_server_output.match(/^chef-compliance-ctl .+$/)
948
+ if compliance_command
949
+ IO.write("#{server.container.config_item('lxc.rootfs')}/root/integrate-compliance-with-chef-server/configure-chef-compliance", compliance_command)
950
+ server.run_command("bash /root/integrate-compliance-with-chef-server/configure-chef-compliance")
951
+ server.run_command("chef-compliance-ctl reconfigure")
952
+ end
953
+ end
897
954
  end
898
955
 
899
956
  def configure_supermarket(server)
@@ -47,10 +47,8 @@ module DevLXC
47
47
  end
48
48
 
49
49
  def shutdown
50
- hwaddr = @container.config_item("lxc.network.0.hwaddr") if @container.defined?
51
- @container.shutdown
52
- remove_static_ip_address(hwaddr)
53
- release_lingering_dhcp_ip_addresses(hwaddr)
50
+ @container.shutdown if @container.running?
51
+ remove_static_ip_address(@container.config_item("lxc.network.0.hwaddr")) if @container.defined?
54
52
  end
55
53
 
56
54
  def snapshot(comment=nil)
@@ -144,18 +142,16 @@ module DevLXC
144
142
  end
145
143
 
146
144
  def destroy
147
- if @container.defined?
148
- hwaddr = @container.config_item("lxc.network.0.hwaddr")
149
- @container.snapshot_list.each { |snapshot| @container.snapshot_destroy(snapshot.first) }
150
- end
145
+ return unless @container.defined?
146
+ @container.snapshot_list.each { |snapshot| @container.snapshot_destroy(snapshot.first) }
147
+ hwaddr = @container.config_item("lxc.network.0.hwaddr")
151
148
  @container.destroy
152
149
  remove_static_ip_address(hwaddr)
153
- release_lingering_dhcp_ip_addresses(hwaddr)
154
150
  end
155
151
 
156
152
  def release_lingering_dhcp_ip_addresses(hwaddr)
157
153
  dhcp_leases = IO.readlines('/var/lib/misc/dnsmasq.lxcbr0.leases')
158
- dhcp_leases.each do |dhcp_lease|
154
+ leases_to_release = dhcp_leases.map do |dhcp_lease|
159
155
  if m = dhcp_lease.match(/ #{hwaddr} (\d+\.\d+\.\d+\.\d+) /)
160
156
  mac_addr = hwaddr
161
157
  ip_addr = m[1]
@@ -167,10 +163,18 @@ module DevLXC
167
163
  ip_addr = m[2]
168
164
  end
169
165
  if mac_addr && ip_addr
170
- puts "Releasing lingering DHCP lease: #{dhcp_lease}"
171
- system("dhcp_release lxcbr0 #{ip_addr} #{mac_addr}")
166
+ { dhcp_lease: dhcp_lease, mac_addr: mac_addr, ip_addr: ip_addr }
172
167
  end
173
168
  end
169
+ leases_to_release.compact!
170
+ unless leases_to_release.empty?
171
+ system("systemctl stop lxc-net.service")
172
+ leases_to_release.each do |l|
173
+ puts "Releasing lingering DHCP lease: #{l[:dhcp_lease]}"
174
+ DevLXC.search_file_delete_line("/var/lib/misc/dnsmasq.lxcbr0.leases", /( #{l[:mac_addr]} #{l[:ip_addr]} )/)
175
+ end
176
+ system("systemctl start lxc-net.service")
177
+ end
174
178
  end
175
179
 
176
180
  def assign_static_ip_address(hwaddr)
@@ -180,14 +184,11 @@ module DevLXC
180
184
  DevLXC.reload_dnsmasq
181
185
  end
182
186
 
183
- def remove_static_ip_address(hwaddr)
184
- if @ipaddress
185
- DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /,#{@ipaddress}$/)
186
- end
187
- unless hwaddr.nil?
187
+ def remove_static_ip_address(hwaddr=nil)
188
+ if hwaddr
188
189
  DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /^#{hwaddr}/)
190
+ DevLXC.reload_dnsmasq
189
191
  end
190
- DevLXC.reload_dnsmasq
191
192
  end
192
193
 
193
194
  end
@@ -1,3 +1,3 @@
1
1
  module DevLXC
2
- VERSION = "2.3.3"
2
+ VERSION = "2.4.0"
3
3
  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.3
4
+ version: 2.4.0
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-12-19 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler