2016-05-31 03:17:02 +00:00
|
|
|
require "tempfile"
|
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
require_relative "../../../../lib/vagrant/util/template_renderer"
|
2013-05-14 20:22:19 +00:00
|
|
|
|
2013-04-04 18:39:58 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestArch
|
|
|
|
module Cap
|
|
|
|
class ConfigureNetworks
|
2013-05-22 15:29:58 +00:00
|
|
|
include Vagrant::Util
|
|
|
|
|
2013-04-04 18:39:58 +00:00
|
|
|
def self.configure_networks(machine, networks)
|
guests/arch: Configure networks in one command
This commit updates the procedure for configuring arch networks to occur
in a single command. Previously, each network was configured
independently. If, for some reason, one of the networks destroyed the
SSH connection, the box would be irrecoverable. This commit does not
alleviate that behavior, but attempts to mitigate it by running all
network-related configuration commands in a single communicator (SSH)
session.
The new procedure looks like this:
1. Upload a temp file to /tmp/vagrant-network-id... for each interface
on the guest.
2. Compile a commands array (of bash) to execute after all network
configurations have been uploaded.
3. Concatenate all the commands together in a single communicator
session.
This was tested against `terrywant/archlinux` using the following Vagrantfile:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "terrywang/archlinux"
config.vm.hostname = "banana-ramama.example.com"
config.vm.network "private_network", type: "dhcp"
config.vm.network "private_network", ip: "33.33.33.10"
config.vm.provision "file", source: "Vagrantfile", destination: "/tmp/vf"
config.vm.provision "shell", inline: "echo hi"
end
```
2016-05-31 02:11:48 +00:00
|
|
|
comm = machine.communicate
|
|
|
|
|
2016-06-24 23:08:35 +00:00
|
|
|
commands = ["set -e"]
|
2016-06-23 02:08:02 +00:00
|
|
|
interfaces = machine.guest.capability(:network_interfaces)
|
2014-09-06 02:56:01 +00:00
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
networks.each.with_index do |network, i|
|
2014-09-06 02:56:01 +00:00
|
|
|
network[:device] = interfaces[network[:interface]]
|
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
|
guests/arch: Configure networks in one command
This commit updates the procedure for configuring arch networks to occur
in a single command. Previously, each network was configured
independently. If, for some reason, one of the networks destroyed the
SSH connection, the box would be irrecoverable. This commit does not
alleviate that behavior, but attempts to mitigate it by running all
network-related configuration commands in a single communicator (SSH)
session.
The new procedure looks like this:
1. Upload a temp file to /tmp/vagrant-network-id... for each interface
on the guest.
2. Compile a commands array (of bash) to execute after all network
configurations have been uploaded.
3. Concatenate all the commands together in a single communicator
session.
This was tested against `terrywant/archlinux` using the following Vagrantfile:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "terrywang/archlinux"
config.vm.hostname = "banana-ramama.example.com"
config.vm.network "private_network", type: "dhcp"
config.vm.network "private_network", ip: "33.33.33.10"
config.vm.provision "file", source: "Vagrantfile", destination: "/tmp/vf"
config.vm.provision "shell", inline: "echo hi"
end
```
2016-05-31 02:11:48 +00:00
|
|
|
options: network,
|
|
|
|
)
|
2016-05-29 03:17:40 +00:00
|
|
|
|
guests/arch: Configure networks in one command
This commit updates the procedure for configuring arch networks to occur
in a single command. Previously, each network was configured
independently. If, for some reason, one of the networks destroyed the
SSH connection, the box would be irrecoverable. This commit does not
alleviate that behavior, but attempts to mitigate it by running all
network-related configuration commands in a single communicator (SSH)
session.
The new procedure looks like this:
1. Upload a temp file to /tmp/vagrant-network-id... for each interface
on the guest.
2. Compile a commands array (of bash) to execute after all network
configurations have been uploaded.
3. Concatenate all the commands together in a single communicator
session.
This was tested against `terrywant/archlinux` using the following Vagrantfile:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "terrywang/archlinux"
config.vm.hostname = "banana-ramama.example.com"
config.vm.network "private_network", type: "dhcp"
config.vm.network "private_network", ip: "33.33.33.10"
config.vm.provision "file", source: "Vagrantfile", destination: "/tmp/vf"
config.vm.provision "shell", inline: "echo hi"
end
```
2016-05-31 02:11:48 +00:00
|
|
|
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
|
2013-04-04 18:39:58 +00:00
|
|
|
|
2016-05-31 04:18:16 +00:00
|
|
|
Tempfile.open("vagrant-arch-configure-networks") do |f|
|
2016-05-31 03:17:02 +00:00
|
|
|
f.binmode
|
2016-05-29 03:17:40 +00:00
|
|
|
f.write(entry)
|
|
|
|
f.fsync
|
|
|
|
f.close
|
guests/arch: Configure networks in one command
This commit updates the procedure for configuring arch networks to occur
in a single command. Previously, each network was configured
independently. If, for some reason, one of the networks destroyed the
SSH connection, the box would be irrecoverable. This commit does not
alleviate that behavior, but attempts to mitigate it by running all
network-related configuration commands in a single communicator (SSH)
session.
The new procedure looks like this:
1. Upload a temp file to /tmp/vagrant-network-id... for each interface
on the guest.
2. Compile a commands array (of bash) to execute after all network
configurations have been uploaded.
3. Concatenate all the commands together in a single communicator
session.
This was tested against `terrywant/archlinux` using the following Vagrantfile:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "terrywang/archlinux"
config.vm.hostname = "banana-ramama.example.com"
config.vm.network "private_network", type: "dhcp"
config.vm.network "private_network", ip: "33.33.33.10"
config.vm.provision "file", source: "Vagrantfile", destination: "/tmp/vf"
config.vm.provision "shell", inline: "echo hi"
end
```
2016-05-31 02:11:48 +00:00
|
|
|
comm.upload(f.path, remote_path)
|
2016-05-29 03:17:40 +00:00
|
|
|
end
|
2013-04-04 18:39:58 +00:00
|
|
|
|
guests/arch: Configure networks in one command
This commit updates the procedure for configuring arch networks to occur
in a single command. Previously, each network was configured
independently. If, for some reason, one of the networks destroyed the
SSH connection, the box would be irrecoverable. This commit does not
alleviate that behavior, but attempts to mitigate it by running all
network-related configuration commands in a single communicator (SSH)
session.
The new procedure looks like this:
1. Upload a temp file to /tmp/vagrant-network-id... for each interface
on the guest.
2. Compile a commands array (of bash) to execute after all network
configurations have been uploaded.
3. Concatenate all the commands together in a single communicator
session.
This was tested against `terrywant/archlinux` using the following Vagrantfile:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "terrywang/archlinux"
config.vm.hostname = "banana-ramama.example.com"
config.vm.network "private_network", type: "dhcp"
config.vm.network "private_network", ip: "33.33.33.10"
config.vm.provision "file", source: "Vagrantfile", destination: "/tmp/vf"
config.vm.provision "shell", inline: "echo hi"
end
```
2016-05-31 02:11:48 +00:00
|
|
|
commands << <<-EOH.gsub(/^ {14}/, '')
|
|
|
|
# Configure #{network[:device]}
|
|
|
|
mv '#{remote_path}' '/etc/netctl/#{network[:device]}'
|
|
|
|
ip link set '#{network[:device]}' down
|
|
|
|
netctl restart '#{network[:device]}'
|
|
|
|
netctl enable '#{network[:device]}'
|
|
|
|
EOH
|
2013-04-04 18:39:58 +00:00
|
|
|
end
|
guests/arch: Configure networks in one command
This commit updates the procedure for configuring arch networks to occur
in a single command. Previously, each network was configured
independently. If, for some reason, one of the networks destroyed the
SSH connection, the box would be irrecoverable. This commit does not
alleviate that behavior, but attempts to mitigate it by running all
network-related configuration commands in a single communicator (SSH)
session.
The new procedure looks like this:
1. Upload a temp file to /tmp/vagrant-network-id... for each interface
on the guest.
2. Compile a commands array (of bash) to execute after all network
configurations have been uploaded.
3. Concatenate all the commands together in a single communicator
session.
This was tested against `terrywant/archlinux` using the following Vagrantfile:
```ruby
Vagrant.configure(2) do |config|
config.vm.box = "terrywang/archlinux"
config.vm.hostname = "banana-ramama.example.com"
config.vm.network "private_network", type: "dhcp"
config.vm.network "private_network", ip: "33.33.33.10"
config.vm.provision "file", source: "Vagrantfile", destination: "/tmp/vf"
config.vm.provision "shell", inline: "echo hi"
end
```
2016-05-31 02:11:48 +00:00
|
|
|
|
|
|
|
# Run all the network modification commands in one communicator call.
|
|
|
|
comm.sudo(commands.join("\n"))
|
2013-04-04 18:39:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|