class Vpsb::Tasks::CreateDroplet

Public Instance Methods

call() click to toggle source
# File lib/vpsb/tasks/create_droplet.rb, line 8
def call
  prepare

  ask_loop(proc {|r| process(r)}) do
    ap preparation_results
    puts "Save this configuration y[es]/n[o]?"
  end

  create_droplet
  puts "Your droplet has been created. Congratulations! Visit https://cloud.digitalocean.com/ to see more details"
end

Private Instance Methods

create_droplet() click to toggle source
# File lib/vpsb/tasks/create_droplet.rb, line 28
def create_droplet
  puts "Creating droplet please wait... It may take a couple of minutes"
  command = [
    "knife digital_ocean droplet create",
    "--server-name #{core.get(:do_host)}",
    "--image       #{core.get(:do_image)}",
    "--location    #{core.get(:do_region)}",
    "--size        #{core.get(:do_size)}",
    "--ssh-keys    #{core.get(:do_droplet_ssh_key)}",
  ].join(' ')

  output = run(core.get(:server_app_path), command)
  ip = output.split("\n").find{ |x| x.include?('IPv4 address is:')}.split(':').last.strip
  core.data[:do_host_ip] = ip
  puts output
end
process(r) click to toggle source
# File lib/vpsb/tasks/create_droplet.rb, line 22
def process(r)
  return true if r[0].to_s.downcase == 'y'
  reprepare
  false
end
run(where, what) click to toggle source
# File lib/vpsb/tasks/create_droplet.rb, line 45
def run(where, what)
  %x{cd #{where} && #{what}}
end