Class: Kontena::Machine::DigitalOcean::NodeDestroyer
- Inherits:
-
Object
- Object
- Kontena::Machine::DigitalOcean::NodeDestroyer
- Includes:
- Cli::ShellSpinner, RandomName
- Defined in:
- lib/kontena/machine/digital_ocean/node_destroyer.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(api_client, token) ⇒ NodeDestroyer
constructor
A new instance of NodeDestroyer.
- #run!(grid, name) ⇒ Object
Constructor Details
#initialize(api_client, token) ⇒ NodeDestroyer
Returns a new instance of NodeDestroyer.
12 13 14 15 |
# File 'lib/kontena/machine/digital_ocean/node_destroyer.rb', line 12 def initialize(api_client, token) @api_client = api_client @client = DropletKit::Client.new(access_token: token) end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
8 9 10 |
# File 'lib/kontena/machine/digital_ocean/node_destroyer.rb', line 8 def api_client @api_client end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/kontena/machine/digital_ocean/node_destroyer.rb', line 8 def client @client end |
Instance Method Details
#run!(grid, name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kontena/machine/digital_ocean/node_destroyer.rb', line 17 def run!(grid, 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 node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name} if node spinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do api_client.delete("nodes/#{grid['id']}/#{name}") end end end |