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

Version Path
krates-plugin-digitalocean-0.3.11 lib/kontena/machine/digital_ocean/node_destroyer.rb
krates-plugin-digitalocean-0.3.10 lib/kontena/machine/digital_ocean/node_destroyer.rb
krates-plugin-digitalocean-0.3.9 lib/kontena/machine/digital_ocean/node_destroyer.rb
krates-plugin-digitalocean-0.3.8 lib/kontena/machine/digital_ocean/node_destroyer.rb
staticpages-plugin-digitalocean-0.3.7 lib/kontena/machine/digital_ocean/node_destroyer.rb
staticpages-plugin-digitalocean-0.3.6 lib/kontena/machine/digital_ocean/node_destroyer.rb
staticpages-plugin-digitalocean-0.3.5 lib/kontena/machine/digital_ocean/node_destroyer.rb
kontena-plugin-digitalocean-0.3.3 lib/kontena/machine/digital_ocean/node_destroyer.rb
kontena-plugin-digitalocean-0.3.2 lib/kontena/machine/digital_ocean/node_destroyer.rb
kontena-plugin-digitalocean-0.3.1 lib/kontena/machine/digital_ocean/node_destroyer.rb
kontena-plugin-digitalocean-0.3.1.rc1 lib/kontena/machine/digital_ocean/node_destroyer.rb
kontena-plugin-digitalocean-0.2.5 lib/kontena/machine/digital_ocean/node_destroyer.rb
kontena-plugin-digitalocean-0.2.4 lib/kontena/machine/digital_ocean/node_destroyer.rb