LVP for coreos guest support

This commit is contained in:
Artur Roszczyk 2013-08-03 20:31:42 +02:00
parent 5010738043
commit d8c10ad901
5 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,15 @@
module VagrantPlugins
module GuestCoreOS
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
if !comm.test("sudo hostname --fqdn | grep '#{name}'")
comm.sudo("hostname #{name.split('.')[0]}")
end
end
end
end
end
end
end

View File

@ -0,0 +1,65 @@
require "tempfile"
require "vagrant/util/template_renderer"
module VagrantPlugins
module GuestCoreOS
module Cap
class ConfigureNetworks
include Vagrant::Util
def self.configure_networks(machine, networks)
machine.communicate.tap do |comm|
# Remove any previous host only network additions to the interface file
comm.sudo("systemctl stop etcd")
primary_machine = machine.env.active_machines
#machine.env[:primary_machine].provider.driver.read_network_interfaces
#puts machine.env['admin1'].provider_config.network_adapters
#puts primary_machine
# Configure each network interface
interfaces = []
comm.sudo("ifconfig | grep enp0 | cut -f1 -d:") do |_, result|
interfaces = result.split("\n")
end
networks.each do |network|
comm.sudo("ifconfig #{interfaces[network[:interface].to_i]} #{network[:ip]} netmask #{network[:netmask]}")
end
puts 'TODO start etcd'
primary_machine_config = machine.env.active_machines.first
primary_machine = machine.env.machine(*primary_machine_config, true)
get_ip = ->(machine) do
_, network_config = machine.config.vm.networks.detect { |type, _| type == :private_network}
network_config[:ip]
end
primary_machine_ip = get_ip.(primary_machine)
if get_ip.(machine) == primary_machine_ip
entry = TemplateRenderer.render("guests/coreos/etcd.service")
else
entry = TemplateRenderer.render("guests/coreos/etcd.service",
:options => {:connect_to => primary_machine_ip})
end
puts entry
Tempfile.open("vagrant", '.') do |temp|
temp.binmode
temp.write(entry)
temp.close
comm.upload(temp.path, "/tmp/etcd-cluster.service")
end
comm.sudo("mv /tmp/etcd-cluster.service /media/state/units/")
comm.sudo("systemctl restart local-enable.service")
end
end
end
end
end
end

View File

@ -0,0 +1,9 @@
module VagrantPlugins
module GuestCoreOS
class Guest < Vagrant.plugin("2", :guest)
def detect?(machine)
machine.communicate.test("cat /etc/gentoo-release | grep CoreOS")
end
end
end
end

View File

@ -0,0 +1,25 @@
require "vagrant"
module VagrantPlugins
module GuestCoreOS
class Plugin < Vagrant.plugin("2")
name "CoreOS guest"
description "CoreOS guest support."
guest("coreos", "linux") do
require File.expand_path("../guest", __FILE__)
Guest
end
guest_capability("coreos", "change_host_name") do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
guest_capability("coreos", "configure_networks") do
require_relative "cap/configure_networks"
Cap::ConfigureNetworks
end
end
end
end

View File

@ -0,0 +1,10 @@
[Unit]
Description=Clustered etcd
#After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/etcd -c 4001 -s 7001 <% if options[:connect_to] %>-C <%= options[:connect_to] %>:7001<% end %> -d /home/core/etcd
[Install]
WantedBy=local.target