morpheus-cli 5.2.4 → 5.3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/README.md +3 -3
- data/lib/morpheus/cli/activity_command.rb +7 -4
- data/lib/morpheus/cli/backup_jobs_command.rb +1 -1
- data/lib/morpheus/cli/backups_command.rb +2 -3
- data/lib/morpheus/cli/cli_command.rb +19 -9
- data/lib/morpheus/cli/clusters.rb +4 -1
- data/lib/morpheus/cli/commands/standard/history_command.rb +4 -5
- data/lib/morpheus/cli/dashboard_command.rb +3 -3
- data/lib/morpheus/cli/execution_request_command.rb +15 -5
- data/lib/morpheus/cli/invoices_command.rb +29 -97
- data/lib/morpheus/cli/mixins/option_source_helper.rb +15 -16
- data/lib/morpheus/cli/mixins/print_helper.rb +3 -0
- data/lib/morpheus/cli/network_domains_command.rb +2 -2
- data/lib/morpheus/cli/remote.rb +2 -1
- data/lib/morpheus/cli/reports_command.rb +1 -1
- data/lib/morpheus/cli/service_plans_command.rb +4 -1
- data/lib/morpheus/cli/user_sources_command.rb +118 -134
- data/lib/morpheus/cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 537ea8ecb044cb316ca3c7610ff9d48d2cfdea448c37c2ce171d797143b9d5bb
|
4
|
+
data.tar.gz: e80110f66f9a28496f507bebc117fb7aa74f770f33f8aadb9078bf331b4099f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fff28a9b02ccbff264efa449fd56455316af3263c990cc15f37eae658f45c44e47f5138c33428744d0b687850fa7a710f9fe7193ca753da82057c5570da1ab0
|
7
|
+
data.tar.gz: 7738424a32347e6e51970a7b4542accf527057f1634f4a798ec8e98cf0a908c92b5a14a0fda217dd2f94f2666c0d588f9935d5a0f2ab71b7dc78daa04b97563f
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
<img src="https://morpheusdata.com/wp-content/uploads/2020/04/morpheus-logo-v2.svg" width="200px">
|
2
|
+
|
1
3
|
# Morpheus CLI
|
2
4
|
|
3
5
|
- Website: https://www.morpheusdata.com/
|
4
6
|
- Guide: [Morpheus CLI Wiki](https://github.com/gomorpheus/morpheus-cli/wiki)
|
5
|
-
- Docs: [Morpheus Documentation](https://
|
7
|
+
- Docs: [Morpheus CLI Documentation](https://clidocs.morpheusdata.com)
|
6
8
|
- Support: [Morpheus Support](https://support.morpheusdata.com)
|
7
9
|
|
8
|
-
<img src="https://www.morpheusdata.com/wp-content/uploads/2018/06/cropped-morpheus_highres.png" width="600px">
|
9
|
-
|
10
10
|
This library is a Ruby gem that provides a command line interface for interacting with the Morpheus Data appliance. The features provided include provisioning clusters, hosts, and containers, deploying and monitoring applications, automating tasks, and much more.
|
11
11
|
|
12
12
|
## Installation
|
@@ -22,6 +22,9 @@ class Morpheus::Cli::ActivityCommand
|
|
22
22
|
params, options = {}, {}
|
23
23
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
24
24
|
opts.banner = subcommand_usage()
|
25
|
+
opts.on('-a', '--details', "Display more details object id, full date and time, etc." ) do
|
26
|
+
options[:details] = true
|
27
|
+
end
|
25
28
|
opts.on('-t','--type TYPE', "Activity Type eg. Provisioning, Admin") do |val|
|
26
29
|
options[:type] ||= []
|
27
30
|
options[:type] << val
|
@@ -115,20 +118,20 @@ EOT
|
|
115
118
|
# {"SEVERITY" => lambda {|record| format_activity_severity(record['severity']) } },
|
116
119
|
{"TYPE" => lambda {|record| record['activityType'] } },
|
117
120
|
{"NAME" => lambda {|record| record['name'] } },
|
118
|
-
{"RESOURCE" => lambda {|record| "#{record['objectType']} #{record['objectId']}" } },
|
121
|
+
options[:details] ? {"RESOURCE" => lambda {|record| "#{record['objectType']} #{record['objectId']}" } } : nil,
|
119
122
|
{"MESSAGE" => lambda {|record| record['message'] || '' } },
|
120
123
|
{"USER" => lambda {|record| record['user'] ? record['user']['username'] : record['userName'] } },
|
121
124
|
#{"DATE" => lambda {|record| "#{format_duration_ago(record['ts'] || record['timestamp'])}" } },
|
122
125
|
{"DATE" => lambda {|record|
|
123
|
-
# show full time if searching for custom timerange, otherwise the default is to show relative time
|
124
|
-
if params['start'] || params['end'] || params['timeframe']
|
126
|
+
# show full time if searching for custom timerange or --details, otherwise the default is to show relative time
|
127
|
+
if params['start'] || params['end'] || params['timeframe'] || options[:details]
|
125
128
|
"#{format_local_dt(record['ts'] || record['timestamp'])}"
|
126
129
|
else
|
127
130
|
"#{format_duration_ago(record['ts'] || record['timestamp'])}"
|
128
131
|
end
|
129
132
|
|
130
133
|
} },
|
131
|
-
]
|
134
|
+
].compact
|
132
135
|
print as_pretty_table(activity, columns, options)
|
133
136
|
print_results_pagination(json_response)
|
134
137
|
end
|
@@ -10,7 +10,7 @@ class Morpheus::Cli::BackupJobsCommand
|
|
10
10
|
|
11
11
|
set_command_name :'backup-jobs'
|
12
12
|
|
13
|
-
register_subcommands :list, :get
|
13
|
+
register_subcommands :list, :get #, :add, :update, :remove, :run
|
14
14
|
|
15
15
|
def connect(opts)
|
16
16
|
@api_client = establish_remote_appliance_connection(opts)
|
@@ -10,7 +10,7 @@ class Morpheus::Cli::BackupsCommand
|
|
10
10
|
|
11
11
|
set_command_name :'backups'
|
12
12
|
|
13
|
-
register_subcommands :list, :get
|
13
|
+
register_subcommands :list, :get #, :add, :update, :remove, :run, :restore
|
14
14
|
|
15
15
|
def connect(opts)
|
16
16
|
@api_client = establish_remote_appliance_connection(opts)
|
@@ -82,8 +82,7 @@ EOT
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def _get(id, options)
|
86
|
-
params = {}
|
85
|
+
def _get(id, params, options)
|
87
86
|
@backups_interface.setopts(options)
|
88
87
|
if options[:dry_run]
|
89
88
|
print_dry_run @backups_interface.dry.get(id, params)
|
@@ -466,11 +466,16 @@ module Morpheus
|
|
466
466
|
|
467
467
|
when :list
|
468
468
|
opts.on( '-m', '--max MAX', "Max Results" ) do |val|
|
469
|
-
max
|
470
|
-
if
|
471
|
-
|
469
|
+
# api supports max=-1 for all at the moment..
|
470
|
+
if val.to_s == "all" || val.to_s == "-1"
|
471
|
+
options[:max] = "-1"
|
472
|
+
else
|
473
|
+
max = val.to_i
|
474
|
+
if max <= 0
|
475
|
+
raise ::OptionParser::InvalidArgument.new("must be a positive integer")
|
476
|
+
end
|
477
|
+
options[:max] = max
|
472
478
|
end
|
473
|
-
options[:max] = max
|
474
479
|
end
|
475
480
|
|
476
481
|
opts.on( '-o', '--offset OFFSET', "Offset Results" ) do |val|
|
@@ -486,12 +491,17 @@ module Morpheus
|
|
486
491
|
end
|
487
492
|
|
488
493
|
opts.on( '-S', '--sort ORDER', "Sort Order. DIRECTION may be included as \"ORDER [asc|desc]\"." ) do |v|
|
489
|
-
|
490
|
-
|
491
|
-
options[:sort] = v_parts[0]
|
492
|
-
options[:direction] = (v_parts[1].strip == "desc") ? "desc" : "asc"
|
493
|
-
else
|
494
|
+
if v.to_s.include?(",")
|
495
|
+
# sorting on multiple properties, just pass it as is, newer api supports multiple fields
|
494
496
|
options[:sort] = v
|
497
|
+
else
|
498
|
+
v_parts = v.to_s.split(" ")
|
499
|
+
if v_parts.size > 1
|
500
|
+
options[:sort] = v_parts[0]
|
501
|
+
options[:direction] = (v_parts[1].strip == "desc") ? "desc" : "asc"
|
502
|
+
else
|
503
|
+
options[:sort] = v
|
504
|
+
end
|
495
505
|
end
|
496
506
|
end
|
497
507
|
|
@@ -934,6 +934,9 @@ class Morpheus::Cli::Clusters
|
|
934
934
|
end
|
935
935
|
else
|
936
936
|
payload = {"permissions" => prompt_permissions(options.merge({:available_plans => namespace_service_plans}))}
|
937
|
+
# if payload["permissions"] && payload["permissions"]["resourcePool"]
|
938
|
+
# payload["permissions"].delete("resourcePool")
|
939
|
+
# end
|
937
940
|
end
|
938
941
|
|
939
942
|
@clusters_interface.setopts(options)
|
@@ -3897,8 +3900,8 @@ class Morpheus::Cli::Clusters
|
|
3897
3900
|
perms = prompt_permissions(options.merge({:available_plans => namespace_service_plans}))
|
3898
3901
|
if perms['resourcePool'] && !perms['resourcePool']['visibility'].nil?
|
3899
3902
|
rtn['visibility'] = perms['resourcePool']['visibility']
|
3900
|
-
perms.delete('resourcePool')
|
3901
3903
|
end
|
3904
|
+
perms.delete('resourcePool')
|
3902
3905
|
rtn['permissions'] = perms
|
3903
3906
|
rtn
|
3904
3907
|
end
|
@@ -14,14 +14,14 @@ class Morpheus::Cli::HistoryCommand
|
|
14
14
|
# AND start logging every terminal command, not just shell...
|
15
15
|
def handle(args)
|
16
16
|
options = {show_pagination:false}
|
17
|
-
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
18
|
-
opts.banner = "Usage:
|
17
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
18
|
+
opts.banner = "Usage: #{prog_name} #{command_name} [search]"
|
19
19
|
# -n is a hidden alias for -m
|
20
20
|
opts.on( '-n', '--max-commands MAX', "Alias for -m, --max option." ) do |val|
|
21
21
|
options[:max] = val
|
22
22
|
end
|
23
23
|
opts.add_hidden_option('-n')
|
24
|
-
opts.on( '-p', '--pagination', "Display pagination and count info eg. Viewing 1-
|
24
|
+
opts.on( '-p', '--pagination', "Display pagination and count info eg. Viewing 1-25 of 42" ) do
|
25
25
|
options[:show_pagination] = true
|
26
26
|
end
|
27
27
|
opts.on( nil, '--flush', "Flush history, purges entire shell history file." ) do
|
@@ -38,10 +38,9 @@ Examples:
|
|
38
38
|
history "instances list"
|
39
39
|
history --flush
|
40
40
|
|
41
|
-
The most recently executed commands are seen by default. Use --
|
41
|
+
The most recently executed commands are seen by default. Use --desc to see the oldest commands.
|
42
42
|
EOT
|
43
43
|
end
|
44
|
-
raw_cmd = "#{command_name} #{args.join(' ')}"
|
45
44
|
optparse.parse!(args)
|
46
45
|
# verify_args!(args:args, count: 0, optparse:optparse)
|
47
46
|
if args.count > 0
|
@@ -272,20 +272,20 @@ This includes instance and backup counts, favorite instances, monitoring and rec
|
|
272
272
|
# {"SEVERITY" => lambda {|record| format_activity_severity(record['severity']) } },
|
273
273
|
{"TYPE" => lambda {|record| record['activityType'] } },
|
274
274
|
{"NAME" => lambda {|record| record['name'] } },
|
275
|
-
{"RESOURCE" => lambda {|record| "#{record['objectType']} #{record['objectId']}" } },
|
275
|
+
options[:details] ? {"RESOURCE" => lambda {|record| "#{record['objectType']} #{record['objectId']}" } } : nil,
|
276
276
|
{"MESSAGE" => lambda {|record| record['message'] || '' } },
|
277
277
|
{"USER" => lambda {|record| record['user'] ? record['user']['username'] : record['userName'] } },
|
278
278
|
#{"DATE" => lambda {|record| "#{format_duration_ago(record['ts'] || record['timestamp'])}" } },
|
279
279
|
{"DATE" => lambda {|record|
|
280
280
|
# show full time if searching for custom timerange, otherwise the default is to show relative time
|
281
|
-
if params['start'] || params['end'] || params['timeframe']
|
281
|
+
if params['start'] || params['end'] || params['timeframe'] || options[:details]
|
282
282
|
"#{format_local_dt(record['ts'] || record['timestamp'])}"
|
283
283
|
else
|
284
284
|
"#{format_duration_ago(record['ts'] || record['timestamp'])}"
|
285
285
|
end
|
286
286
|
|
287
287
|
} },
|
288
|
-
]
|
288
|
+
].compact
|
289
289
|
print as_pretty_table(activity, columns, options)
|
290
290
|
# print_results_pagination(json_response)
|
291
291
|
# print reset,"\n"
|
@@ -31,6 +31,10 @@ class Morpheus::Cli::ExecutionRequestCommand
|
|
31
31
|
handle_subcommand(args)
|
32
32
|
end
|
33
33
|
|
34
|
+
def default_refresh_interval
|
35
|
+
5
|
36
|
+
end
|
37
|
+
|
34
38
|
def get(args)
|
35
39
|
raw_args = args
|
36
40
|
options = {}
|
@@ -134,7 +138,7 @@ class Morpheus::Cli::ExecutionRequestCommand
|
|
134
138
|
options = {}
|
135
139
|
params = {}
|
136
140
|
script_content = nil
|
137
|
-
|
141
|
+
options[:refresh_until_finished] = true
|
138
142
|
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
139
143
|
opts.banner = subcommand_usage("[options]")
|
140
144
|
opts.on('--server ID', String, "Server ID") do |val|
|
@@ -161,8 +165,14 @@ class Morpheus::Cli::ExecutionRequestCommand
|
|
161
165
|
exit 1
|
162
166
|
end
|
163
167
|
end
|
164
|
-
opts.on(
|
165
|
-
|
168
|
+
opts.on('--refresh [SECONDS]', String, "Refresh until execution is finished. Default interval is #{default_refresh_interval} seconds.") do |val|
|
169
|
+
options[:refresh_until_finished] = true
|
170
|
+
if !val.to_s.empty?
|
171
|
+
options[:refresh_interval] = val.to_f
|
172
|
+
end
|
173
|
+
end
|
174
|
+
opts.on(nil, '--no-refresh', "Do not refresh. The default behavior is to refresh until finished." ) do
|
175
|
+
options[:refresh_until_finished] = false
|
166
176
|
end
|
167
177
|
#build_option_type_options(opts, options, add_user_source_option_types())
|
168
178
|
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
|
@@ -212,8 +222,8 @@ class Morpheus::Cli::ExecutionRequestCommand
|
|
212
222
|
end
|
213
223
|
execution_request = json_response['executionRequest']
|
214
224
|
print_green_success "Executing request #{execution_request['uniqueId']}"
|
215
|
-
if
|
216
|
-
get([execution_request['uniqueId'], "--refresh"] + (options[:remote] ? ["-r",options[:remote]] : []))
|
225
|
+
if options[:refresh_until_finished]
|
226
|
+
get([execution_request['uniqueId'], "--refresh", options[:refresh_interval] ? options[:refresh_interval].to_s : nil].compact + (options[:remote] ? ["-r",options[:remote]] : []))
|
217
227
|
else
|
218
228
|
get([execution_request['uniqueId']] + (options[:remote] ? ["-r",options[:remote]] : []))
|
219
229
|
end
|
@@ -33,7 +33,6 @@ class Morpheus::Cli::InvoicesCommand
|
|
33
33
|
options[:show_estimates] = true
|
34
34
|
# options[:show_costs] = true
|
35
35
|
options[:show_prices] = true
|
36
|
-
# options[:show_raw_data] = true
|
37
36
|
end
|
38
37
|
opts.on('--dates', "Display Ref Start, Ref End, etc.") do |val|
|
39
38
|
options[:show_dates] = true
|
@@ -117,9 +116,6 @@ class Morpheus::Cli::InvoicesCommand
|
|
117
116
|
options[:tags][k] << (v || '')
|
118
117
|
end
|
119
118
|
end
|
120
|
-
opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
|
121
|
-
options[:show_raw_data] = true
|
122
|
-
end
|
123
119
|
opts.on('--totals', "View total costs and prices for all the invoices found.") do |val|
|
124
120
|
params['includeTotals'] = true
|
125
121
|
options[:show_invoice_totals] = true
|
@@ -144,36 +140,35 @@ class Morpheus::Cli::InvoicesCommand
|
|
144
140
|
# construct params
|
145
141
|
params.merge!(parse_list_options(options))
|
146
142
|
if options[:clouds]
|
147
|
-
cloud_ids = parse_cloud_id_list(options[:clouds])
|
143
|
+
cloud_ids = parse_cloud_id_list(options[:clouds], {}, false, true)
|
148
144
|
return 1, "clouds not found for #{options[:clouds]}" if cloud_ids.nil?
|
149
145
|
params['zoneId'] = cloud_ids
|
150
146
|
end
|
151
147
|
if options[:groups]
|
152
|
-
group_ids = parse_group_id_list(options[:groups])
|
148
|
+
group_ids = parse_group_id_list(options[:groups], {}, false, true)
|
153
149
|
return 1, "groups not found for #{options[:groups]}" if group_ids.nil?
|
154
150
|
params['siteId'] = group_ids
|
155
151
|
end
|
156
152
|
if options[:instances]
|
157
|
-
instance_ids = parse_instance_id_list(options[:instances])
|
153
|
+
instance_ids = parse_instance_id_list(options[:instances], {}, false, true)
|
158
154
|
return 1, "instances not found for #{options[:instances]}" if instance_ids.nil?
|
159
155
|
params['instanceId'] = instance_ids
|
160
156
|
end
|
161
157
|
if options[:servers]
|
162
|
-
server_ids = parse_server_id_list(options[:servers])
|
158
|
+
server_ids = parse_server_id_list(options[:servers], {}, false, true)
|
163
159
|
return 1, "servers not found for #{options[:servers]}" if server_ids.nil?
|
164
160
|
params['serverId'] = server_ids
|
165
161
|
end
|
166
162
|
if options[:users]
|
167
|
-
user_ids = parse_user_id_list(options[:users])
|
163
|
+
user_ids = parse_user_id_list(options[:users], {}, false, true)
|
168
164
|
return 1, "users not found for #{options[:users]}" if user_ids.nil?
|
169
165
|
params['userId'] = user_ids
|
170
166
|
end
|
171
167
|
if options[:projects]
|
172
|
-
project_ids = parse_project_id_list(options[:projects])
|
168
|
+
project_ids = parse_project_id_list(options[:projects], {}, false, true)
|
173
169
|
return 1, "projects not found for #{options[:projects]}" if project_ids.nil?
|
174
170
|
params['projectId'] = project_ids
|
175
171
|
end
|
176
|
-
params['rawData'] = true if options[:show_raw_data]
|
177
172
|
params['refId'] = ref_ids unless ref_ids.empty?
|
178
173
|
if options[:tags] && !options[:tags].empty?
|
179
174
|
options[:tags].each do |k,v|
|
@@ -271,7 +266,7 @@ class Morpheus::Cli::InvoicesCommand
|
|
271
266
|
columns += [
|
272
267
|
{"ESTIMATE" => lambda {|it| format_boolean(it['estimate']) } },
|
273
268
|
{"ACTIVE" => lambda {|it| format_boolean(it['active']) } },
|
274
|
-
{"ITEMS" => lambda {|it| it['lineItems'].size rescue '' } },
|
269
|
+
{"ITEMS" => lambda {|it| (it['lineItemCount'] ? it['lineItemCount'] : it['lineItems'].size) rescue '' } },
|
275
270
|
{"TAGS" => lambda {|it| (it['metadata'] || it['tags']) ? (it['metadata'] || it['tags']).collect {|m| "#{m['name']}: #{m['value']}" }.join(', ') : '' } },
|
276
271
|
]
|
277
272
|
if show_projects
|
@@ -291,9 +286,6 @@ class Morpheus::Cli::InvoicesCommand
|
|
291
286
|
{"CREATED" => lambda {|it| format_local_dt(it['dateCreated']) } },
|
292
287
|
{"UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } },
|
293
288
|
]
|
294
|
-
if options[:show_raw_data]
|
295
|
-
columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }]
|
296
|
-
end
|
297
289
|
unless options[:totals_only]
|
298
290
|
print as_pretty_table(invoices, columns, options)
|
299
291
|
print_results_pagination(json_response, {:label => "invoice", :n_label => "invoices"})
|
@@ -361,7 +353,6 @@ class Morpheus::Cli::InvoicesCommand
|
|
361
353
|
options[:show_estimates] = true
|
362
354
|
# options[:show_costs] = true
|
363
355
|
options[:show_prices] = true
|
364
|
-
# options[:show_raw_data] = true
|
365
356
|
options[:max_line_items] = 10000
|
366
357
|
end
|
367
358
|
opts.on('--prices', '--prices', "Display prices: Total, Compute, Storage, Network, Extra" ) do
|
@@ -370,13 +361,6 @@ class Morpheus::Cli::InvoicesCommand
|
|
370
361
|
opts.on('--estimates', '--estimates', "Display all estimated costs, from usage info: Compute, Storage, Network, Extra" ) do
|
371
362
|
options[:show_estimates] = true
|
372
363
|
end
|
373
|
-
opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
|
374
|
-
options[:show_raw_data] = true
|
375
|
-
end
|
376
|
-
opts.on('--pretty-raw-data', '--raw-data', "Display Raw Data that is a bit more pretty") do |val|
|
377
|
-
options[:show_raw_data] = true
|
378
|
-
options[:pretty_json] = true
|
379
|
-
end
|
380
364
|
opts.on('--no-line-items', '--no-line-items', "Do not display line items.") do |val|
|
381
365
|
options[:hide_line_items] = true
|
382
366
|
end
|
@@ -401,9 +385,6 @@ EOT
|
|
401
385
|
|
402
386
|
def _get(id, options)
|
403
387
|
params = {}
|
404
|
-
if options[:show_raw_data]
|
405
|
-
params['rawData'] = true
|
406
|
-
end
|
407
388
|
begin
|
408
389
|
@invoices_interface.setopts(options)
|
409
390
|
if options[:dry_run]
|
@@ -412,6 +393,9 @@ EOT
|
|
412
393
|
end
|
413
394
|
json_response = @invoices_interface.get(id, params)
|
414
395
|
invoice = json_response['invoice']
|
396
|
+
if options[:hide_line_items]
|
397
|
+
json_response['invoice'].delete('lineItems') rescue nil
|
398
|
+
end
|
415
399
|
render_result = render_with_format(json_response, options, 'invoice')
|
416
400
|
return 0 if render_result
|
417
401
|
|
@@ -437,7 +421,7 @@ EOT
|
|
437
421
|
"End" => lambda {|it| format_date(it['endDate']) },
|
438
422
|
"Ref Start" => lambda {|it| format_dt(it['refStart']) },
|
439
423
|
"Ref End" => lambda {|it| format_dt(it['refEnd']) },
|
440
|
-
"Items" => lambda {|it| it['lineItems'].size rescue '' },
|
424
|
+
"Items" => lambda {|it| (it['lineItemCount'] ? it['lineItemCount'] : it['lineItems'].size) rescue '' },
|
441
425
|
"Tags" => lambda {|it| (it['metadata'] || it['tags']) ? (it['metadata'] || it['tags']).collect {|m| "#{m['name']}: #{m['value']}" }.join(', ') : '' },
|
442
426
|
"Project ID" => lambda {|it| it['project'] ? it['project']['id'] : '' },
|
443
427
|
"Project Name" => lambda {|it| it['project'] ? it['project']['name'] : '' },
|
@@ -523,9 +507,6 @@ EOT
|
|
523
507
|
{"CREATED" => lambda {|it| format_local_dt(it['dateCreated']) } },
|
524
508
|
{"UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } }
|
525
509
|
]
|
526
|
-
if options[:show_raw_data]
|
527
|
-
line_items_columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }]
|
528
|
-
end
|
529
510
|
print_h2 "Line Items"
|
530
511
|
#max_line_items = options[:max_line_items] ? options[:max_line_items].to_i : 5
|
531
512
|
paged_line_items = line_items #.first(max_line_items)
|
@@ -578,10 +559,7 @@ EOT
|
|
578
559
|
end
|
579
560
|
print as_pretty_table(cost_rows, cost_columns, options)
|
580
561
|
|
581
|
-
|
582
|
-
print_h2 "Raw Data"
|
583
|
-
puts as_json(invoice['rawData'], {pretty_json:false}.merge(options))
|
584
|
-
end
|
562
|
+
|
585
563
|
|
586
564
|
print reset,"\n"
|
587
565
|
return 0
|
@@ -658,37 +636,20 @@ Update an invoice.
|
|
658
636
|
params = {}
|
659
637
|
payload = {}
|
660
638
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
661
|
-
opts.banner = subcommand_usage("[
|
662
|
-
opts.on( '--
|
663
|
-
payload[:daily] = true
|
664
|
-
end
|
665
|
-
opts.on( '--costing', "Refresh Costing Data" ) do
|
666
|
-
payload[:costing] = true
|
667
|
-
end
|
668
|
-
opts.on( '--current', "Collect the most up to date costing data." ) do
|
669
|
-
payload[:current] = true
|
670
|
-
end
|
671
|
-
opts.on( '--date DATE', String, "Date to collect costing for. By default the cost data is collected for the end of the previous period." ) do |val|
|
672
|
-
payload[:date] = val.to_s
|
673
|
-
end
|
674
|
-
opts.on( '-c', '--cloud CLOUD', "Specify cloud(s) to refresh costing for." ) do |val|
|
639
|
+
opts.banner = subcommand_usage("[-c CLOUD]")
|
640
|
+
opts.on( '-c', '--clouds CLOUD', "Specify clouds to refresh costing for." ) do |val|
|
675
641
|
payload[:clouds] ||= []
|
676
642
|
payload[:clouds] << val
|
677
643
|
end
|
678
|
-
opts.on( '--all', "Refresh costing for all clouds." ) do
|
644
|
+
opts.on( '--all', "Refresh costing for all clouds. This can be used instead of --clouds" ) do
|
679
645
|
payload[:all] = true
|
680
646
|
end
|
681
|
-
|
682
|
-
|
683
|
-
|
647
|
+
opts.on( '--date DATE', String, "Date to collect costing for. By default the cost data is collected for the end of the previous job interval (hour or day)." ) do |val|
|
648
|
+
payload[:date] = val.to_s
|
649
|
+
end
|
684
650
|
build_standard_update_options(opts, options, [:query, :auto_confirm])
|
685
651
|
opts.footer = <<-EOT
|
686
|
-
Refresh
|
687
|
-
By default, nothing is changed.
|
688
|
-
Include --daily to regenerate invoice records.
|
689
|
-
Include --costing to refresh actual costing data.
|
690
|
-
Include --current to refresh costing data for the actual current time.
|
691
|
-
To get the latest invoice costing data, include --daily --costing --current --all
|
652
|
+
Refresh invoice costing data for the specified clouds.
|
692
653
|
EOT
|
693
654
|
end
|
694
655
|
optparse.parse!(args)
|
@@ -699,17 +660,11 @@ EOT
|
|
699
660
|
payload = options[:payload]
|
700
661
|
end
|
701
662
|
payload.deep_merge!(parse_passed_options(options))
|
702
|
-
# --clouds
|
663
|
+
# --clouds lookup ID for name
|
703
664
|
if payload[:clouds]
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
else
|
708
|
-
cloud = find_cloud_option(cloud_id)
|
709
|
-
return 1 if cloud.nil?
|
710
|
-
cloud['id']
|
711
|
-
end
|
712
|
-
}
|
665
|
+
cloud_ids = parse_cloud_id_list(payload[:clouds], {}, false, true)
|
666
|
+
return 1, "clouds not found for #{payload[:clouds]}" if cloud_ids.nil?
|
667
|
+
payload[:clouds] = cloud_ids
|
713
668
|
end
|
714
669
|
# are you sure?
|
715
670
|
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to refresh invoices?")
|
@@ -740,7 +695,6 @@ EOT
|
|
740
695
|
options[:show_actual_costs] = true
|
741
696
|
options[:show_costs] = true
|
742
697
|
options[:show_prices] = true
|
743
|
-
# options[:show_raw_data] = true
|
744
698
|
end
|
745
699
|
# opts.on('--actuals', '--actuals', "Display all actual costs: Compute, Storage, Network, Extra" ) do
|
746
700
|
# options[:show_actual_costs] = true
|
@@ -829,9 +783,6 @@ EOT
|
|
829
783
|
options[:tags][k] << (v || '')
|
830
784
|
end
|
831
785
|
end
|
832
|
-
opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
|
833
|
-
options[:show_raw_data] = true
|
834
|
-
end
|
835
786
|
opts.on('--totals', "View total costs and prices for all the invoices found.") do |val|
|
836
787
|
params['includeTotals'] = true
|
837
788
|
options[:show_invoice_totals] = true
|
@@ -857,36 +808,35 @@ EOT
|
|
857
808
|
# construct params
|
858
809
|
params.merge!(parse_list_options(options))
|
859
810
|
if options[:clouds]
|
860
|
-
cloud_ids = parse_cloud_id_list(options[:clouds])
|
811
|
+
cloud_ids = parse_cloud_id_list(options[:clouds], {}, false, true)
|
861
812
|
return 1, "clouds not found for #{options[:clouds]}" if cloud_ids.nil?
|
862
813
|
params['zoneId'] = cloud_ids
|
863
814
|
end
|
864
815
|
if options[:groups]
|
865
|
-
group_ids = parse_group_id_list(options[:groups])
|
816
|
+
group_ids = parse_group_id_list(options[:groups], {}, false, true)
|
866
817
|
return 1, "groups not found for #{options[:groups]}" if group_ids.nil?
|
867
818
|
params['siteId'] = group_ids
|
868
819
|
end
|
869
820
|
if options[:instances]
|
870
|
-
instance_ids = parse_instance_id_list(options[:instances])
|
821
|
+
instance_ids = parse_instance_id_list(options[:instances], {}, false, true)
|
871
822
|
return 1, "instances not found for #{options[:instances]}" if instance_ids.nil?
|
872
823
|
params['instanceId'] = instance_ids
|
873
824
|
end
|
874
825
|
if options[:servers]
|
875
|
-
server_ids = parse_server_id_list(options[:servers])
|
826
|
+
server_ids = parse_server_id_list(options[:servers], {}, false, true)
|
876
827
|
return 1, "servers not found for #{options[:servers]}" if server_ids.nil?
|
877
828
|
params['serverId'] = server_ids
|
878
829
|
end
|
879
830
|
if options[:users]
|
880
|
-
user_ids = parse_user_id_list(options[:users])
|
831
|
+
user_ids = parse_user_id_list(options[:users], {}, false, true)
|
881
832
|
return 1, "users not found for #{options[:users]}" if user_ids.nil?
|
882
833
|
params['userId'] = user_ids
|
883
834
|
end
|
884
835
|
if options[:projects]
|
885
|
-
project_ids = parse_project_id_list(options[:projects])
|
836
|
+
project_ids = parse_project_id_list(options[:projects], {}, false, true)
|
886
837
|
return 1, "projects not found for #{options[:projects]}" if project_ids.nil?
|
887
838
|
params['projectId'] = project_ids
|
888
839
|
end
|
889
|
-
params['rawData'] = true if options[:show_raw_data]
|
890
840
|
params['refId'] = ref_ids unless ref_ids.empty?
|
891
841
|
if options[:tags] && !options[:tags].empty?
|
892
842
|
options[:tags].each do |k,v|
|
@@ -944,9 +894,6 @@ EOT
|
|
944
894
|
"UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) }
|
945
895
|
]
|
946
896
|
|
947
|
-
if options[:show_raw_data]
|
948
|
-
columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }]
|
949
|
-
end
|
950
897
|
# if options[:show_invoice_totals]
|
951
898
|
# line_item_totals = json_response['lineItemTotals']
|
952
899
|
# if line_item_totals
|
@@ -995,13 +942,6 @@ EOT
|
|
995
942
|
options = {}
|
996
943
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
997
944
|
opts.banner = subcommand_usage("[id]")
|
998
|
-
opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
|
999
|
-
options[:show_raw_data] = true
|
1000
|
-
end
|
1001
|
-
opts.on('--pretty-raw-data', '--raw-data', "Display Raw Data that is a bit more pretty") do |val|
|
1002
|
-
options[:show_raw_data] = true
|
1003
|
-
options[:pretty_json] = true
|
1004
|
-
end
|
1005
945
|
opts.on('--sigdig DIGITS', "Significant digits when rounding cost values for display as currency. Default is 2. eg. $3.50") do |val|
|
1006
946
|
options[:sigdig] = val.to_i
|
1007
947
|
end
|
@@ -1023,9 +963,6 @@ EOT
|
|
1023
963
|
|
1024
964
|
def _get_line_item(id, options)
|
1025
965
|
params = {}
|
1026
|
-
if options[:show_raw_data]
|
1027
|
-
params['rawData'] = true
|
1028
|
-
end
|
1029
966
|
@invoice_line_items_interface.setopts(options)
|
1030
967
|
if options[:dry_run]
|
1031
968
|
print_dry_run @invoice_line_items_interface.dry.get(id, params)
|
@@ -1063,11 +1000,6 @@ EOT
|
|
1063
1000
|
}
|
1064
1001
|
print_description_list(description_cols, line_item, options)
|
1065
1002
|
|
1066
|
-
if options[:show_raw_data]
|
1067
|
-
print_h2 "Raw Data"
|
1068
|
-
puts as_json(line_item['rawData'], {pretty_json:false}.merge(options))
|
1069
|
-
end
|
1070
|
-
|
1071
1003
|
print reset,"\n"
|
1072
1004
|
end
|
1073
1005
|
return 0, nil
|