Sha256: 21b3a24eb4b79db46aa6e840008756d5b3d51e45d0b75210c228efcb78e994d4

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

require_relative '../prompts'

module Kontena::Plugin::DigitalOcean::Nodes
  class RestartCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions
    include Kontena::Plugin::DigitalOcean::Prompts

    parameter "[NAME]", "Node name"
    option "--token", "TOKEN", "DigitalOcean API token", environment_variable: "DO_TOKEN"

    def execute
      require_api_url
      require_current_grid
      do_token = ask_do_token

      require_relative '../../../machine/digital_ocean'

      node_name = ask_node(require_token)
      client = DropletKit::Client.new(access_token: do_token)
      droplet = client.droplets.all.find{|d| d.name == node_name}
      if droplet
        spinner "Restarting DigitalOcean droplet #{pastel.cyan(name)} " do
          client.droplet_actions.reboot(droplet_id: droplet.id)
          sleep 1 until client.droplets.find(id: droplet.id).status == 'active'
        end
      else
        exit_with_error "Cannot find droplet #{pastel.cyan(name)} in DigitalOcean"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kontena-plugin-digitalocean-0.2.5 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.2.4 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.2.3 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.2.2 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.2.1 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.2.0 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.2.0.pre2 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb