2015-04-20 17:13:21 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestPhoton
|
|
|
|
module Cap
|
|
|
|
class ConfigureNetworks
|
|
|
|
include Vagrant::Util
|
|
|
|
|
|
|
|
def self.configure_networks(machine, networks)
|
2016-06-05 20:54:42 +00:00
|
|
|
comm = machine.communicate
|
2015-04-20 21:56:26 +00:00
|
|
|
|
2016-06-05 20:54:42 +00:00
|
|
|
commands = []
|
|
|
|
interfaces = []
|
2015-04-20 21:56:26 +00:00
|
|
|
|
2016-06-05 20:54:42 +00:00
|
|
|
comm.sudo("ifconfig | grep 'eth' | cut -f1 -d' '") do |_, result|
|
|
|
|
interfaces = result.split("\n")
|
|
|
|
end
|
2015-04-20 21:56:26 +00:00
|
|
|
|
2016-06-05 20:54:42 +00:00
|
|
|
networks.each do |network|
|
|
|
|
device = interfaces[network[:interface]]
|
|
|
|
command = "ifconfig #{device}"
|
|
|
|
command << " #{network[:ip]}" if network[:ip]
|
2016-10-06 20:23:13 +00:00
|
|
|
command << " netmask #{network[:netmask]}" if network[:netmask]
|
2016-06-05 20:54:42 +00:00
|
|
|
commands << command
|
2015-04-20 17:13:21 +00:00
|
|
|
end
|
2016-06-05 20:54:42 +00:00
|
|
|
|
|
|
|
comm.sudo(commands.join("\n"))
|
2015-04-20 17:13:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|