diff --git a/plugins/guests/coreos/cap/change_host_name.rb b/plugins/guests/coreos/cap/change_host_name.rb new file mode 100644 index 000000000..f568beadb --- /dev/null +++ b/plugins/guests/coreos/cap/change_host_name.rb @@ -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 diff --git a/plugins/guests/coreos/cap/configure_networks.rb b/plugins/guests/coreos/cap/configure_networks.rb new file mode 100644 index 000000000..6166105cf --- /dev/null +++ b/plugins/guests/coreos/cap/configure_networks.rb @@ -0,0 +1,71 @@ +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) + current_ip = get_ip.(machine) + if current_ip == primary_machine_ip + entry = TemplateRenderer.render("guests/coreos/etcd.service", :options => { + :my_ip => current_ip + }) + else + connection_string = "#{primary_machine_ip}:7001" + entry = TemplateRenderer.render("guests/coreos/etcd.service", :options => { + :connection_string => connection_string, + :my_ip => current_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 diff --git a/plugins/guests/coreos/guest.rb b/plugins/guests/coreos/guest.rb new file mode 100644 index 000000000..3afdca891 --- /dev/null +++ b/plugins/guests/coreos/guest.rb @@ -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 diff --git a/plugins/guests/coreos/plugin.rb b/plugins/guests/coreos/plugin.rb new file mode 100644 index 000000000..cc5229e82 --- /dev/null +++ b/plugins/guests/coreos/plugin.rb @@ -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 diff --git a/plugins/guests/gentoo/guest.rb b/plugins/guests/gentoo/guest.rb index 33af4ae5d..a4c77e9e6 100644 --- a/plugins/guests/gentoo/guest.rb +++ b/plugins/guests/gentoo/guest.rb @@ -2,7 +2,7 @@ module VagrantPlugins module GuestGentoo class Guest < Vagrant.plugin("2", :guest) def detect?(machine) - machine.communicate.test("cat /etc/gentoo-release") + machine.communicate.test("grep Gentoo /etc/gentoo-release") end end end diff --git a/templates/guests/coreos/etcd.service.erb b/templates/guests/coreos/etcd.service.erb new file mode 100644 index 000000000..65d7870ea --- /dev/null +++ b/templates/guests/coreos/etcd.service.erb @@ -0,0 +1,10 @@ +[Unit] +Description=Clustered etcd +#After=docker.service + +[Service] +Restart=always +ExecStart=/usr/bin/etcd -c 4001 -s 7001 -h <%= options[:my_ip] %> <% if options[:connection_string] %>-C <%= options[:connection_string] %><% end %> -d /home/core/etcd + +[Install] +WantedBy=local.target