Sha256: 069ce7ad6888f643f3c051f1c47459d0d090310dddb4343699b3d801c3943ecc

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 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

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

        true
      end

    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

12 entries across 12 versions & 1 rubygems

Version Path
testlab-1.21.1 lib/testlab/provisioners/route.rb
testlab-1.21.0 lib/testlab/provisioners/route.rb
testlab-1.20.6 lib/testlab/provisioners/route.rb
testlab-1.20.5 lib/testlab/provisioners/route.rb
testlab-1.20.4 lib/testlab/provisioners/route.rb
testlab-1.20.3 lib/testlab/provisioners/route.rb
testlab-1.20.2 lib/testlab/provisioners/route.rb
testlab-1.20.1 lib/testlab/provisioners/route.rb
testlab-1.20.0 lib/testlab/provisioners/route.rb
testlab-1.19.0 lib/testlab/provisioners/route.rb
testlab-1.18.1 lib/testlab/provisioners/route.rb
testlab-1.18.0 lib/testlab/provisioners/route.rb