lib/kontena/machine/digital_ocean/master_provisioner.rb in kontena-plugin-digitalocean-0.1.1 vs lib/kontena/machine/digital_ocean/master_provisioner.rb in kontena-plugin-digitalocean-0.2.0.pre1

- old
+ new

@@ -1,16 +1,16 @@ require 'fileutils' require 'erb' require 'open3' -require 'shell-spinner' module Kontena module Machine module DigitalOcean class MasterProvisioner include RandomName include Machine::CertHelper + include Kontena::Cli::ShellSpinner attr_reader :client, :http_client # @param [String] token Digital Ocean token def initialize(token) @@ -25,51 +25,55 @@ if opts[:ssl_cert] abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert])) ssl_cert = File.read(File.expand_path(opts[:ssl_cert])) else - ShellSpinner "Generating self-signed SSL certificate" do + spinner "Generating self-signed SSL certificate" do ssl_cert = generate_self_signed_cert end end - userdata_vars = { + name = generate_name + userdata_vars = opts.merge( ssl_cert: ssl_cert, - auth_server: opts[:auth_server], - version: opts[:version], - vault_secret: opts[:vault_secret], - vault_iv: opts[:vault_iv], - mongodb_uri: opts[:mongodb_uri] - } + server_name: name.sub('kontena-master-', '') + ) droplet = DropletKit::Droplet.new( - name: generate_name, + name: name, region: opts[:region], image: 'coreos-stable', size: opts[:size], private_networking: true, user_data: user_data(userdata_vars), ssh_keys: [ssh_key.id] ) - ShellSpinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do + spinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do droplet = client.droplets.create(droplet) until droplet.status == 'active' droplet = client.droplets.find(id: droplet.id) - sleep 5 + sleep 1 end end master_url = "https://#{droplet.public_ip}" Excon.defaults[:ssl_verify_peer] = false @http_client = Excon.new("#{master_url}", :connect_timeout => 10) - ShellSpinner "Waiting for #{droplet.name.colorize(:cyan)} to start" do - sleep 5 until master_running? + spinner "Waiting for #{droplet.name.colorize(:cyan)} to start" do + sleep 0.5 until master_running? end - puts "Kontena Master is now running at #{master_url}" - puts "Use #{"kontena login --name=#{droplet.name.sub('kontena-master-', '')} #{master_url}".colorize(:light_black)} to complete Kontena Master setup" + puts + puts "Kontena Master is now running at #{master_url}".colorize(:green) + puts + + { + name: name.sub('kontena-master-', ''), + public_ip: droplet.public_ip, + code: opts[:initial_admin_code] + } end def user_data(vars) cloudinit_template = File.join(__dir__ , '/cloudinit_master.yml') erb(File.read(cloudinit_template), vars)