morpheus-cli 4.2.3 → 4.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/lib/morpheus/cli/invoices_command.rb +151 -51
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/formatters.rb +3 -0
- 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: 9cb4101fbb710060028dcbfcda3ad4caeb117950e68506f804a6d0fa604c8c08
|
4
|
+
data.tar.gz: 5d12f8d57d4d4ad8b83a8f9fc731e893b6f29ae6a8b36faa0bb5cb4b904d4eb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1673ab1af718c3570d502ba4323102e58999b2c2a8c883df79c6043a84ba92c9a49fe831160cd273f5912d1624965be0dbc854a78b23105d8e2a6768cd5ec17
|
7
|
+
data.tar.gz: 644dc0ded92efb77ca3c3007c7dc0d84c3e147c6f42acb49b5635024a4ea268ba9a5887af4733589a8b6794e0f6a67432252fe9f66ff50d88e9a5b05981d96b5
|
data/Dockerfile
CHANGED
@@ -23,7 +23,18 @@ class Morpheus::Cli::InvoicesCommand
|
|
23
23
|
ref_ids = []
|
24
24
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
25
25
|
opts.banner = subcommand_usage()
|
26
|
-
opts.on('
|
26
|
+
opts.on('-a', '--all', "Display all costs, prices and raw data" ) do
|
27
|
+
options[:show_costs] = true
|
28
|
+
options[:show_prices] = true
|
29
|
+
options[:show_raw_data] = true
|
30
|
+
end
|
31
|
+
opts.on('--costs', '--costs', "Display all costs: Compute, Memory, Storage, etc." ) do
|
32
|
+
options[:show_costs] = true
|
33
|
+
end
|
34
|
+
opts.on('--prices', '--prices', "Display all costs: Compute, Memory, Storage, etc." ) do
|
35
|
+
options[:show_prices] = true
|
36
|
+
end
|
37
|
+
opts.on('--type TYPE', String, "Filter by Ref Type eg. ComputeSite (Group), ComputeZone (Cloud), ComputeServer (Host), Instance, Container, User") do |val|
|
27
38
|
if val.to_s.downcase == 'cloud' || val.to_s.downcase == 'zone'
|
28
39
|
params['refType'] = 'ComputeZone'
|
29
40
|
elsif val.to_s.downcase == 'instance'
|
@@ -40,43 +51,40 @@ class Morpheus::Cli::InvoicesCommand
|
|
40
51
|
params['refType'] = val
|
41
52
|
end
|
42
53
|
end
|
43
|
-
opts.on('--
|
54
|
+
opts.on('--id ID', String, "Filter by Ref ID") do |val|
|
44
55
|
ref_ids << val
|
45
56
|
end
|
46
|
-
opts.on('--
|
47
|
-
# params['siteId'] = val
|
48
|
-
params['refType'] = 'ComputeSite'
|
57
|
+
opts.on('--ref-id ID', String, "Filter by Ref ID") do |val|
|
49
58
|
ref_ids << val
|
50
59
|
end
|
51
|
-
opts.
|
52
|
-
|
53
|
-
params['
|
54
|
-
|
60
|
+
opts.add_hidden_option('--ref-id')
|
61
|
+
opts.on('--group ID', String, "Filter by Group") do |val|
|
62
|
+
params['siteId'] ||= []
|
63
|
+
params['siteId'] << val
|
55
64
|
end
|
56
|
-
opts.on('--
|
57
|
-
|
58
|
-
params['
|
59
|
-
ref_ids << val
|
65
|
+
opts.on('--cloud ID', String, "Filter by Cloud") do |val|
|
66
|
+
params['zoneId'] ||= []
|
67
|
+
params['zoneId'] << val
|
60
68
|
end
|
61
|
-
opts.on('--
|
62
|
-
|
63
|
-
params['
|
64
|
-
ref_ids << val
|
69
|
+
opts.on('--instance ID', String, "Filter by Instance") do |val|
|
70
|
+
params['instanceId'] ||= []
|
71
|
+
params['instanceId'] << val
|
65
72
|
end
|
66
|
-
opts.on('--
|
67
|
-
|
68
|
-
params['
|
69
|
-
ref_ids << val
|
73
|
+
opts.on('--container ID', String, "Filter by Container") do |val|
|
74
|
+
params['containerId'] ||= []
|
75
|
+
params['containerId'] << val
|
70
76
|
end
|
71
|
-
opts.on('--
|
72
|
-
|
73
|
-
params['
|
74
|
-
|
77
|
+
opts.on('--server ID', String, "Filter by Server (Host)") do |val|
|
78
|
+
params['serverId'] ||= []
|
79
|
+
params['serverId'] << val
|
80
|
+
end
|
81
|
+
opts.on('--user ID', String, "Filter by User") do |val|
|
82
|
+
params['userId'] ||= []
|
83
|
+
params['userId'] << val
|
75
84
|
end
|
76
85
|
# opts.on('--cluster ID', String, "Filter by Cluster") do |val|
|
77
|
-
#
|
78
|
-
# params['
|
79
|
-
# params['refId'] = val.to_i
|
86
|
+
# params['clusterId'] ||= []
|
87
|
+
# params['clusterId'] << val
|
80
88
|
# end
|
81
89
|
opts.on('--start DATE', String, "Start date in the format YYYY-MM-DD.") do |val|
|
82
90
|
params['startDate'] = val #parse_time(val).utc.iso8601
|
@@ -90,12 +98,14 @@ class Morpheus::Cli::InvoicesCommand
|
|
90
98
|
opts.on('--active [true|false]',String, "Filter by active.") do |val|
|
91
99
|
params['active'] = (val.to_s != 'false' && val.to_s != 'off')
|
92
100
|
end
|
101
|
+
opts.on('--estimate [true|false]',String, "Filter by estimate.") do |val|
|
102
|
+
params['estimate'] = (val.to_s != 'false' && val.to_s != 'off')
|
103
|
+
end
|
93
104
|
opts.on('--tenant ID', String, "View invoices for a tenant. Default is your own account.") do |val|
|
94
105
|
params['accountId'] = val
|
95
106
|
end
|
96
107
|
opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val|
|
97
108
|
options[:show_raw_data] = true
|
98
|
-
params['rawData'] = true
|
99
109
|
end
|
100
110
|
build_standard_list_options(opts, options)
|
101
111
|
opts.footer = "List invoices."
|
@@ -108,6 +118,7 @@ class Morpheus::Cli::InvoicesCommand
|
|
108
118
|
return 1
|
109
119
|
end
|
110
120
|
begin
|
121
|
+
params['rawData'] = true if options[:show_raw_data]
|
111
122
|
params['refId'] = ref_ids unless ref_ids.empty?
|
112
123
|
params.merge!(parse_list_options(options))
|
113
124
|
@invoices_interface.setopts(options)
|
@@ -116,7 +127,7 @@ class Morpheus::Cli::InvoicesCommand
|
|
116
127
|
return
|
117
128
|
end
|
118
129
|
json_response = @invoices_interface.list(params)
|
119
|
-
render_result = render_with_format(json_response, options, '
|
130
|
+
render_result = render_with_format(json_response, options, 'invoices')
|
120
131
|
return 0 if render_result
|
121
132
|
invoices = json_response['invoices']
|
122
133
|
title = "Morpheus Invoices"
|
@@ -138,22 +149,62 @@ class Morpheus::Cli::InvoicesCommand
|
|
138
149
|
if invoices.empty?
|
139
150
|
print cyan,"No invoices found.",reset,"\n"
|
140
151
|
else
|
152
|
+
current_date = Time.now
|
153
|
+
current_period = "#{current_date.year}#{current_date.month.to_s.rjust(2, '0')}"
|
141
154
|
columns = [
|
142
155
|
{"INVOICE ID" => lambda {|it| it['id'] } },
|
143
156
|
{"TYPE" => lambda {|it| format_invoice_ref_type(it) } },
|
144
157
|
{"REF ID" => lambda {|it| it['refId'] } },
|
145
158
|
{"REF NAME" => lambda {|it| it['refName'] } },
|
146
159
|
#{"INTERVAL" => lambda {|it| it['interval'] } },
|
160
|
+
{"CLOUD" => lambda {|it| it['cloud'] ? it['cloud']['name'] : '' } },
|
147
161
|
{"ACCOUNT" => lambda {|it| it['account'] ? it['account']['name'] : '' } },
|
148
162
|
{"ACTIVE" => lambda {|it| format_boolean(it['active']) } },
|
163
|
+
#{"ESTIMATE" => lambda {|it| format_boolean(it['estimate']) } },
|
149
164
|
{"PERIOD" => lambda {|it| format_invoice_period(it) } },
|
150
165
|
{"START" => lambda {|it| format_date(it['startDate']) } },
|
151
166
|
{"END" => lambda {|it| it['endDate'] ? format_date(it['endDate']) : '' } },
|
152
|
-
|
153
|
-
{"COST" => lambda {|it| format_money(it['totalCost']) } },
|
167
|
+
|
154
168
|
]
|
169
|
+
if options[:show_costs]
|
170
|
+
columns += [
|
171
|
+
{"COMPUTE" => lambda {|it| format_money(it['computeCost']) } },
|
172
|
+
# {"MEMORY" => lambda {|it| format_money(it['memoryCost']) } },
|
173
|
+
{"STORAGE" => lambda {|it| format_money(it['storageCost']) } },
|
174
|
+
{"NETWORK" => lambda {|it| format_money(it['networkCost']) } },
|
175
|
+
{"OTHER" => lambda {|it| format_money(it['extraCost']) } },
|
176
|
+
]
|
177
|
+
end
|
178
|
+
columns += [
|
179
|
+
{"MTD" => lambda {|it| format_money(it['runningCost']) } },
|
180
|
+
{"TOTAL" => lambda {|it|
|
181
|
+
if it['period'] == current_period && it['totalCost'].to_f > 0
|
182
|
+
format_money(it['totalCost']) + " (Projected)"
|
183
|
+
else
|
184
|
+
format_money(it['totalCost'])
|
185
|
+
end
|
186
|
+
} }
|
187
|
+
]
|
188
|
+
if options[:show_prices]
|
189
|
+
columns += [
|
190
|
+
{"COMPUTE PRICE" => lambda {|it| format_money(it['computePrice']) } },
|
191
|
+
# {"MEMORY PRICE" => lambda {|it| format_money(it['memoryPrice']) } },
|
192
|
+
{"STORAGE PRICE" => lambda {|it| format_money(it['storagePrice']) } },
|
193
|
+
{"NETWORK PRICE" => lambda {|it| format_money(it['networkPrice']) } },
|
194
|
+
{"OTHER PRICE" => lambda {|it| format_money(it['extraPrice']) } },
|
195
|
+
{"MTD PRICE" => lambda {|it| format_money(it['runningPrice']) } },
|
196
|
+
{"TOTAL PRICE" => lambda {|it|
|
197
|
+
if it['period'] == current_period && it['totalPrice'].to_f > 0
|
198
|
+
format_money(it['totalPrice']) + " (Projected)"
|
199
|
+
else
|
200
|
+
format_money(it['totalPrice'])
|
201
|
+
end
|
202
|
+
} }
|
203
|
+
]
|
204
|
+
end
|
205
|
+
|
155
206
|
if options[:show_raw_data]
|
156
|
-
columns
|
207
|
+
columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }]
|
157
208
|
end
|
158
209
|
print as_pretty_table(invoices, columns, options)
|
159
210
|
print_results_pagination(json_response, {:label => "invoice", :n_label => "invoices"})
|
@@ -220,26 +271,75 @@ class Morpheus::Cli::InvoicesCommand
|
|
220
271
|
"Start" => lambda {|it| format_date(it['startDate']) },
|
221
272
|
"End" => lambda {|it| it['endDate'] ? format_date(it['endDate']) : '' },
|
222
273
|
"Estimate" => lambda {|it| format_boolean(it['estimate']) },
|
223
|
-
"
|
224
|
-
"
|
225
|
-
"Memory Price" => lambda {|it| format_money(it['memoryPrice']) },
|
226
|
-
"Memory Cost" => lambda {|it| format_money(it['memoryCost']) },
|
227
|
-
"Storage Price" => lambda {|it| format_money(it['storagePrice']) },
|
228
|
-
"Storage Cost" => lambda {|it| format_money(it['storageCost']) },
|
229
|
-
"Network Price" => lambda {|it| format_money(it['networkPrice']) },
|
230
|
-
"Network Cost" => lambda {|it| format_money(it['networkCost']) },
|
231
|
-
"License Price" => lambda {|it| format_money(it['licensePrice']) },
|
232
|
-
"License Cost" => lambda {|it| format_money(it['licenseCost']) },
|
233
|
-
"Extra Price" => lambda {|it| format_money(it['extraPrice']) },
|
234
|
-
"Extra Cost" => lambda {|it| format_money(it['extraCost']) },
|
235
|
-
"Running Price" => lambda {|it| format_money(it['runningPrice']) },
|
236
|
-
"Running Cost" => lambda {|it| format_money(it['runningCost']) },
|
237
|
-
"Total Price" => lambda {|it| format_money(it['totalPrice']) },
|
238
|
-
"Total Cost" => lambda {|it| format_money(it['totalCost']) },
|
239
|
-
# "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
240
|
-
# "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
|
274
|
+
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
275
|
+
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
|
241
276
|
}
|
242
277
|
print_description_list(description_cols, invoice)
|
278
|
+
=begin
|
279
|
+
print_h2 "Costs"
|
280
|
+
cost_columns = {
|
281
|
+
"Compute" => lambda {|it| format_money(it['computeCost']) },
|
282
|
+
"Memory" => lambda {|it| format_money(it['memoryCost']) },
|
283
|
+
"Storage" => lambda {|it| format_money(it['storageCost']) },
|
284
|
+
"Network" => lambda {|it| format_money(it['networkCost']) },
|
285
|
+
"License" => lambda {|it| format_money(it['licenseCost']) },
|
286
|
+
"Other" => lambda {|it| format_money(it['extraCost']) },
|
287
|
+
"Running" => lambda {|it| format_money(it['runningCost']) },
|
288
|
+
"Total Cost" => lambda {|it| format_money(it['totalCost']) },
|
289
|
+
}
|
290
|
+
print as_pretty_table([invoice], cost_columns, options)
|
291
|
+
|
292
|
+
print_h2 "Prices"
|
293
|
+
price_columns = {
|
294
|
+
"Compute" => lambda {|it| format_money(it['computePrice']) },
|
295
|
+
"Memory" => lambda {|it| format_money(it['memoryPrice']) },
|
296
|
+
"Storage" => lambda {|it| format_money(it['storagePrice']) },
|
297
|
+
"Network" => lambda {|it| format_money(it['networkPrice']) },
|
298
|
+
"License" => lambda {|it| format_money(it['licensePrice']) },
|
299
|
+
"Other" => lambda {|it| format_money(it['extraPrice']) },
|
300
|
+
"Running" => lambda {|it| format_money(it['runningPrice']) },
|
301
|
+
"Total Price" => lambda {|it| format_money(it['totalPrice']) },
|
302
|
+
}
|
303
|
+
print as_pretty_table([invoice], price_columns, options)
|
304
|
+
=end
|
305
|
+
|
306
|
+
current_date = Time.now
|
307
|
+
current_period = "#{current_date.year}#{current_date.month.to_s.rjust(2, '0')}"
|
308
|
+
|
309
|
+
print "\n"
|
310
|
+
# print_h2 "Costs"
|
311
|
+
cost_rows = [
|
312
|
+
{label: 'Cost'.upcase, compute: invoice['computeCost'], memory: invoice['memoryCost'], storage: invoice['storageCost'], network: invoice['networkCost'], license: invoice['licenseCost'], extra: invoice['extraCost'], running: invoice['runningCost'], total: invoice['totalCost']},
|
313
|
+
{label: 'Price'.upcase, compute: invoice['computePrice'], memory: invoice['memoryPrice'], storage: invoice['storagePrice'], network: invoice['networkPrice'], license: invoice['licensePrice'], extra: invoice['extraPrice'], running: invoice['runningPrice'], total: invoice['totalPrice']},
|
314
|
+
]
|
315
|
+
cost_columns = {
|
316
|
+
"" => lambda {|it| it[:label] },
|
317
|
+
"Compute".upcase => lambda {|it| format_money(it[:compute]) },
|
318
|
+
"Memory".upcase => lambda {|it| format_money(it[:memory]) },
|
319
|
+
"Storage".upcase => lambda {|it| format_money(it[:storage]) },
|
320
|
+
"Network".upcase => lambda {|it| format_money(it[:network]) },
|
321
|
+
"License".upcase => lambda {|it| format_money(it[:license]) },
|
322
|
+
"Other".upcase => lambda {|it| format_money(it[:extra]) },
|
323
|
+
"MTD" => lambda {|it| format_money(it[:running]) },
|
324
|
+
"Total".upcase => lambda {|it|
|
325
|
+
if invoice['period'] == current_period && it[:total].to_f > 0
|
326
|
+
format_money(it[:total]) + " (Projected)"
|
327
|
+
else
|
328
|
+
format_money(it[:total])
|
329
|
+
end
|
330
|
+
},
|
331
|
+
}
|
332
|
+
# remove columns that rarely have data...
|
333
|
+
if cost_rows.sum { |it| it[:memory].to_f } == 0
|
334
|
+
cost_columns.delete("Memory".upcase)
|
335
|
+
end
|
336
|
+
if cost_rows.sum { |it| it[:license].to_f } == 0
|
337
|
+
cost_columns.delete("License".upcase)
|
338
|
+
end
|
339
|
+
if cost_rows.sum { |it| it[:extra].to_f } == 0
|
340
|
+
cost_columns.delete("Other".upcase)
|
341
|
+
end
|
342
|
+
print as_pretty_table(cost_rows, cost_columns, options)
|
243
343
|
|
244
344
|
if options[:show_raw_data]
|
245
345
|
print_h2 "Raw Data"
|
data/lib/morpheus/cli/version.rb
CHANGED
data/lib/morpheus/formatters.rb
CHANGED
@@ -346,6 +346,9 @@ end
|
|
346
346
|
def format_money(amount, currency='usd')
|
347
347
|
if amount.to_f == 0
|
348
348
|
return currency_sym(currency).to_s + "0"
|
349
|
+
# elsif amount.to_f < 0.01
|
350
|
+
# # return exponent notation like 3.4e-09
|
351
|
+
# return currency_sym(currency).to_s + "#{amount}"
|
349
352
|
else
|
350
353
|
rtn = amount.to_f.round(2).to_s
|
351
354
|
if rtn.index('.').nil?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpheus-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Estes
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-03-
|
14
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|