Sha256: 8350875fb4fc5dc08be0128a0fa957dbcfb0d619476e4342904440d73e91480f

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

require 'shell-spinner'

module Kontena
  module Machine
    module Packet
      class NodeDestroyer
        include RandomName
        include PacketCommon

        attr_reader :client, :api_client

        # @param [Kontena::Client] api_client Kontena api client
        # @param [String] token Packet api token
        def initialize(api_client, token)
          @api_client = api_client
          @client = login(token)
        end

        def run!(grid, project_id, name)
          device = client.list_devices(project_id).find{|d| d.hostname == name}
          abort("Device #{name.colorize(:cyan)} not found in Packet") unless device

          ShellSpinner "Terminating Packet device #{name.colorize(:cyan)} " do
            begin
              response = client.delete_device(device.id)
              raise unless response.success?
            rescue
              abort "Cannot delete device #{name.colorize(:cyan)} in Packet"
            end
          end

          node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
          if node
            ShellSpinner "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

11 entries across 11 versions & 2 rubygems

Version Path
kontena-plugin-packet-0.1.2 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.1.1 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.1.0 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.7 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.6 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.5 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.4 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.3 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.2 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.1 lib/kontena/machine/packet/node_destroyer.rb
kontena-cli-0.14.0 lib/kontena/machine/packet/node_destroyer.rb