Module: WrataApi::ServerMethods
- Included in:
- WrataApi
- Defined in:
- lib/wrata_api/server_methods.rb
Overview
Methods for getting server status
Instance Method Summary collapse
- #book_server(server_name) ⇒ Nothing
-
#executing_test?(server_name) ⇒ True, False
Check if server execute some test.
-
#free_servers(count) ⇒ Array, Hash
Got as much free servers as ‘count`.
- #power_off_server(server_name) ⇒ Nothing
- #power_on_server(server_name, size = nil) ⇒ Nothing
-
#powering_status(server_name) ⇒ Symbol
If server is powered on or off.
-
#server_data(server_name) ⇒ Hash
Return servers data.
-
#server_status_timeout_error(server, status) ⇒ String
Error for server timeout.
-
#servers ⇒ Array, String
List of all servers.
- #unbook_server(server_name) ⇒ Nothing
-
#wait_for_server_have_status(server, status) ⇒ Nothing
Waiting until server have statue.
Instance Method Details
#book_server(server_name) ⇒ Nothing
62 63 64 65 |
# File 'lib/wrata_api/server_methods.rb', line 62 def book_server(server_name) uri = URI.parse("#{@uri}/queue/book_server") perform_post(uri, 'server' => server_name) end |
#executing_test?(server_name) ⇒ True, False
Returns check if server execute some test.
48 49 50 51 |
# File 'lib/wrata_api/server_methods.rb', line 48 def executing_test?(server_name) all_data = server_data(server_name) all_data.key?('test') end |
#free_servers(count) ⇒ Array, Hash
Got as much free servers as ‘count`
16 17 18 19 20 21 22 23 24 |
# File 'lib/wrata_api/server_methods.rb', line 16 def free_servers(count) free = ServerList.new(self) raise NotEnoughServerCount if count > servers.length servers.each do |single_server| free.servers << single_server if single_server['book_client_id'].nil? return free if free.length == count end end |
#power_off_server(server_name) ⇒ Nothing
79 80 81 82 83 84 85 86 |
# File 'lib/wrata_api/server_methods.rb', line 79 def power_off_server(server_name) return if powering_status(server_name) == :off unbook_server(server_name) uri = URI.parse("#{@uri}/servers/cloud_server_destroy") perform_post(uri, 'server' => server_name) wait_for_server_have_status(server_name, :off) end |
#power_on_server(server_name, size = nil) ⇒ Nothing
69 70 71 72 73 74 75 |
# File 'lib/wrata_api/server_methods.rb', line 69 def power_on_server(server_name, size = nil) return if powering_status(server_name) == :on uri = URI.parse("#{@uri}/servers/cloud_server_create") perform_post(uri, 'server' => server_name, 'size' => size) wait_for_server_have_status(server_name, :on) end |
#powering_status(server_name) ⇒ Symbol
Returns if server is powered on or off.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wrata_api/server_methods.rb', line 34 def powering_status(server_name) all_data = server_data(server_name) status = all_data['_status'] case status when 'created' :on when 'destroyed' :off else :other end end |
#server_data(server_name) ⇒ Hash
Return servers data
27 28 29 30 31 |
# File 'lib/wrata_api/server_methods.rb', line 27 def server_data(server_name) uri = URI.parse("#{@uri}/runner/updated_data") response = perform_get(uri, 'servers' => [{ name: server_name }].to_json) response['servers_data'].first end |
#server_status_timeout_error(server, status) ⇒ String
Returns error for server timeout.
108 109 110 111 |
# File 'lib/wrata_api/server_methods.rb', line 108 def server_status_timeout_error(server, status) "Couldn't wait until #{server} have status "\ "#{status} in specified timeout" end |
#servers ⇒ Array, String
Returns list of all servers.
8 9 10 11 |
# File 'lib/wrata_api/server_methods.rb', line 8 def servers uri = URI.parse("#{@uri}/servers.json") perform_get(uri) end |
#unbook_server(server_name) ⇒ Nothing
55 56 57 58 |
# File 'lib/wrata_api/server_methods.rb', line 55 def unbook_server(server_name) uri = URI.parse("#{@uri}/queue/unbook_server") perform_post(uri, 'server' => server_name) end |
#wait_for_server_have_status(server, status) ⇒ Nothing
Waiting until server have statue
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/wrata_api/server_methods.rb', line 92 def wait_for_server_have_status(server, status) current_wait_time = 0 loop do return if powering_status(server) == status @logger.info("Wait for state: #{status}: \ #{current_wait_time} of: #{@waiting_timeout}") sleep @between_request_timeout current_wait_time += @between_request_timeout raise(server_status_timeout_error(server, status)) if current_wait_time > @waiting_timeout end end |