Class: Bosh::Cli::Client::ErrandsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/client/errands_client.rb

Defined Under Namespace

Classes: ErrandResult

Instance Method Summary collapse

Constructor Details

#initialize(director) ⇒ ErrandsClient

Returns a new instance of ErrandsClient.



20
21
22
# File 'lib/cli/client/errands_client.rb', line 20

def initialize(director)
  @director = director
end

Instance Method Details

#run_errand(deployment_name, errand_name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cli/client/errands_client.rb', line 24

def run_errand(deployment_name, errand_name)
  url = "/deployments/#{deployment_name}/errands/#{errand_name}/runs"
  options = { content_type: 'application/json', payload: '{}' }

  status, task_id = @director.request_and_track(:post, url, options)

  if status != :done
    return [status, task_id, nil]
  end

  task_result = JSON.parse(@director.get_task_result_log(task_id))
  errand_result = ErrandResult.new(*task_result.values_at('exit_code', 'stdout', 'stderr'))

  [status, task_id, errand_result]
end