Sha256: 27d446bd4f3a78ab52afd3bb69600b8f1ddc11294f41fc29e445ea53cec20366

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

class TestLab

  class Provisioner

    # Route Provisioner Error Class
    class RouteError < ProvisionerError; end

    # Route Provisioner Class
    #
    # @author Zachary Patten <zachary AT jovelabs DOT com>
    class Route
      include TestLab::Utility::Misc

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

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

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

      # Route: Network Up
      def on_network_up(network)
        manage_route(:add, network)

        true
      end

      # Route: Network Down
      def on_network_down(network)
        manage_route(:del, network)

        true
      end
      alias :on_network_destroy :on_network_down

      # Route: Node Down
      def on_node_down(node)
        node.networks.each do |network|
          manage_route(:del, network)
        end

        true
      end
      alias :on_node_destroy :on_node_down

    private

      def manage_route(action, network)
        command = ZTK::Command.new(:ui => @ui, :silence => true, :ignore_exit_status => true)

        case RUBY_PLATFORM
        when /darwin/ then
          action = ((action == :del) ? :delete : :add)
          command.exec(%(#{sudo} route #{action} -net #{TestLab::Utility.network(network.address)} #{network.node.ip} #{TestLab::Utility.netmask(network.address)}))
        when /linux/ then
          command.exec(%(#{sudo} route #{action} -net #{TestLab::Utility.network(network.address)} netmask #{TestLab::Utility.netmask(network.address)} gw #{network.node.ip}))
        end
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
testlab-1.22.4 lib/testlab/provisioners/route.rb
testlab-1.22.3 lib/testlab/provisioners/route.rb
testlab-1.22.2 lib/testlab/provisioners/route.rb
testlab-1.22.1 lib/testlab/provisioners/route.rb
testlab-1.22.0 lib/testlab/provisioners/route.rb