lib/kontena/machine/vagrant/master_provisioner.rb in kontena-plugin-vagrant-0.2.7 vs lib/kontena/machine/vagrant/master_provisioner.rb in kontena-plugin-vagrant-0.3.0

- old
+ new

@@ -1,16 +1,14 @@ -require 'fileutils' -require 'erb' -require 'open3' -require 'json' +require_relative 'common' module Kontena module Machine module Vagrant class MasterProvisioner include RandomName include Kontena::Machine::Common + include Kontena::Machine::Vagrant::Common include Kontena::Cli::Common include Kontena::Cli::ShellSpinner API_URL = 'http://192.168.66.100:8080' attr_reader :client @@ -46,30 +44,31 @@ initial_admin_code: initial_admin_code, vault_iv: vault_iv, coreos_channel: coreos_channel, cloudinit: "#{vagrant_path}/cloudinit.yml" } - vagrant_data = erb(File.read(template), vars) - cloudinit = erb(File.read(cloudinit_template), vars) - File.write("#{vagrant_path}/Vagrantfile", vagrant_data) - File.write("#{vagrant_path}/cloudinit.yml", cloudinit) + spinner "Creating Vagrant config " do + vagrant_data = erb(File.read(template), vars) + cloudinit = erb(File.read(cloudinit_template), vars) + File.write("#{vagrant_path}/Vagrantfile", vagrant_data) + File.write("#{vagrant_path}/cloudinit.yml", cloudinit) + end + Dir.chdir(vagrant_path) do - spinner "Creating Vagrant machine #{name.colorize(:cyan)} " do - Open3.popen2("vagrant up") do |stdin, output, wait| - while o = output.gets - print o if ENV['DEBUG'] - end - end - end + spinner "Triggering CoreOS Container Linux box update" + run_command('vagrant box update') + spinner "Executing 'vagrant up'" + run_command('vagrant up') + spinner "'vagrant up' executed successfully" end spinner "Waiting for #{name.colorize(:cyan)} to start " do sleep 1 until master_running? end master_version = nil - spinner "Retrieving Kontena Master version" do + spinner "Retrieving #{name.colorize(:cyan)} version" do master_version = JSON.parse(client.get(path: '/'))["version"] rescue nil end spinner "Kontena Master #{master_version} is now running at #{API_URL}" @@ -78,13 +77,9 @@ public_ip: API_URL.split('//').last, provider: 'vagrant', version: master_version, code: opts[:initial_admin_code] } - end - - def erb(template, vars) - ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding }) end def master_running? client.get(path: '/').status == 200 rescue