Module: CemAcpt::Goss::Api
- Extended by:
- Logging
- Defined in:
- lib/cem_acpt/goss/api.rb,
lib/cem_acpt/goss/api/action_response.rb
Overview
Holds methods for interacting with the Goss API running on a test node.
Defined Under Namespace
Modules: DurationHandler Classes: ActionResponse, ActionResponseResult, ActionResponseSummary
Constant Summary collapse
- ACTIONS =
The actions that can be run against the Goss API. The key is the action name and the value is the port/endpoint of the action.
{ acpt: '8080/acpt', idempotent: '8081/idempotent', noop: '8082/noop', }.freeze
Constants included from Logging
Class Method Summary collapse
-
.action_uri(host, action) ⇒ URI
Create a URI for the specified action against the specified host.
-
.get(uri, internet = nil) ⇒ Array
Get the JSON response from the specified URI.
- .get_run_logs(host, internet = nil) ⇒ Object
-
.run_action(host, action, internet = nil) ⇒ ActionResponse
Run the specified action against the specified host.
Methods included from Logging
current_log_config, current_log_config, current_log_format, current_log_format, current_log_level, current_log_level, included, logger, logger, new_log_config, new_log_config, new_log_formatter, new_log_formatter, new_log_level, new_log_level, new_logger, new_logger, verbose?, verbose?
Class Method Details
.action_uri(host, action) ⇒ URI
Create a URI for the specified action against the specified host.
27 28 29 |
# File 'lib/cem_acpt/goss/api.rb', line 27 def action_uri(host, action) URI("http://#{host}:#{ACTIONS[action.to_sym]}") end |
.get(uri, internet = nil) ⇒ Array
Get the JSON response from the specified URI.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cem_acpt/goss/api.rb', line 36 def get(uri, internet = nil) if internet.nil? require 'net/http' response = Net::HTTP.get_response(uri) [response.code, JSON.parse(response.body)] else response = internet.get(uri.to_s) [response.status, JSON.parse(response.read)] end end |
.get_run_logs(host, internet = nil) ⇒ Object
59 60 61 62 |
# File 'lib/cem_acpt/goss/api.rb', line 59 def get_run_logs(host, internet = nil) status_code, body = get(URI("http://#{host}:8083/run-logs"), internet) ActionResponse.new(host, :run_logs, status_code, body) end |
.run_action(host, action, internet = nil) ⇒ ActionResponse
Run the specified action against the specified host.
53 54 55 56 57 |
# File 'lib/cem_acpt/goss/api.rb', line 53 def run_action(host, action, internet = nil) uri = action_uri(host, action) status_code, body = get(uri, internet) ActionResponse.new(host, action, status_code, body) end |