Class: OrchestratorClient
- Inherits:
-
Object
- Object
- OrchestratorClient
show all
- Defined in:
- lib/orchestrator_client.rb,
lib/orchestrator_client/version.rb
Defined Under Namespace
Classes: ApiError, BadResponse, Command, Config, ConfigError, Job, Jobs
Constant Summary
collapse
- VERSION =
'0.4.3'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(overrides, load_files = false) ⇒ OrchestratorClient
Returns a new instance of OrchestratorClient.
17
18
19
20
21
|
# File 'lib/orchestrator_client.rb', line 17
def initialize(overrides, load_files=false)
@config = Config.new(overrides, load_files)
@config.validate
@http = create_http(config.root_url)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
14
15
16
|
# File 'lib/orchestrator_client.rb', line 14
def config
@config
end
|
#http ⇒ Object
Returns the value of attribute http.
15
16
17
|
# File 'lib/orchestrator_client.rb', line 15
def http
@http
end
|
Instance Method Details
#command ⇒ Object
61
62
63
|
# File 'lib/orchestrator_client.rb', line 61
def command
@command ||= OrchestratorClient::Command.new(self)
end
|
#create_http(root_url) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/orchestrator_client.rb', line 23
def create_http(root_url)
Faraday.new(url: root_url) do |f|
f.['Content-Type'] = 'application/json'
f.['X-Authentication'] = config.token
f.['User-Agent'] = config['User-Agent']
f.ssl['ca_file'] = config['cacert']
f.ssl['version'] = :TLSv1_2
if !!File::ALT_SEPARATOR
f.adapter :net_http
else
f.adapter :net_http_persistent, pool_size: 5 do |http|
http.idle_timeout = 30
end
end
end
end
|
#get(location) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/orchestrator_client.rb', line 41
def get(location)
res = http.get(location)
if res.status != 200
raise OrchestratorClient::ApiError.make_error_from_response(res)
end
JSON.parse(res.body)
end
|
#jobs ⇒ Object
65
66
67
|
# File 'lib/orchestrator_client.rb', line 65
def jobs
@jobs ||= OrchestratorClient::Jobs.new(self)
end
|
#new_job(options, type = :deploy) ⇒ Object
69
70
71
|
# File 'lib/orchestrator_client.rb', line 69
def new_job(options, type = :deploy)
OrchestratorClient::Job.new(self, options, type)
end
|
#post(location, body) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/orchestrator_client.rb', line 51
def post(location, body)
res = http.post(location, body.to_json)
unless Set.new([202, 200]).include? res.status
raise OrchestratorClient::ApiError.make_error_from_response(res)
end
JSON.parse(res.body)
end
|
#root ⇒ Object
85
86
87
|
# File 'lib/orchestrator_client.rb', line 85
def root
get(url)
end
|
#run_task(options) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/orchestrator_client.rb', line 73
def run_task(options)
if options[:plan_job] || options['plan_job']
type = :plan_task
else
type = :task
end
job = OrchestratorClient::Job.new(self, options, type)
job.start
job.wait
job.nodes['items']
end
|