Sha256: 79c10b19d804d03d20370f1cef0ab5a881e617f28e273043b6cf38c0d21a5c80

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

module Kontena
  module Machine
    module Packet
      class NodeDestroyer
        include RandomName
        include PacketCommon
        include Kontena::Cli::ShellSpinner

        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

          spinner "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
            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

7 entries across 7 versions & 1 rubygems

Version Path
kontena-plugin-packet-0.2.5 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.2.4 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.2.3 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.2.2 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.2.1 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.2.0 lib/kontena/machine/packet/node_destroyer.rb
kontena-plugin-packet-0.2.0.pre1 lib/kontena/machine/packet/node_destroyer.rb