lib/commands/network.rb in testlab-1.4.4 vs lib/commands/network.rb in testlab-1.5.0
- old
+ new
@@ -28,18 +28,14 @@
c.long_desc <<-EOF
Displays the status of all networks or single/multiple networks if supplied via the ID parameter.
EOF
c.command :status do |status|
status.action do |global_options, options, args|
- networks = iterate_objects_by_name(options[:name], TestLab::Network).delete_if{ |network| network.node.dead? }
+ networks = iterate_objects_by_name(options[:name], TestLab::Network)
- if (networks.count == 0)
- @testlab.ui.stderr.puts("You either have no networks defined or dead nodes!".yellow)
- else
- ZTK::Report.new(:ui => @testlab.ui).list(networks, TestLab::Network::STATUS_KEYS) do |network|
- OpenStruct.new(network.status)
- end
+ ZTK::Report.new(:ui => @testlab.ui).list(networks, TestLab::Network::STATUS_KEYS) do |network|
+ OpenStruct.new(network.status)
end
end
end
# ROUTES
@@ -54,11 +50,10 @@
add.action do |global_options,options,args|
iterate_objects_by_name(options[:name], TestLab::Network) do |network|
p = TestLab::Provisioner::Route.new({}, @ui)
p.on_network_up(network)
@testlab.ui.stdout.puts("Added routes successfully!".green.bold)
- @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
end
end
end
# ROUTE DEL
@@ -68,26 +63,31 @@
del.action do |global_options,options,args|
iterate_objects_by_name(options[:name], TestLab::Network) do |network|
p = TestLab::Provisioner::Route.new({}, @ui)
p.on_network_down(network)
@testlab.ui.stdout.puts("Deleted routes successfully!".red.bold)
- @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
end
end
end
# ROUTE SHOW
#############
+
+ # Route show helper method because OSX sucks
+ def osx_network(net)
+ net.network.split('.').delete_if{ |o| o == '0' }.join('.')
+ end
+
route.desc 'Show routes to lab networks'
route.command :show do |show|
show.action do |global_options,options,args|
iterate_objects_by_name(options[:name], TestLab::Network) do |network|
- @testlab.ui.stdout.puts("TestLab routes:".green.bold)
+ @testlab.ui.stdout.puts("Routes for TestLab network '#{network.id}':".green.bold)
case RUBY_PLATFORM
when /darwin/ then
- @testlab.ui.stdout.puts %x(netstat -nrf inet | grep '#{network.node.ip}').strip
+ @testlab.ui.stdout.puts %x(netstat -nrf inet | grep '#{osx_network(network)}/#{network.cidr}').strip
when /linux/ then
- @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip
+ @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.network}').strip
end
end
end
end
end