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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UpcloudCommon

#abort_unless_api_access, #api_access?, #find_plan, #find_template, #get_server, #upcloud_client, #zone_exist?

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



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

def initialize(upcloud_username, upcloud_password)
  @username = upcloud_username
  @password = upcloud_password
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#run!(name) ⇒ Object



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

def run!(name)
  abort_unless_api_access

  servers = 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 = post(
        "server/#{server[:uuid]}/restart", body: {
          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