Class: DigitalOcean

Inherits:
Provider show all
Defined in:
lib/open-dock/providers/digital_ocean.rb

Instance Method Summary collapse

Methods inherited from Provider

#initialize

Constructor Details

This class inherits a constructor from Provider

Instance Method Details

#create(config) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/open-dock/providers/digital_ocean.rb', line 5

def create(config)
  droplet = DropletKit::Droplet.new config
  resp = @connection.droplets.create droplet
  if resp == droplet
    ip = @connection.find_droplet_by_name(config["name"]).networks["v4"].first.ip_address
    say "Droplet #{config["name"]} (IP: #{ip}) successfully created!"
  else
    raise resp
  end
end

#delete(host) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/open-dock/providers/digital_ocean.rb', line 16

def delete(host)
  begin
    id = @connection.find_droplet_by_name(host).id
    resp = @connection.droplets.delete id: id
  rescue NoMethodError
    raise "#{host} does not exist"
  rescue
    raise resp
  end

  if resp.is_a?(TrueClass)
    say "Droplet #{host} successfully deleted!"
  else
    raise resp
  end
end

#list_paramsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/open-dock/providers/digital_ocean.rb', line 33

def list_params
  say "\nSizes:"
  @connection.sizes.all.each do |i|
    say "   - #{i.slug.ljust(6)} =>   $#{i.price_monthly}/mo"
  end

  say "\nRegions:"
  @connection.regions.all.each do |i|
    say "   - #{i.slug.ljust(6)} =>   #{i.name}"
  end

  say "\nImages:"
  @connection.images.all.each do |i|
    say "   - #{i.slug.ljust(20)} =>   #{i.distribution} #{i.name}" unless i.slug.nil?
  end

  say "\nSSH Keys:"
  @connection.ssh_keys.all.each do |i|
    say "   - #{i.fingerprint} =>   #{i.name}"
  end
end