Module: CemAcpt::Goss::Api
- 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
Class Method Summary collapse
-
.action_uri(host, action) ⇒ URI
Create a URI for the specified action against the specified host.
-
.run_action(internet, host, action) ⇒ ActionResponse
Run the specified action against the specified host.
-
.run_actions_async(hosts, results: Queue.new, only: [], except: []) ⇒ Queue
Run the specified actions against the specified hosts asynchronously.
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 |
.run_action(internet, host, action) ⇒ ActionResponse
Run the specified action against the specified host.
74 75 76 77 78 79 |
# File 'lib/cem_acpt/goss/api.rb', line 74 def run_action(internet, host, action) uri = action_uri(host, action) response = internet.get(uri.to_s) body = JSON.parse(response.read) ActionResponse.new(host, action, response.status, body) end |
.run_actions_async(hosts, results: Queue.new, only: [], except: []) ⇒ Queue
Run the specified actions against the specified hosts asynchronously.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cem_acpt/goss/api.rb', line 38 def run_actions_async(hosts, results: Queue.new, only: [], except: []) raise ArgumentError, 'hosts must be an Array' unless hosts.is_a?(Array) raise ArgumentError, 'results must be a Queue-like object implementing #<<' unless results.respond_to?(:<<) raise ArgumentError, 'only must be an Array' unless except.is_a?(Array) raise ArgumentError, 'except must be an Array' unless except.is_a?(Array) only.map!(&:to_sym) except.map!(&:to_sym) only_specified = !only.empty? except_specified = !except.empty? Async do internet = Async::HTTP::Internet.new = Async::Barrier.new .async do hosts.each do |host| ACTIONS.keys.each do |action, _| next if only_specified && !only.include?(action) next if except_specified && except.include?(action) results << run_action(internet, host, action) end end end .wait ensure internet&.close results.close if results.respond_to?(:close) end results end |