Skip to content

Commit

Permalink
Merge pull request vagrant-landrush#52 from njam/ip-instead-ifconfig
Browse files Browse the repository at this point in the history
Use "ip addr show" to detect ip address
  • Loading branch information
phinze committed Apr 10, 2014
2 parents 64f78ba + aa75169 commit 735c347
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/landrush/cap/linux/read_host_visible_ip_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ 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
end

result.chomp.split("\n").last
end

def self.command
%Q(hostname -I | awk -F' ' '{print $NF}')
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'minitest/spec'

require 'landrush'
require 'landrush/cap/linux/read_host_visible_ip_address'

require 'minitest/autorun'

Expand Down Expand Up @@ -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"
)

Expand Down

0 comments on commit 735c347

Please sign in to comment.