Class: Kontena::Machine::DigitalOcean::MasterDestroyer

Inherits:
Object
  • Object
show all
Includes:
Cli::ShellSpinner
Defined in:
lib/kontena/machine/digital_ocean/master_destroyer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ MasterDestroyer

Returns a new instance of MasterDestroyer.

Parameters:

  • token (String)

    Digital Ocean token



10
11
12
# File 'lib/kontena/machine/digital_ocean/master_destroyer.rb', line 10

def initialize(token)
  @client = DropletKit::Client.new(access_token: token)
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



7
8
9
# File 'lib/kontena/machine/digital_ocean/master_destroyer.rb', line 7

def api_client
  @api_client
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/kontena/machine/digital_ocean/master_destroyer.rb', line 7

def client
  @client
end

Instance Method Details

#run!(name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kontena/machine/digital_ocean/master_destroyer.rb', line 14

def run!(name)
  droplet = client.droplets.all.find{|d| d.name == name}
  if droplet
    spinner "Terminating DigitalOcean droplet #{name.colorize(:cyan)} " do
      result = client.droplets.delete(id: droplet.id)
      if result.is_a?(String)
        abort "Cannot delete droplet #{name.colorize(:cyan)} in DigitalOcean"
      end
    end
  else
    abort "Cannot find droplet #{name.colorize(:cyan)} in DigitalOcean"
  end
end