Class: TestLab::Provisioner::AptCacherNG

Inherits:
Object
  • Object
show all
Defined in:
lib/testlab/provisioners/apt_cacher_ng.rb

Overview

AptCacherNG Provisioner Class

Author:

  • Zachary Patten <zachary AT jovelabs DOT com>

Instance Method Summary collapse

Constructor Details

#initialize(config = {}, ui = nil) ⇒ AptCacherNG

Returns a new instance of AptCacherNG.



13
14
15
16
17
18
19
20
21
22
# File 'lib/testlab/provisioners/apt_cacher_ng.rb', line 13

def initialize(config={}, ui=nil)
  @config = (config || Hash.new)
  @ui     = (ui     || TestLab.ui)

  @config[:apt] ||= Hash.new
  @config[:apt][:cacher_ng] ||= Hash.new
  @config[:apt][:cacher_ng][:exclude_hosts] ||= Array.new

  @ui.logger.debug { "config(#{@config.inspect})" }
end

Instance Method Details

#on_container_provision(container) ⇒ Boolean

APT-CacherNG: Container Provision

Parameters:

Returns:

  • (Boolean)

    True if successful.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/testlab/provisioners/apt_cacher_ng.rb', line 61

def on_container_provision(container)
  @ui.logger.debug { "APT-CacherNG Provisioner: Container #{container.id}" }

  # Ensure the container APT calls use apt-cacher-ng on the node
  gateway_ip                     = container.primary_interface.network.ip

  @config[:apt][:cacher_ng] = { :proxy_url => "http://#{gateway_ip}:3142" }.merge(@config[:apt][:cacher_ng])

  container.file(:target => apt_conf_d_proxy_file, :chown => "root:root", :chmod => "0644") do |file|
    file.puts(ZTK::Template.render(apt_conf_d_proxy_file_template, @config))
  end

  # Fix the APT sources since LXC mudges them when using apt-cacher-ng
  container.exec(%(sudo sed -i 's/127.0.0.1:3142\\///g' /etc/apt/sources.list))
end

#on_node_provision(node) ⇒ Boolean

APT-CacherNG: Node Provision

Parameters:

Returns:

  • (Boolean)

    True if successful.



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
# File 'lib/testlab/provisioners/apt_cacher_ng.rb', line 28

def on_node_provision(node)
  @ui.logger.debug { "APT-CacherNG Provisioner: Node #{node.id}" }

  node.bootstrap(ZTK::Template.render(provision_template, @config))

  context = {
    :apt => {
      :cacher_ng => {
        :proxy_url => "http://127.0.0.1:3142",
        :exclude_hosts => Array.new
      }
    }
  }

  node.file(:target => apt_conf_d_proxy_file, :chown => "root:root", :chmod => "0644") do |file|
    file.puts(ZTK::Template.render(apt_conf_d_proxy_file_template, context))
  end

  node.exec(%(sudo mkdir -pv #{File.dirname(apt_cacher_ng_security_conf_file)}))
  node.file(:target => apt_cacher_ng_security_conf_file, :chown => "root:root", :chmod => "0644") do |file|
    file.puts(ZTK::Template.render(apt_cacher_ng_security_conf_template, context))
  end

  node.exec(%(sudo service apt-cacher-ng restart))

  true
end