class Conjure::DigitalOcean::Droplet

Public Class Methods

new(options) click to toggle source
# File lib/conjure/digital_ocean/droplet.rb, line 8
def initialize(options)
  @options = options
  @properties = {}
  create
end

Public Instance Methods

ip_address() click to toggle source
# File lib/conjure/digital_ocean/droplet.rb, line 14
def ip_address
  @ip_address ||= begin
    wait_until_ready
    @properties["networks"]["v4"].first["ip_address"]
  end
end

Private Instance Methods

account() click to toggle source
# File lib/conjure/digital_ocean/droplet.rb, line 43
def account
  raise "Error: DIGITALOCEAN_API_TOKEN must be set." unless ENV["DIGITALOCEAN_API_TOKEN"]
  @account ||= Account.new(:token => ENV["DIGITALOCEAN_API_TOKEN"])
end
create() click to toggle source
# File lib/conjure/digital_ocean/droplet.rb, line 23
def create
  puts "Creating DigitalOcean droplet..."
  response = account.post("droplets", {
    image: @options[:image],
    name: "#{@options[:name_prefix]}-#{SecureRandom.hex 4}",
    region: @options[:region],
    size: @options[:size],
    ssh_keys: [key.id],
  })
  @properties = response["droplet"]
end
key() click to toggle source
# File lib/conjure/digital_ocean/droplet.rb, line 48
def key
  KeySet.new(account).find_or_create @options[:key_data]
end
wait_until_ready() click to toggle source
# File lib/conjure/digital_ocean/droplet.rb, line 35
def wait_until_ready
  while @properties["status"] != "active" do
    sleep 5
    @properties = account.get("droplets/#{@properties['id']}")["droplet"]
  end
  sleep 30
end