Class: Kontena::Machine::Upcloud::NodeRestarter
- Inherits:
-
Object
- Object
- Kontena::Machine::Upcloud::NodeRestarter
- Includes:
- Cli::ShellSpinner, RandomName
- Defined in:
- lib/kontena/machine/upcloud/node_restarter.rb
Instance Attribute Summary collapse
-
#uc_client ⇒ Object
readonly
Returns the value of attribute uc_client.
Instance Method Summary collapse
-
#initialize(upcloud_username, upcloud_password) ⇒ NodeRestarter
constructor
A new instance of NodeRestarter.
- #run!(name) ⇒ Object
Constructor Details
#initialize(upcloud_username, upcloud_password) ⇒ NodeRestarter
Returns a new instance of NodeRestarter.
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_client ⇒ Object (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 |