class TestLab::Provisioner::Route

Route Provisioner Class

@author Zachary Patten <zachary AT jovelabs DOT com>

Public Class Methods

new(config={}, ui=nil) click to toggle source
# File lib/testlab/provisioners/route.rb, line 14
def initialize(config={}, ui=nil)
  @config = (config || Hash.new)
  @ui     = (ui     || TestLab.ui)

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

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

Public Instance Methods

on_network_destroy(network)
Alias for: on_network_down
on_network_down(network) click to toggle source

Route: Network Down

# File lib/testlab/provisioners/route.rb, line 31
def on_network_down(network)
  manage_route(:del, network)

  true
end
Also aliased as: on_network_destroy
on_network_up(network) click to toggle source

Route: Network Up

# File lib/testlab/provisioners/route.rb, line 24
def on_network_up(network)
  manage_route(:add, network)

  true
end
on_node_destroy(node)
Alias for: on_node_down
on_node_down(node) click to toggle source

Route: Node Down

# File lib/testlab/provisioners/route.rb, line 39
def on_node_down(node)
  node.networks.each do |network|
    manage_route(:del, network)
  end

  true
end
Also aliased as: on_node_destroy

Private Instance Methods

manage_route(action, network) click to toggle source
# File lib/testlab/provisioners/route.rb, line 50
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