guests/gentoo: Use shared cap for listing network interfaces

This commit is contained in:
Seth Vargo 2016-06-26 11:41:16 -04:00
parent 8fe47b79c2
commit e2becda89d
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
2 changed files with 3 additions and 7 deletions

View File

@ -12,15 +12,11 @@ module VagrantPlugins
comm = machine.communicate
commands = []
interfaces = []
interfaces = machine.guest.capability(:network_interfaces, "/bin/ip")
# Remove any previous network additions to the configuration file.
commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net"
comm.sudo("ifconfig -a | grep -o ^[0-9a-z]* | grep -v '^lo'") do |_, stdout|
interfaces = stdout.split("\n")
end
networks.each_with_index do |network, i|
network[:device] = interfaces[network[:interface]]

View File

@ -7,9 +7,9 @@ module VagrantPlugins
# eth0\nenp0s8\nenp0s9
#
# @return [Array<String>]
def self.network_interfaces(machine)
def self.network_interfaces(machine, path = "/sbin/ip")
s = ""
machine.communicate.sudo("/sbin/ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |type, data|
machine.communicate.sudo("#{path} -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |type, data|
s << data if type == :stdout
end
s.split("\n")