diff --git a/lib/landrush/cap/linux/read_host_visible_ip_address.rb b/lib/landrush/cap/linux/read_host_visible_ip_address.rb index acd9a96..ff3851b 100644 --- a/lib/landrush/cap/linux/read_host_visible_ip_address.rb +++ b/lib/landrush/cap/linux/read_host_visible_ip_address.rb @@ -22,7 +22,6 @@ module ReadHostVisibleIpAddress # TODO: Find a better heuristic for this implementation. # def self.read_host_visible_ip_address(machine) - command = "ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'" result = "" machine.communicate.execute(command) do |type, data| result << data if type == :stdout @@ -30,6 +29,10 @@ def self.read_host_visible_ip_address(machine) result.chomp.split("\n").last end + + def self.command + %Q(ip addr show | awk '$1=="inet" {print $2}' | cut -f1 -d'/' | tail -n1) + end end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index b4f5c6e..4fcb0c4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,7 @@ require 'minitest/spec' require 'landrush' +require 'landrush/cap/linux/read_host_visible_ip_address' require 'minitest/autorun' @@ -84,7 +85,7 @@ def fake_machine(options={}) machine.instance_variable_set("@communicator", RecordingCommunicator.new) machine.communicate.stub_command( - "ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'", + Landrush::Cap::Linux::ReadHostVisibleIpAddress.command, "#{options.fetch(:ip, '1.2.3.4')}\n" )