Class: Kontena::Machine::Upcloud::NodeRestarter

Inherits:
Object
  • Object
show all
Includes:
Cli::ShellSpinner, RandomName
Defined in:
lib/kontena/machine/upcloud/node_restarter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upcloud_username, upcloud_password) ⇒ NodeRestarter

Returns a new instance of NodeRestarter.

Parameters:

  • upcloud_username (String)

    Upcloud username

  • upcloud_password (String)

    Upcloud password



12
13
14
# File 'lib/kontena/machine/upcloud/node_restarter.rb', line 12

def initialize(upcloud_username, upcloud_password)
  @uc_client = Kontena::Machine::Upcloud::Client.new(upcloud_username, upcloud_password)
end

Instance Attribute Details

#uc_clientObject (readonly)

Returns the value of attribute uc_client.



8
9
10
# File 'lib/kontena/machine/upcloud/node_restarter.rb', line 8

def uc_client
  @uc_client
end

Instance Method Details

#run!(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kontena/machine/upcloud/node_restarter.rb', line 16

def run!(name)

  servers = uc_client.get('server')
  unless servers && servers.has_key?(:servers)
    abort('Upcloud API error')
  end

  server = servers[:servers][:server].find{|s| s[:hostname] == name}

  if server
    spinner "Restarting UpCloud node #{name.colorize(:cyan)} " do
      result = uc_client.post(
        "server/#{server[:uuid]}/restart", {
          restart_server: {
            stop_type: 'soft',
            timeout: 600,
            timeout_action: 'destroy' # hard shutdown in case sof timeouts
          }
        }.to_json
      )
    end
  else
    abort "Cannot find node #{name.colorize(:cyan)} in UpCloud"
  end
end