9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/vagrant-vyatta/cap/configure_networks.rb', line 9
def self.configure_networks(machine, networks)
machine.communicate.tap do |comm|
commands = <<-EOS
WRAPPER=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper
. /etc/bash_completion
$WRAPPER begin
EOS
networks.each do |network|
commands << "$WRAPPER delete interfaces ethernet eth#{network[:interface]}\n"
if network[:type].to_sym == :static
subnet = IPAddr.new(network[:netmask]).to_i.to_s(2).count("1")
commands << "$WRAPPER set interfaces ethernet eth#{network[:interface]} address #{network[:ip]}/#{subnet}\n"
elsif network[:type].to_sym == :dhcp
commands << "$WRAPPER set interfaces ethernet eth#{network[:interface]} address dhcp\n"
end
end
commands << <<-EOS
$WRAPPER commit
$WRAPPER save
$WRAPPER end
EOS
temp = Tempfile.new("vagrant")
temp.binmode
temp.write(commands)
temp.close
comm.upload(temp.path, "/tmp/vagrant-configure-network")
comm.execute("bash /tmp/vagrant-configure-network")
comm.execute("rm -f /tmp/vagrant-configure-network")
end
end
|