Sha256: fc8543a0290ce4cb4d0d7d543112c76a638f32a11f275cc513c752056d1c34ec

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

require 'kontena/plugin/digital_ocean/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
      suppress_warnings # until DO merges resource_kit pr #32
      require 'kontena/machine/digital_ocean'
      require_api_url
      require_current_grid
      do_token = ask_do_token

      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
    ensure
      resume_warnings
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
krates-plugin-digitalocean-0.3.11 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
krates-plugin-digitalocean-0.3.10 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
krates-plugin-digitalocean-0.3.9 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
krates-plugin-digitalocean-0.3.8 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
staticpages-plugin-digitalocean-0.3.7 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
staticpages-plugin-digitalocean-0.3.6 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
staticpages-plugin-digitalocean-0.3.5 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.3.3 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.3.2 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
kontena-plugin-digitalocean-0.3.1 lib/kontena/plugin/digital_ocean/nodes/restart_command.rb