Sha256: 3f8e4651558989dc9bdecf1d8006cd7a71d2896b24ce414fc8036948ab01edf0

Contents?: true

Size: 1.27 KB

Versions: 11

Compression:

Stored size: 1.27 KB

Contents

require 'shell-spinner'

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

        attr_reader :client

        # @param [String] token Packet api token
        def initialize(token)
          @client = login(token)
        end

        # @param [String] project_id Packet project id
        # @param [String] token Node hostname
        def run!(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
          abort("Your version of 'packethost' gem does not support rebooting servers") unless client.respond_to?(:reboot_device)

          ShellSpinner "Restarting Packet device #{device.hostname.colorize(:cyan)} " do
            begin
              response = client.reboot_device(device)
              raise unless response.success?
            rescue
              abort "Cannot delete device #{name.colorize(:cyan)} in Packet"
            end
            sleep 5
            until device && device.state == :active
              device = find_device(project.id, device.hostname) rescue nil
              sleep 5
            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_restarter.rb
kontena-plugin-packet-0.1.1 lib/kontena/machine/packet/node_restarter.rb
kontena-plugin-packet-0.1.0 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.7 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.6 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.5 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.4 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.3 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.2 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.1 lib/kontena/machine/packet/node_restarter.rb
kontena-cli-0.14.0 lib/kontena/machine/packet/node_restarter.rb