Sha256: eeca4a48de715f289ca023832a3cf2ab476aac314bb930bb74b96394085ae3ad

Contents?: true

Size: 1.39 KB

Versions: 49

Compression:

Stored size: 1.39 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 Provision
      def on_network_up(network)
        manage_route(:add, network)

        true
      end

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

        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

49 entries across 49 versions & 1 rubygems

Version Path
testlab-1.17.0 lib/testlab/provisioners/route.rb
testlab-1.16.1 lib/testlab/provisioners/route.rb
testlab-1.16.0 lib/testlab/provisioners/route.rb
testlab-1.15.1 lib/testlab/provisioners/route.rb
testlab-1.15.0 lib/testlab/provisioners/route.rb
testlab-1.14.0 lib/testlab/provisioners/route.rb
testlab-1.13.0 lib/testlab/provisioners/route.rb
testlab-1.12.0 lib/testlab/provisioners/route.rb
testlab-1.11.7 lib/testlab/provisioners/route.rb
testlab-1.11.6 lib/testlab/provisioners/route.rb
testlab-1.11.5 lib/testlab/provisioners/route.rb
testlab-1.11.4 lib/testlab/provisioners/route.rb
testlab-1.11.3 lib/testlab/provisioners/route.rb
testlab-1.11.2 lib/testlab/provisioners/route.rb
testlab-1.11.1 lib/testlab/provisioners/route.rb
testlab-1.11.0 lib/testlab/provisioners/route.rb
testlab-1.10.0 lib/testlab/provisioners/route.rb
testlab-1.9.2 lib/testlab/provisioners/route.rb
testlab-1.9.1 lib/testlab/provisioners/route.rb
testlab-1.9.0 lib/testlab/provisioners/route.rb