lib/testlab/provisioners/bind.rb in testlab-1.0.1 vs lib/testlab/provisioners/bind.rb in testlab-1.1.0

- old
+ new

@@ -13,12 +13,14 @@ def initialize(config={}, ui=nil) @config = (config || Hash.new) @ui = (ui || TestLab.ui) @config[:bind] ||= Hash.new - @config[:bind][:domain] ||= "default.zone" + @config[:bind][:domain] ||= "tld.invalid" + @config[:bind][:forwarders] ||= %w(8.8.8.8 8.8.4.4) + @ui.logger.debug { "config(#{@config.inspect})" } end # Bind: Node Provision # @@ -35,15 +37,29 @@ # Bind: Node Deprovision # # @param [TestLab::Node] node The node which we want to deprovision. # @return [Boolean] True if successful. def on_node_deprovision(node) - node.ssh.exec(%(DEBIAN_FRONTEND="noninteractive" sudo apt-get -y purge bind9)) + @ui.logger.debug { "BIND Deprovisioner: Node #{node.id}" } + node.exec(%(sudo DEBIAN_FRONTEND="noninteractive" apt-get -y purge bind9)) + true end + # Bind: Container Up + # + # @param [TestLab::Node] node The container which just came online. + # @return [Boolean] True if successful. + def on_container_up(container) + @ui.logger.debug { "BIND Provisioner: Container #{container.id}" } + + bind_reload(container.node) + + true + end + # Bind: Network Up # # @param [TestLab::Network] network The network that is being onlined. # @return [Boolean] True if successful. def on_network_up(network) @@ -51,17 +67,18 @@ bind_reload(network.node) true end + alias :on_network_create :on_network_up # Builds the main bind configuration sections def build_bind_main_partial(file) bind_conf_template = File.join(TestLab::Provisioner.template_dir, "bind", "bind.erb") file.puts(ZTK::Template.do_not_edit_notice(:message => "TestLab v#{TestLab::VERSION} BIND Configuration", :char => '//')) - file.puts(ZTK::Template.render(bind_conf_template, {})) + file.puts(ZTK::Template.render(bind_conf_template, @config)) end def build_bind_records forward_records = Hash.new reverse_records = Hash.new @@ -80,11 +97,11 @@ end { :forward => forward_records, :reverse => reverse_records } end # Builds the bind configuration sections for our zones - def build_bind_zone_partial(ssh, file) + def build_bind_zone_partial(node, file) bind_zone_template = File.join(TestLab::Provisioner.template_dir, "bind", 'bind-zone.erb') bind_records = build_bind_records forward_records = bind_records[:forward] reverse_records = bind_records[:reverse] @@ -95,54 +112,54 @@ } file.puts file.puts(ZTK::Template.render(bind_zone_template, context)) - build_bind_db(ssh, network.arpa, reverse_records[network.id]) + build_bind_db(node, network.arpa, reverse_records[network.id]) end TestLab::Container.domains.each do |domain| context = { :zone => domain } file.puts file.puts(ZTK::Template.render(bind_zone_template, context)) - build_bind_db(ssh, domain, forward_records[domain]) + build_bind_db(node, domain, forward_records[domain]) end end - def build_bind_db(ssh, zone, records) + def build_bind_db(node, zone, records) bind_db_template = File.join(TestLab::Provisioner.template_dir, "bind", 'bind-db.erb') - ssh.file(:target => %(/etc/bind/db.#{zone}), :chown => "bind:bind") do |file| + node.file(:target => %(/etc/bind/db.#{zone}), :chown => "bind:bind") do |file| file.puts(ZTK::Template.do_not_edit_notice(:message => "TestLab v#{TestLab::VERSION} BIND DB: #{zone}", :char => ';')) file.puts(ZTK::Template.render(bind_db_template, { :zone => zone, :records => records })) end end # Builds the BIND configuration - def build_bind_conf(ssh) - ssh.file(:target => %(/etc/bind/named.conf), :chown => "bind:bind") do |file| + def build_bind_conf(node) + node.file(:target => %(/etc/bind/named.conf), :chown => "bind:bind") do |file| build_bind_main_partial(file) - build_bind_zone_partial(ssh, file) + build_bind_zone_partial(node, file) end end - def bind_install(ssh) - ssh.exec(%(DEBIAN_FRONTEND="noninteractive" sudo apt-get -y install bind9)) - ssh.exec(%(sudo rm -fv /etc/bind/{*.arpa,*.zone,*.conf*})) + def bind_install(node) + node.exec(%(sudo DEBIAN_FRONTEND="noninteractive" apt-get -y install bind9)) + node.exec(%(sudo rm -fv /etc/bind/{*.arpa,*.zone,*.conf*})) end def bind_reload(node) - node.ssh.exec(%(sudo chown -Rv bind:bind /etc/bind)) - node.ssh.exec(%(sudo rndc reload)) + node.exec(%(sudo chown -Rv bind:bind /etc/bind)) + node.exec(%(sudo rndc reload)) end def bind_provision(node) - bind_install(node.ssh) - build_bind_conf(node.ssh) + bind_install(node) + build_bind_conf(node) bind_reload(node) end end