Class: Morpheus::Cli::Processes
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#find_available_user_option, #find_cloud_option, #find_group_option, #find_tenant_option, #get_available_user_options, #get_cloud_options, #get_group_options, #get_tenant_options, included, #load_option_source_data, #options_interface, #parse_cloud_id_list, #parse_group_id_list, #parse_option_source_id_list, #parse_project_id_list, #parse_tenant_id_list, #parse_user_id_list
#cloud_type_for_id, #cloud_type_for_name, #cloud_type_for_name_or_id, #clouds_interface, #find_cloud_by_id, #find_cloud_by_name, #find_cloud_by_name_or_id, #find_group_by_id, #find_group_by_name, #find_group_by_name_or_id, #find_network_by_id, #find_network_by_name, #find_network_by_name_or_id, #find_network_group_by_id, #find_network_group_by_name, #find_network_group_by_name_or_id, #find_network_server_type_by_id, #find_network_server_type_by_name, #find_network_server_type_by_name_or_code, #find_network_server_type_by_name_or_id, #find_network_type_by_id, #find_network_type_by_name, #find_network_type_by_name_or_id, #find_resource_pool_by_id, #find_resource_pool_by_name, #find_resource_pool_by_name_or_id, #find_resource_pool_group_by_id, #find_resource_pool_group_by_name, #find_resource_pool_group_by_name_or_id, #find_subnet_by_id, #find_subnet_by_name, #find_subnet_by_name_or_id, #find_subnet_type_by_id, #find_subnet_type_by_name, #find_subnet_type_by_name_or_id, #format_network_pool_server_status, #get_available_cloud_types, #groups_interface, included, #network_groups_interface, #network_pool_server_column_definitions, #network_pool_server_list_column_definitions, #network_pool_server_type_column_definitions, #network_pool_server_type_list_column_definitions, #network_server_type_column_definitions, #network_server_type_list_column_definitions, #network_types_interface, #networks_interface, #prompt_for_network, #prompt_for_networks, #prompt_for_pools, #prompt_for_subnets, #resource_pool_groups_interface, #resource_pools_interface, #subnet_types_interface, #subnets_interface
#accounts_interface, #add_perms_options, #api_client, #apps_interface, #cloud_datastores_interface, #clouds_interface, #datastores_interface, #find_app_by_id, #find_app_by_name, #find_app_by_name_or_id, #find_cloud_by_id_for_provisioning, #find_cloud_by_name_for_provisioning, #find_cloud_by_name_or_id_for_provisioning, #find_cloud_resource_pool_by_name_or_id, #find_group_by_id_for_provisioning, #find_group_by_name_for_provisioning, #find_group_by_name_or_id_for_provisioning, #find_host_by_id, #find_host_by_name, #find_host_by_name_or_id, #find_instance_by_id, #find_instance_by_name, #find_instance_by_name_or_id, #find_instance_type_by_code, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_instance_type_layout_by_id, #find_server_by_id, #find_server_by_name, #find_server_by_name_or_id, #find_workflow_by_id, #find_workflow_by_name, #find_workflow_by_name_or_id, #format_app_status, #format_blueprint_type, #format_container_connection_string, #format_container_status, #format_instance_connection_string, #format_instance_container_display_name, #format_instance_status, #format_metadata, #format_snapshot_status, #get_available_accounts, #get_available_clouds, #get_available_environments, #get_available_groups, #get_available_plans, #get_provision_type_for_zone_type, #get_static_environments, #get_volume_size, included, #instance_type_layouts_interface, #instance_types_interface, #instances_interface, #load_balance_protocols_dropdown, #load_service_plan_datastores, #options_interface, #parse_blueprint_type, #parse_host_id_list, #parse_instance_id_list, #parse_metadata, #parse_resource_id_list, #parse_server_id_list, #print_permissions, #prompt_evars, #prompt_exposed_ports, #prompt_instance_load_balancer, #prompt_metadata, #prompt_network_interfaces, #prompt_new_instance, #prompt_permissions, #prompt_permissions_v2, #prompt_resize_volumes, #prompt_security_groups, #prompt_service_plan_options, #prompt_volume_controller_mount_point, #prompt_volumes, #provision_types_interface, #reject_service_plan_option_types, #servers_interface
#api_client, #format_process_duration, #format_process_error, #format_process_output, #format_process_status, included, #print_process_details, #print_process_event_details, #processes_interface, #wait_for_process_execution
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Constructor Details
alias_subcommand :details, :get set_default_subcommand :list
[View source]
17
18
19
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 17
def initialize()
end
|
Instance Method Details
permalink
#cancel(args) ⇒ Object
[View source]
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 384
def cancel(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[id]")
build_standard_update_options(opts, options, [:auto_confirm])
opts. = <<-EOT
Cancel a process.
[id] is required. This is the id of a process.
Only a process that is currently running and is of a cancellable type can be canceled.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
process_id = args[0]
payload = parse_payload(options)
if payload.nil?
payload = parse_passed_options(options)
end
confirm!("Are you sure you would like to cancel process #{process_id}?", options)
@processes_interface.setopts(options)
if options[:dry_run]
print_dry_run @processes_interface.dry.cancel(process_id, payload)
return
end
json_response = @processes_interface.cancel(process_id, payload)
render_response(json_response, options) do
print_green_success "Cancelling process #{process_id}"
end
return 0, nil
end
|
permalink
#connect(options) ⇒ Object
[View source]
21
22
23
24
25
26
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 21
def connect(options)
@api_client = establish_remote_appliance_connection(options)
@processes_interface = @api_client.processes
@clouds_interface = @api_client.clouds
end
|
permalink
#event_details(args) ⇒ Object
[View source]
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 419
def event_details(args)
options = {}
params = {}
process_event_id = nil
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[event-id]")
build_common_options(opts, options, [:query, :json, :yaml, :csv, :fields, :dry_run, :remote])
opts. = "Display details for a specific process event.\n" +
"[event-id] is required. This is the id of the process event."
end
optparse.parse!(args)
if args.count != 1
puts_error optparse
return 1
end
connect(options)
begin
process_event_id = args[0]
params.merge!(parse_list_options(options))
@processes_interface.setopts(options)
if options[:dry_run]
print_dry_run @processes_interface.dry.get_event(process_event_id, params)
return
end
json_response = @processes_interface.get_event(process_event_id, params)
if options[:json]
puts as_json(json_response, options, "processEvent")
return 0
elsif options[:yaml]
puts as_yaml(json_response, options, "processEvent")
return 0
elsif options[:csv]
puts records_as_csv(json_response['processEvent'], options)
return 0
else
process_event = json_response['processEvent'] || json_response['event']
title = "Process Event Details"
subtitles = []
subtitles += parse_list_subtitles(options)
print_h1 title, subtitles
print_process_event_details(process_event, options)
print reset, "\n"
return 0
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
permalink
#get(args) ⇒ Object
[View source]
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 254
def get(args)
options = {}
params = {}
process_id = nil
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[id]")
opts.on(nil, '--details', "Display more details. Shows everything, untruncated." ) do
options[:details] = true
end
build_common_options(opts, options, [:query, :json, :yaml, :csv, :fields, :dry_run, :remote])
opts. = "Display details for a specific process.\n"
"[id] is required. This is the id of the process."
end
optparse.parse!(args)
if args.count != 1
puts_error optparse
return 1
end
connect(options)
begin
process_id = args[0]
params.merge!(parse_list_options(options))
@processes_interface.setopts(options)
if options[:dry_run]
print_dry_run @processes_interface.dry.get(process_id, params)
return
end
json_response = @processes_interface.get(process_id, params)
if options[:json]
puts as_json(json_response, options, "process")
return 0
elsif options[:yaml]
puts as_yaml(json_response, options, "process")
return 0
elsif options[:csv]
puts records_as_csv(json_response['process'], options)
return 0
else
process = json_response["process"]
title = "Process Details"
subtitles = []
subtitles << " Process ID: #{process_id}"
subtitles += parse_list_subtitles(options)
print_h1 title, subtitles
print_process_details(process, options)
print_h2 "Process Events"
process_events = process['events'] || process['processEvents'] || []
history_records = []
if process_events.empty?
puts "#{cyan}No events found.#{reset}"
print reset,"\n"
else
process_events.each do |process_event|
event_row = {
id: process_event['id'],
eventId: process_event['id'],
uniqueId: process_event['uniqueId'],
name: process_event['displayName'], description: process_event['description'],
processType: process_event['processType'] ? (process_event['processType']['name'] || process_event['processType']['code']) : process['processTypeName'],
createdBy: process_event['createdBy'] ? (process_event['createdBy']['displayName'] || process_event['createdBy']['username']) : '',
startDate: format_local_dt(process_event['startDate']),
duration: format_process_duration(process_event),
status: format_process_status(process_event),
error: format_process_error(process_event, options[:details] ? nil : 20),
output: format_process_output(process_event, options[:details] ? nil : 20)
}
history_records << event_row
end
columns = [
{:id => {:display_name => "EVENT ID"} },
:name,
:description,
{:processType => {:display_name => "PROCESS TYPE"} },
{:createdBy => {:display_name => "CREATED BY"} },
{:startDate => {:display_name => "START DATE"} },
{:duration => {:display_name => "ETA/DURATION"} },
:status,
:error,
:output
]
print cyan
print as_pretty_table(history_records, columns, options)
({size: process_events.size, total: process_events.size})
print reset, "\n"
end
return 0, nil
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
permalink
#handle(args) ⇒ Object
[View source]
28
29
30
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 28
def handle(args)
handle_subcommand(args)
end
|
permalink
#list(args) ⇒ Object
[View source]
32
33
34
35
36
37
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 32
def list(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage()
opts.on( nil, '--events', "Display sub processes (events)." ) do
options[:show_events] = true
end
opts.on( nil, '--output', "Display process output." ) do
options[:show_output] = true
end
opts.on(nil, '--details', "Display all details. Includes sub processes, output and error data is not truncated." ) do
options[:show_events] = true
options[:show_output] = true
options[:details] = true
end
opts.on('--app APP', String, "Limit results to specific app(s).") do |val|
params['appIds'] = val.split(',').collect {|it| it.to_s.strip }.reject { |it| it.empty? }
end
opts.on('--instance INSTANCE', String, "Limit results to specific instance(s).") do |val|
params['instanceIds'] = val.split(',').collect {|it| it.to_s.strip }.reject { |it| it.empty? }
end
opts.on('--container CONTAINER', String, "Limit results to specific container(s).") do |val|
params['containerIds'] = val.split(',').collect {|it| it.to_s.strip }.reject { |it| it.empty? }
end
opts.on('--host HOST', String, "Limit results to specific host(s).") do |val|
params['serverIds'] = val.split(',').collect {|it| it.to_s.strip }.reject { |it| it.empty? }
end
opts.on('--server HOST', String, "Limit results to specific servers(s).") do |val|
params['serverIds'] = val.split(',').collect {|it| it.to_s.strip }.reject { |it| it.empty? }
end
opts.add_hidden_option('--server')
opts.on('--cloud CLOUD', String, "Limit results to specific cloud(s).") do |val|
params['zoneIds'] = val.split(',').collect {|it| it.to_s.strip }.reject { |it| it.empty? }
end
opts.on('--user USER', String, "Limit results to user(s).") do |val|
options[:user] = val
end
build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
opts. = "List historical processes."
end
optparse.parse!(args)
if args.count != 0
puts optparse
return 1
end
connect(options)
begin
params.merge!(parse_list_options(options))
if params['instanceIds']
params['instanceIds'] = params['instanceIds'].collect do |instance_id|
if instance_id.to_s =~ /\A\d{1,}\Z/
instance_id.to_i
else
instance = find_instance_by_name_or_id(instance_id)
if instance.nil?
return 1, "instance not found for '#{instance_id}'" end
instance['id']
end
end
end
if params['serverIds']
params['serverIds'] = params['serverIds'].collect do |server_id|
if server_id.to_s =~ /\A\d{1,}\Z/
server_id.to_i
else
server = find_server_by_name_or_id(server_id)
if server.nil?
return 1, "server not found for '#{server_id}'" end
server['id']
end
end
end
if params['appIds']
params['appIds'] = params['appIds'].collect do |app_id|
if app_id.to_s =~ /\A\d{1,}\Z/
app_id.to_i
else
app = find_app_by_name_or_id(app_id)
if app.nil?
return 1, "app not found for '#{app_id}'" end
app['id']
end
end
end
if params['zoneIds']
params['zoneIds'] = params['zoneIds'].collect do |zone_id|
if zone_id.to_s =~ /\A\d{1,}\Z/
zone_id.to_i
else
zone = find_cloud_by_name_or_id(zone_id)
if zone.nil?
return 1, "cloud not found for '#{zone_id}'" end
zone['id']
end
end
end
if options[:user]
user = find_available_user_option(options[:user])
return 1, "user not found by '#{options[:user]}'" if user.nil?
params['userId'] = user['id']
end
@processes_interface.setopts(options)
if options[:dry_run]
print_dry_run @processes_interface.dry.list(params)
return
end
json_response = @processes_interface.list(params)
if options[:json]
puts as_json(json_response, options, "processes")
return 0
elsif options[:yaml]
puts as_yaml(json_response, options, "processes")
return 0
elsif options[:csv]
puts records_as_csv(json_response['processes'], options)
return 0
else
title = "Process List"
subtitles = []
if params[:query]
subtitles << "Search: #{params[:query]}".strip
end
subtitles += parse_list_subtitles(options)
print_h1 title, subtitles
if json_response['processes'].empty?
print "#{cyan}No process history found.#{reset}\n\n"
return 0
else
history_records = []
json_response["processes"].each do |process|
row = {
id: process['id'],
eventId: nil,
uniqueId: process['uniqueId'],
name: process['displayName'],
description: process['description'],
processType: process['processType'] ? (process['processType']['name'] || process['processType']['code']) : process['processTypeName'],
createdBy: process['createdBy'] ? (process['createdBy']['displayName'] || process['createdBy']['username']) : '',
startDate: format_local_dt(process['startDate']),
duration: format_process_duration(process),
status: format_process_status(process),
error: format_process_error(process, options[:details] ? nil : 20),
output: format_process_output(process, options[:details] ? nil : 20)
}
history_records << row
process_events = process['events'] || process['processEvents']
if options[:show_events]
if process_events
process_events.each do |process_event|
event_row = {
id: process['id'],
eventId: process_event['id'],
uniqueId: process_event['uniqueId'],
name: process_event['displayName'], description: process_event['description'],
processType: process_event['processType'] ? (process_event['processType']['name'] || process_event['processType']['code']) : process['processTypeName'],
createdBy: process_event['createdBy'] ? (process_event['createdBy']['displayName'] || process_event['createdBy']['username']) : '',
startDate: format_local_dt(process_event['startDate']),
duration: format_process_duration(process_event),
status: format_process_status(process_event),
error: format_process_error(process_event, options[:details] ? nil : 20),
output: format_process_output(process_event, options[:details] ? nil : 20)
}
history_records << event_row
end
else
end
end
end
columns = [
{:id => {:display_name => "PROCESS ID"} },
:name,
:description,
{:processType => {:display_name => "PROCESS TYPE"} },
{:createdBy => {:display_name => "CREATED BY"} },
{:startDate => {:display_name => "START DATE"} },
{:duration => {:display_name => "ETA/DURATION"} },
:status,
:error
]
if options[:show_events]
columns.insert(1, {:eventId => {:display_name => "EVENT ID"} })
end
if options[:show_output]
columns << :output
end
if options[:include_fields]
columns = options[:include_fields]
end
print cyan
print as_pretty_table(history_records, columns, options)
if options[:show_events]
({size: history_records.size, total: history_records.size}, {:label => "process", :n_label => "processes"})
else
(json_response, {:label => "process", :n_label => "processes"})
end
print reset, "\n"
return 0
end
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
permalink
#retry(args) ⇒ Object
[View source]
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
# File 'lib/morpheus/cli/commands/processes_command.rb', line 349
def retry(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[id]")
build_standard_update_options(opts, options, [:auto_confirm])
opts. = <<-EOT
Retry a process.
[id] is required. This is the id of a process.
Only a process that is failed or cancelled and is of a retryable type can be retried.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
process_id = args[0]
payload = parse_payload(options)
if payload.nil?
payload = parse_passed_options(options)
end
confirm!("Are you sure you would like to retry process #{process_id}?", options)
@processes_interface.setopts(options)
if options[:dry_run]
print_dry_run @processes_interface.dry.retry(process_id, payload)
return
end
json_response = @processes_interface.retry(process_id, payload)
render_response(json_response, options) do
print_green_success "Retrying process #{process_id}"
end
return 0, nil
end
|