Sha256: 7b05e565fc591ca59437a1644ec7d78fd1cd75f8e7b0f796775ebe25412ba994
Contents?: true
Size: 1.32 KB
Versions: 6
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("grids/#{grid['id']}/nodes/#{name}") end end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems