Sha256: 0a7770d7050f33248ee8a32965daba1609d2a41baa70e6b966be6dd2929021f7
Contents?: true
Size: 1.32 KB
Versions: 13
Compression:
Stored size: 1.32 KB
Contents
module Kontena module Machine module DigitalOcean class NodeDestroyer include RandomName include Kontena::Cli::ShellSpinner attr_reader :client, :api_client # @param [Kontena::Client] api_client Kontena api client # @param [String] token Digital Ocean token def initialize(api_client, token) @api_client = api_client @client = DropletKit::Client.new(access_token: token) end 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 end end end end
Version data entries
13 entries across 13 versions & 3 rubygems