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

Inherits:
Object
  • Object
show all
Includes:
RandomName, UpcloudCommon
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?, #client, #find_plan, #find_template, #get_server, #zone_exist?

Methods included from RandomName

#generate_name

Constructor Details

#initialize(upcloud_username, upcloud_password) ⇒ NodeRestarter



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

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

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#run!(name) ⇒ Object



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
44
# File 'lib/kontena/machine/upcloud/node_restarter.rb', line 19

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
    ShellSpinner "Restarting Upcloud node #{name.colorize(:cyan)} " do
      result = post(
        "server/#{server[:uuid]}/restart", body: {
          restart_server: {
            stop_type: 'soft',
            timeout: 600,
            timeout_action: 'ignore'
          }
        }.to_json
      )
    end
  else
    abort "Cannot find node #{name.colorize(:cyan)} in Upcloud"
  end
end