class TestLab::Provisioner::HostsFile
HostsFile
Provisioner
Class
@author Zachary Patten <zachary AT jovelabs DOT com>
Public Class Methods
new(config={}, ui=nil)
click to toggle source
# File lib/testlab/provisioners/hosts_file.rb, line 14 def initialize(config={}, ui=nil) @config = (config || Hash.new) @ui = (ui || TestLab.ui) @command = ZTK::Command.new(:ui => @ui, :silence => true, :ignore_exit_status => true) @ui.logger.debug { "config(#{@config.inspect})" } end
Public Instance Methods
on_container_callback(container)
click to toggle source
HostsFile: Container
Provision
# File lib/testlab/provisioners/hosts_file.rb, line 23 def on_container_callback(container) remove_hosts(container) add_hosts(container) true end
Private Instance Methods
add_hosts(container)
click to toggle source
# File lib/testlab/provisioners/hosts_file.rb, line 39 def add_hosts(container) script = <<-EOF cat <<EOI | #{sudo} tee -a /etc/hosts #{hosts_blob(container)} EOI EOF tempfile = Tempfile.new('script') tempfile.write(script) tempfile.flush command = %(/bin/bash -x #{tempfile.path}) @command.exec(command) container.alive? and container.bootstrap(script) end
def_tag()
click to toggle source
NFS Exports Start Definition Tag
# File lib/testlab/provisioners/hosts_file.rb, line 82 def def_tag "#TESTLAB-HOSTSFILE" end
end_tag()
click to toggle source
NFS Exports End Definition Tag
# File lib/testlab/provisioners/hosts_file.rb, line 87 def end_tag "#TESTLAB-HOSTSFILE" end
hosts_blob(container)
click to toggle source
# File lib/testlab/provisioners/hosts_file.rb, line 61 def hosts_blob(container) blob = Array.new blob << def_tag container.node.containers.each do |con| blob << "#{con.primary_interface.ip}\t#{con.id} #{con.fqdn}" end blob << end_tag blob.join("\n") end
remove_hosts(container)
click to toggle source
# File lib/testlab/provisioners/hosts_file.rb, line 56 def remove_hosts(container) @command.exec(sed_hostsfile) container.alive? and container.exec(sed_hostsfile('linux')) end
sed_hostsfile(platform=RUBY_PLATFORM)
click to toggle source
# File lib/testlab/provisioners/hosts_file.rb, line 72 def sed_hostsfile(platform=RUBY_PLATFORM) case platform when /darwin/ then %(#{sudo} sed -i '' '/#{def_tag}/,/#{end_tag}/d' /etc/hosts) when /linux/ then %(#{sudo} sed -i '/#{def_tag}/,/#{end_tag}/d' /etc/hosts) end end