Update Arch guest to the new networks API
This commit is contained in:
parent
3a2546907e
commit
f4ea1f800c
|
@ -1,3 +1,6 @@
|
|||
require 'set'
|
||||
require 'tempfile'
|
||||
|
||||
module Vagrant
|
||||
module Guest
|
||||
class Arch < Linux
|
||||
|
@ -10,23 +13,34 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# TODO: Convert these to the new format
|
||||
def prepare_host_only_network(net_options=nil)
|
||||
vm.ssh.execute do |ssh|
|
||||
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-HOSTONLY/,/^#VAGRANT-END-HOSTONLY/ d' /etc/rc.conf > /tmp/vagrant-network-interfaces")
|
||||
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/rc.conf'")
|
||||
def configure_networks(networks)
|
||||
# Remove previous Vagrant-managed network interfaces
|
||||
vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf > /tmp/vagrant-network-interfaces")
|
||||
vm.channel.sudo("cat /tmp/vagrant-network-interfaces > /etc/rc.conf")
|
||||
|
||||
# Configure the network interfaces
|
||||
interfaces = Set.new
|
||||
entries = []
|
||||
networks.each do |network|
|
||||
interfaces.add(network[:interface])
|
||||
entries << TemplateRenderer.render("guests/arch/network_#{network[:type]}",
|
||||
:options => network)
|
||||
end
|
||||
end
|
||||
|
||||
def enable_host_only_network(net_options)
|
||||
entry = TemplateRenderer.render('guests/arch/network_hostonly',
|
||||
:net_options => net_options)
|
||||
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
|
||||
# Perform the careful dance necessary to reconfigure
|
||||
# the network interfaces
|
||||
temp = Tempfile.new("vagrant")
|
||||
temp.write(entries.join("\n"))
|
||||
temp.close
|
||||
|
||||
vm.ssh.execute do |ssh|
|
||||
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'")
|
||||
ssh.exec!("sudo /etc/rc.d/network restart")
|
||||
ssh.exec!("sudo su -c 'dhcpcd -k eth0 && dhcpcd eth0 & sleep 3'")
|
||||
vm.channel.upload(temp.path, "/tmp/vagrant-network-entry")
|
||||
|
||||
# Reconfigure the network interfaces
|
||||
vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/rc.conf")
|
||||
vm.channel.sudo("/etc/rc.d/network restart")
|
||||
|
||||
interfaces.each do |interface|
|
||||
vm.channel.sudo("dhcpcd -k eth#{interface} && dhcpcd eth#{interface} && sleep 3")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
interface=eth<%= options[:interface] %>
|
||||
address=
|
||||
netmask=
|
||||
gateway=
|
||||
#VAGRANT-END
|
|
@ -1,7 +0,0 @@
|
|||
#VAGRANT-BEGIN-HOSTONLY
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
interface=eth<%= net_options[:adapter] %>
|
||||
address=<%= net_options[:ip]%>
|
||||
netmask=<%= net_options[:netmask] %>
|
||||
gateway=
|
||||
#VAGRANT-END-HOSTONLY
|
|
@ -0,0 +1,7 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
interface=eth<%= options[:interface] %>
|
||||
address=<%= options[:ip]%>
|
||||
netmask=<%= options[:netmask] %>
|
||||
gateway=
|
||||
#VAGRANT-END
|
Loading…
Reference in New Issue