Sha256: d24a81c4b03e2a2aa95f1930e57770f3725b401284fb02236ff1030c7b300ce8

Contents?: true

Size: 1.9 KB

Versions: 16

Compression:

Stored size: 1.9 KB

Contents

class TestLab

  class Provisioner

    # Resolv Provisioner Error Class
    class ResolvError < ProvisionerError; end

    # Resolv Provisioner Class
    #
    # @author Zachary Patten <zachary AT jovelabs DOT com>
    class Resolv

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

        @config[:resolv] ||= Hash.new

        @config[:resolv][:servers] ||= Array.new
        @config[:resolv][:servers].unshift([TestLab::Network.ips]).flatten!.compact!

        @config[:resolv][:search] ||= Array.new
        @config[:resolv][:search].unshift([TestLab::Container.domains]).flatten!.compact!

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

      # Resolv: Node Provision
      #
      # @param [TestLab::Node] node The node which we want to provision.
      # @return [Boolean] True if successful.
      def on_node_provision(node)
        @ui.logger.debug { "RESOLV Provisioner: Node #{node.id}" }

        @config[:resolv].merge!(
          :servers => %w(127.0.0.1),
          :object => :node
        )

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

        true
      end

      # Resolv: Container Provision
      #
      # @param [TestLab::Container] container The container which we want to
      #   provision.
      # @return [Boolean] True if successful.
      def on_container_provision(container)
        @ui.logger.debug { "RESOLV Provisioner: Container #{container.id}" }

        @config[:resolv].merge!(
          :object => :container
        )

        script = ZTK::Template.render(provision_template, @config)
        container.lxc.attach(%(-- /bin/bash -c '#{script}'))

        true
      end
      alias :on_container_up :on_container_provision

    private

      def provision_template
        File.join(TestLab::Provisioner.template_dir, 'resolv', 'provision.erb')
      end

    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
testlab-1.22.4 lib/testlab/provisioners/resolv.rb
testlab-1.22.3 lib/testlab/provisioners/resolv.rb
testlab-1.22.2 lib/testlab/provisioners/resolv.rb
testlab-1.22.1 lib/testlab/provisioners/resolv.rb
testlab-1.22.0 lib/testlab/provisioners/resolv.rb
testlab-1.21.1 lib/testlab/provisioners/resolv.rb
testlab-1.21.0 lib/testlab/provisioners/resolv.rb
testlab-1.20.6 lib/testlab/provisioners/resolv.rb
testlab-1.20.5 lib/testlab/provisioners/resolv.rb
testlab-1.20.4 lib/testlab/provisioners/resolv.rb
testlab-1.20.3 lib/testlab/provisioners/resolv.rb
testlab-1.20.2 lib/testlab/provisioners/resolv.rb
testlab-1.20.1 lib/testlab/provisioners/resolv.rb
testlab-1.20.0 lib/testlab/provisioners/resolv.rb
testlab-1.19.0 lib/testlab/provisioners/resolv.rb
testlab-1.18.1 lib/testlab/provisioners/resolv.rb