fix(coreos-base/oem-vagrant): Split up plugin, use change_host_name hook.

The old override-plugin.rb didn't actually properly monkey patch the
change host name function because it was missing a requires line
pointing to the file it is defined in upstream. To clarify things split
the code into two files that match the upstream names. Additionally
using this hook as it is intended means it works if a host name is
defined but additional networks are not.

As part of the split switch to starting the units directly. The
indirection through a path unit just adds complexity.
This commit is contained in:
Michael Marineau 2014-04-27 17:52:47 -04:00
parent 9424a28ec3
commit b1294b062d
4 changed files with 43 additions and 32 deletions

View File

@ -5,7 +5,8 @@ if Vagrant::VERSION < "1.5.0"
raise "Need at least vagrant version 1.5.0, please update"
end
require_relative 'override-plugin.rb'
require_relative 'change_host_name.rb'
require_relative 'configure_networks.rb'
Vagrant.configure("2") do |config|
# SSH in as the default 'core' user, it has the vagrant ssh key.

View File

@ -0,0 +1,37 @@
# -*- mode: ruby -*-
# # vi: set ft=ruby :
# NOTE: This monkey-patching of the coreos guest plugin is a terrible
# hack that needs to be removed once the upstream plugin works with
# alpha CoreOS images.
require 'tempfile'
require Vagrant.source_root.join("plugins/guests/coreos/cap/change_host_name.rb")
CLOUD_CONFIG = <<EOF
#cloud-config
hostname: %s
EOF
module VagrantPlugins
module GuestCoreOS
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
temp = Tempfile.new("coreos-vagrant")
temp.binmode
temp.write(CLOUD_CONFIG % [name])
temp.close
path = "/var/tmp/hostname.yml"
path_esc = path.gsub("/", "-")
comm.upload(temp.path, path)
comm.sudo("systemctl start system-cloudinit@#{path_esc}.service")
end
end
end
end
end
end

View File

@ -50,8 +50,6 @@ module VagrantPlugins
interfaces = result.split("\n")
end
ip = ""
# Configure interfaces
# FIXME: fix matching of interfaces with IP adresses
networks.each do |network|
@ -63,38 +61,20 @@ module VagrantPlugins
unit = NETWORK_UNIT % [unit_name, iface_name, address]
cfg = "#{cfg}#{unit}"
ip = network[:ip]
end
cfg = <<EOF
#{cfg}
write_files:
- path: /etc/environment
content: |
COREOS_PUBLIC_IPV4=#{ip}
COREOS_PRIVATE_IPV4=#{ip}
hostname: #{machine.name}
EOF
temp = Tempfile.new("coreos-vagrant")
temp.binmode
temp.write(cfg)
temp.close
comm.upload(temp.path, "/tmp/user-data")
comm.sudo("mkdir -p /var/lib/coreos-vagrant")
comm.sudo("mv /tmp/user-data /var/lib/coreos-vagrant/")
path = "/var/tmp/networks.yml"
path_esc = path.gsub("/", "-")
comm.upload(temp.path, path)
comm.sudo("systemctl start system-cloudinit@#{path_esc}.service")
end
end
end
class ChangeHostName
def self.change_host_name(machine, name)
# This is handled in configure_networks
end
end
end
end
end

View File

@ -1,13 +1,6 @@
#cloud-config
coreos:
units:
- name: coreos-cloudinit-vagrant.path
command: start
runtime: no
content: |
[Path]
PathExists=/var/lib/coreos-vagrant/user-data
Unit=system-cloudinit@var-lib-coreos\x2dvagrant-user\x2ddata.service
- name: coreos-cloudinit-vagrant-user.path
command: start
runtime: no