Module: Aptible::CLI::Helpers::Operation
- Includes:
- Ssh
- Defined in:
- lib/aptible/cli/helpers/operation.rb
Constant Summary
collapse
- POLL_INTERVAL =
1
Instance Method Summary
collapse
Methods included from Ssh
#connect_to_ssh_portal, #exit_with_ssh_portal, #with_ssh_cmd
Methods included from ConfigPath
#aptible_config_path
Instance Method Details
#attach_to_operation_logs(operation) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/aptible/cli/helpers/operation.rb', line 26
def attach_to_operation_logs(operation)
ENV['ACCESS_TOKEN'] = fetch_token
code = connect_to_ssh_portal(
operation,
'-o', 'SendEnv=ACCESS_TOKEN'
)
unless code == 0
msg = ['Disconnected from logs, waiting for operation to complete',
'Once complete, the logs can be viewed here:',
" #{ui_log_url(operation)}"]
msg.each { |e| CLI.logger.warn e }
poll_for_success(operation)
end
end
|
#cancel_operation(operation) ⇒ Object
49
50
51
52
|
# File 'lib/aptible/cli/helpers/operation.rb', line 49
def cancel_operation(operation)
CLI.logger.info "Cancelling #{prettify_operation(operation)}..."
operation.update!(cancelled: true)
end
|
#operation_logs(operation) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/aptible/cli/helpers/operation.rb', line 54
def operation_logs(operation)
res = get_operation_logs_redirect(operation)
s3_file_request = get_operation_logs_s3_file(res.body)
m = "Printing out results of operation logs for #{operation.id}"
CLI.logger.info m
puts s3_file_request.body
end
|
#poll_for_success(operation) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/aptible/cli/helpers/operation.rb', line 12
def poll_for_success(operation)
wait_for_completion operation
return if operation.status == 'succeeded'
raise Thor::Error, "Operation ##{operation.id} failed."
end
|
#prettify_operation(o) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/aptible/cli/helpers/operation.rb', line 63
def prettify_operation(o)
bits = [o.status, o.type, "##{o.id}"]
if o.resource.respond_to?(:handle)
bits.concat ['on', o.resource.handle]
end
bits.join ' '
end
|
#wait_for_completion(operation) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/aptible/cli/helpers/operation.rb', line 19
def wait_for_completion(operation)
while %w(queued running).include? operation.status
sleep 1
operation.get
end
end
|