systemctl wasn't a good idea

This commit is contained in:
me 2013-12-05 16:01:44 +01:00
parent 158d82ea39
commit 2a75c34d62
1 changed files with 12 additions and 8 deletions

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
require "tempfile"
require "vagrant/util/template_renderer"
@ -18,20 +19,23 @@ module VagrantPlugins
temp.write(entry)
temp.close
# Only consider nth line of sed's output below. There certainly is a
# better way to do this
snth = network[:interface] + 1
machine.communicate.upload(temp.path, "/tmp/vagrant_network")
machine.communicate.sudo("mv /tmp/vagrant_network /etc/netctl/eth#{network[:interface]}")
# A hack not to rely on udev rule 80-net-name-slot.rules masking:
# ln -sf /dev/null /etc/udev/80-net-name-slot.rules that
# Only consider nth line of sed's output below. There's always an
# offset of two lines in the below sed command given the current
# interface number -> 1: lo, 2: nat device,
snth = network[:interface] + 2
# A hack not to rely on udev rule 80-net-name-slot.rules masking
# (ln -sf /dev/null /etc/udev/80-net-name-slot.rules).
# I assume this to be the most portable solution because
# otherwise we would need to rely on the Virtual Machine implementation
# to provide details on the configured interfaces, e.g mac address
# to write a custom udev rule.
machine.communicate.sudo("sed -i s/eth#{network[:interface]}/`systemctl list-units -t device | sed -n 's/.*subsystem.net-devices-\\(.*\\).device.*/\\1/p' | sed -n #{snth}p`/g /etc/netctl/eth#{network[:interface]}")
# to write a custom udev rule. Templating the netcfg files and
# replacing the correct interface name within ruby seems more
# complicted too (I'm far from being a ruby expert though).
machine.communicate.sudo("sed -i \"s/eth#{network[:interface]}/`ip link | sed -n 's/.*:\\s\\(.*\\): <.*/\\1/p' | sed -n #{snth}p`/g\" /etc/netctl/eth#{network[:interface]}")
machine.communicate.sudo("netctl start eth#{network[:interface]}")
end
end