morpheus-cli 5.3.2 → 5.3.3
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/api/accounts_interface.rb +4 -30
- data/lib/morpheus/api/api_client.rb +12 -0
- data/lib/morpheus/api/instances_interface.rb +18 -5
- data/lib/morpheus/api/load_balancer_pools_interface.rb +9 -0
- data/lib/morpheus/api/load_balancer_types_interface.rb +9 -0
- data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +9 -0
- data/lib/morpheus/api/load_balancers_interface.rb +4 -53
- data/lib/morpheus/api/network_routers_interface.rb +56 -0
- data/lib/morpheus/api/secondary_read_interface.rb +25 -0
- data/lib/morpheus/api/secondary_rest_interface.rb +42 -0
- data/lib/morpheus/api/virtual_images_interface.rb +23 -2
- data/lib/morpheus/cli/apps.rb +3 -2
- data/lib/morpheus/cli/cli_command.rb +21 -14
- data/lib/morpheus/cli/cli_registry.rb +55 -2
- data/lib/morpheus/cli/cloud_resource_pools_command.rb +169 -133
- data/lib/morpheus/cli/clusters.rb +51 -33
- data/lib/morpheus/cli/instances.rb +292 -174
- data/lib/morpheus/cli/invoices_command.rb +79 -99
- data/lib/morpheus/cli/library_cluster_layouts_command.rb +20 -0
- data/lib/morpheus/cli/load_balancer_types.rb +37 -0
- data/lib/morpheus/cli/load_balancers.rb +149 -314
- data/lib/morpheus/cli/log_settings_command.rb +7 -3
- data/lib/morpheus/cli/mixins/load_balancers_helper.rb +156 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +11 -0
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +123 -101
- data/lib/morpheus/cli/mixins/rest_command.rb +657 -0
- data/lib/morpheus/cli/monitoring_checks_command.rb +2 -0
- data/lib/morpheus/cli/network_routers_command.rb +1183 -185
- data/lib/morpheus/cli/networks_command.rb +194 -101
- data/lib/morpheus/cli/option_parser.rb +25 -17
- data/lib/morpheus/cli/option_types.rb +42 -45
- data/lib/morpheus/cli/tenants_command.rb +18 -20
- data/lib/morpheus/cli/vdi_pools_command.rb +4 -1
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +249 -29
- data/lib/morpheus/cli.rb +1 -0
- data/lib/morpheus/ext/string.rb +41 -0
- data/lib/morpheus/formatters.rb +4 -0
- data/morpheus-cli.gemspec +1 -1
- metadata +13 -4
@@ -222,52 +222,52 @@ class Morpheus::Cli::InvoicesCommand
|
|
222
222
|
# {"LAST COST DATE" => lambda {|it| format_local_dt(it['lastCostDate']) } },
|
223
223
|
# {"LAST ACTUAL DATE" => lambda {|it| format_local_dt(it['lastActualDate']) } },
|
224
224
|
] : []) + [
|
225
|
-
{"COMPUTE PRICE" => lambda {|it| format_money(it['computePrice'], '
|
226
|
-
{"MEMORY PRICE" => lambda {|it| format_money(it['memoryPrice'], '
|
227
|
-
{"STORAGE PRICE" => lambda {|it| format_money(it['storagePrice'], '
|
228
|
-
{"NETWORK PRICE" => lambda {|it| format_money(it['networkPrice'], '
|
229
|
-
{"EXTRA PRICE" => lambda {|it| format_money(it['extraPrice'], '
|
230
|
-
{"MTD PRICE" => lambda {|it| format_money(it['runningPrice'], '
|
225
|
+
{"COMPUTE PRICE" => lambda {|it| format_money(it['computePrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
226
|
+
{"MEMORY PRICE" => lambda {|it| format_money(it['memoryPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
227
|
+
{"STORAGE PRICE" => lambda {|it| format_money(it['storagePrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
228
|
+
{"NETWORK PRICE" => lambda {|it| format_money(it['networkPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
229
|
+
{"EXTRA PRICE" => lambda {|it| format_money(it['extraPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
230
|
+
{"MTD PRICE" => lambda {|it| format_money(it['runningPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
231
231
|
{"TOTAL PRICE" => lambda {|it|
|
232
|
-
format_money(it['totalPrice'], '
|
232
|
+
format_money(it['totalPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) + ((it['totalCost'].to_f > 0 && it['totalCost'] != it['runningCost']) ? " (Projected)" : "")
|
233
233
|
} }
|
234
234
|
]
|
235
235
|
|
236
236
|
if options[:show_costs] && json_response['masterAccount'] != false
|
237
237
|
columns += [
|
238
|
-
{"COMPUTE COST" => lambda {|it| format_money(it['computeCost'], '
|
238
|
+
{"COMPUTE COST" => lambda {|it| format_money(it['computeCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
239
239
|
{"MEMORY COST" => lambda {|it| format_money(it['memoryCost']) } },
|
240
|
-
{"STORAGE COST" => lambda {|it| format_money(it['storageCost'], '
|
241
|
-
{"NETWORK COST" => lambda {|it| format_money(it['networkCost'], '
|
242
|
-
{"EXTRA COST" => lambda {|it| format_money(it['extraCost'], '
|
243
|
-
{"MTD COST" => lambda {|it| format_money(it['runningCost'], '
|
240
|
+
{"STORAGE COST" => lambda {|it| format_money(it['storageCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
241
|
+
{"NETWORK COST" => lambda {|it| format_money(it['networkCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
242
|
+
{"EXTRA COST" => lambda {|it| format_money(it['extraCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
243
|
+
{"MTD COST" => lambda {|it| format_money(it['runningCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
244
244
|
{"TOTAL COST" => lambda {|it|
|
245
|
-
format_money(it['totalCost'], '
|
245
|
+
format_money(it['totalCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) + ((it['totalCost'].to_f > 0 && it['totalCost'] != it['runningCost']) ? " (Projected)" : "")
|
246
246
|
} }
|
247
247
|
]
|
248
248
|
end
|
249
249
|
if options[:show_estimates]
|
250
250
|
columns += [
|
251
|
-
{"METERED COMPUTE PRICE" => lambda {|it| format_money(it['estimatedComputePrice'], '
|
252
|
-
{"METERED MEMORY PRICE" => lambda {|it| format_money(it['estimatedMemoryPrice'], '
|
253
|
-
{"METERED STORAGE PRICE" => lambda {|it| format_money(it['estimatedStoragePrice'], '
|
254
|
-
{"METERED NETWORK PRICE" => lambda {|it| format_money(it['estimatedNetworkPrice'], '
|
255
|
-
{"METERED EXTRA PRICE" => lambda {|it| format_money(it['estimatedExtraPrice'], '
|
256
|
-
{"METERED MTD PRICE" => lambda {|it| format_money(it['estimatedRunningPrice'], '
|
251
|
+
{"METERED COMPUTE PRICE" => lambda {|it| format_money(it['estimatedComputePrice'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
252
|
+
{"METERED MEMORY PRICE" => lambda {|it| format_money(it['estimatedMemoryPrice'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
253
|
+
{"METERED STORAGE PRICE" => lambda {|it| format_money(it['estimatedStoragePrice'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
254
|
+
{"METERED NETWORK PRICE" => lambda {|it| format_money(it['estimatedNetworkPrice'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
255
|
+
{"METERED EXTRA PRICE" => lambda {|it| format_money(it['estimatedExtraPrice'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
256
|
+
{"METERED MTD PRICE" => lambda {|it| format_money(it['estimatedRunningPrice'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
257
257
|
{"METERED TOTAL PRICE" => lambda {|it|
|
258
|
-
format_money(it['estimatedTotalPrice'], '
|
258
|
+
format_money(it['estimatedTotalPrice'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) + ((it['estimatedTotalPrice'].to_f > 0 && it['estimatedTotalPrice'] != it['estimatedRunningPrice']) ? " (Projected)" : "")
|
259
259
|
} },
|
260
260
|
]
|
261
261
|
if options[:show_costs] && json_response['masterAccount'] != false
|
262
262
|
columns += [
|
263
|
-
{"METERED COMPUTE COST" => lambda {|it| format_money(it['estimatedComputeCost'], '
|
264
|
-
{"METERED MEMORY COST" => lambda {|it| format_money(it['estimatedMemoryCost'], '
|
265
|
-
{"METERED STORAGE COST" => lambda {|it| format_money(it['estimatedStorageCost'], '
|
266
|
-
{"METERED NETWORK COST" => lambda {|it| format_money(it['estimatedNetworkCost'], '
|
267
|
-
{"METERED EXTRA COST" => lambda {|it| format_money(it['estimatedExtraCost'], '
|
268
|
-
{"METERED MTD COST" => lambda {|it| format_money(it['estimatedRunningCost'], '
|
263
|
+
{"METERED COMPUTE COST" => lambda {|it| format_money(it['estimatedComputeCost'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
264
|
+
{"METERED MEMORY COST" => lambda {|it| format_money(it['estimatedMemoryCost'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
265
|
+
{"METERED STORAGE COST" => lambda {|it| format_money(it['estimatedStorageCost'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
266
|
+
{"METERED NETWORK COST" => lambda {|it| format_money(it['estimatedNetworkCost'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
267
|
+
{"METERED EXTRA COST" => lambda {|it| format_money(it['estimatedExtraCost'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
268
|
+
{"METERED MTD COST" => lambda {|it| format_money(it['estimatedRunningCost'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
269
269
|
{"METERED TOTAL COST" => lambda {|it|
|
270
|
-
format_money(it['estimatedTotalCost'], '
|
270
|
+
format_money(it['estimatedTotalCost'], it['estimatedCurrency'] || 'USD', {sigdig:options[:sigdig]}) + ((it['estimatedTotalCost'].to_f > 0 && it['estimatedTotalCost'] != it['estimatedRunningCost']) ? " (Projected)" : "")
|
271
271
|
} },
|
272
272
|
]
|
273
273
|
end
|
@@ -306,36 +306,37 @@ class Morpheus::Cli::InvoicesCommand
|
|
306
306
|
|
307
307
|
if invoice_totals
|
308
308
|
cost_rows = [
|
309
|
-
{label: 'Price'.upcase, compute: invoice_totals['actualComputePrice'], memory: invoice_totals['actualMemoryPrice'], storage: invoice_totals['actualStoragePrice'], network: invoice_totals['actualNetworkPrice'], license: invoice_totals['actualLicensePrice'], extra: invoice_totals['actualExtraPrice'], running: invoice_totals['actualRunningPrice'], total: invoice_totals['actualTotalPrice']},
|
309
|
+
{label: 'Price'.upcase, compute: invoice_totals['actualComputePrice'], memory: invoice_totals['actualMemoryPrice'], storage: invoice_totals['actualStoragePrice'], network: invoice_totals['actualNetworkPrice'], license: invoice_totals['actualLicensePrice'], extra: invoice_totals['actualExtraPrice'], running: invoice_totals['actualRunningPrice'], total: invoice_totals['actualTotalPrice'], currency: invoice['currency']},
|
310
310
|
]
|
311
311
|
if options[:show_costs]
|
312
312
|
cost_rows += [
|
313
|
-
{label: 'Cost'.upcase, compute: invoice_totals['actualComputeCost'], memory: invoice_totals['actualMemoryCost'], storage: invoice_totals['actualStorageCost'], network: invoice_totals['actualNetworkCost'], license: invoice_totals['actualLicenseCost'], extra: invoice_totals['actualExtraCost'], running: invoice_totals['actualRunningCost'], total: invoice_totals['actualTotalCost']}
|
313
|
+
{label: 'Cost'.upcase, compute: invoice_totals['actualComputeCost'], memory: invoice_totals['actualMemoryCost'], storage: invoice_totals['actualStorageCost'], network: invoice_totals['actualNetworkCost'], license: invoice_totals['actualLicenseCost'], extra: invoice_totals['actualExtraCost'], running: invoice_totals['actualRunningCost'], total: invoice_totals['actualTotalCost'], currency: invoice['currency']}
|
314
314
|
]
|
315
315
|
end
|
316
316
|
if options[:show_estimates]
|
317
317
|
cost_rows += [
|
318
|
-
{label: 'Metered Price'.upcase, compute: invoice_totals['estimatedComputePrice'], memory: invoice_totals['estimatedMemoryPrice'], storage: invoice_totals['estimatedStoragePrice'], network: invoice_totals['estimatedNetworkPrice'], license: invoice_totals['estimatedLicensePrice'], extra: invoice_totals['estimatedExtraPrice'], running: invoice_totals['estimatedRunningPrice'], total: invoice_totals['estimatedTotalPrice']}
|
318
|
+
{label: 'Metered Price'.upcase, compute: invoice_totals['estimatedComputePrice'], memory: invoice_totals['estimatedMemoryPrice'], storage: invoice_totals['estimatedStoragePrice'], network: invoice_totals['estimatedNetworkPrice'], license: invoice_totals['estimatedLicensePrice'], extra: invoice_totals['estimatedExtraPrice'], running: invoice_totals['estimatedRunningPrice'], total: invoice_totals['estimatedTotalPrice'], currency: invoice['estimatedCurrency']}
|
319
319
|
]
|
320
320
|
if options[:show_costs]
|
321
321
|
cost_rows += [
|
322
|
-
{label: 'Metered Cost'.upcase, compute: invoice_totals['estimatedComputeCost'], memory: invoice_totals['estimatedMemoryCost'], storage: invoice_totals['estimatedStorageCost'], network: invoice_totals['estimatedNetworkCost'], license: invoice_totals['estimatedLicenseCost'], extra: invoice_totals['estimatedExtraCost'], running: invoice_totals['estimatedRunningCost'], total: invoice_totals['estimatedTotalCost']}
|
322
|
+
{label: 'Metered Cost'.upcase, compute: invoice_totals['estimatedComputeCost'], memory: invoice_totals['estimatedMemoryCost'], storage: invoice_totals['estimatedStorageCost'], network: invoice_totals['estimatedNetworkCost'], license: invoice_totals['estimatedLicenseCost'], extra: invoice_totals['estimatedExtraCost'], running: invoice_totals['estimatedRunningCost'], total: invoice_totals['estimatedTotalCost'], currency: invoice['estimatedCurrency']}
|
323
323
|
]
|
324
324
|
end
|
325
325
|
end
|
326
326
|
cost_columns = {
|
327
327
|
"" => lambda {|it| it[:label] },
|
328
|
-
"Compute"
|
329
|
-
"Memory"
|
330
|
-
"Storage"
|
331
|
-
"Network"
|
332
|
-
"License"
|
333
|
-
"Extra"
|
334
|
-
"MTD"
|
335
|
-
"Total"
|
336
|
-
format_money(it[:total], '
|
328
|
+
"Compute" => lambda {|it| format_money(it[:compute], it[:currency] || it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
329
|
+
"Memory" => lambda {|it| format_money(it[:memory], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
330
|
+
"Storage" => lambda {|it| format_money(it[:storage], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
331
|
+
"Network" => lambda {|it| format_money(it[:network], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
332
|
+
"License" => lambda {|it| format_money(it[:license], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
333
|
+
"Extra" => lambda {|it| format_money(it[:extra], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
334
|
+
"MTD" => lambda {|it| format_money(it[:running], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
335
|
+
"Total" => lambda {|it|
|
336
|
+
format_money(it[:total], it[:currency] || 'USD', {sigdig:options[:sigdig]}) + ((it[:total].to_f > 0 && it[:total] != it[:running]) ? " (Projected)" : "")
|
337
337
|
},
|
338
|
-
|
338
|
+
"Currency" => lambda {|it| it[:currency] },
|
339
|
+
}.upcase_keys!
|
339
340
|
# remove columns that rarely have data...
|
340
341
|
if cost_rows.sum { |it| it[:memory].to_f } == 0
|
341
342
|
cost_columns.delete("Memory".upcase)
|
@@ -433,6 +434,10 @@ EOT
|
|
433
434
|
"End" => lambda {|it| format_date(it['endDate']) },
|
434
435
|
"Ref Start" => lambda {|it| format_dt(it['refStart']) },
|
435
436
|
"Ref End" => lambda {|it| format_dt(it['refEnd']) },
|
437
|
+
"Currency" => lambda {|it| (it['estimate'] ? it['estimatedCurrency'] : it['currency']) || 'USD' },
|
438
|
+
"Conversion Rate" => lambda {|it| (it['estimate'] ? it['estimatedConversionRate'] : it['conversionRate']) },
|
439
|
+
# "Estimated Currency" => lambda {|it| it['estimatedCurrency'] },
|
440
|
+
# "Estimated Conversion Rate" => lambda {|it| it['estimatedConversionRate'] },
|
436
441
|
"Items" => lambda {|it| (it['lineItemCount'] ? it['lineItemCount'] : it['lineItems'].size) rescue '' },
|
437
442
|
"Tags" => lambda {|it| (it['metadata'] || it['tags']) ? (it['metadata'] || it['tags']).collect {|m| "#{m['name']}: #{m['value']}" }.join(', ') : '' },
|
438
443
|
"Project ID" => lambda {|it| it['project'] ? it['project']['id'] : '' },
|
@@ -457,39 +462,13 @@ EOT
|
|
457
462
|
if !['ComputeServer','Instance','Container'].include?(invoice['refType'])
|
458
463
|
description_cols.delete("Power State")
|
459
464
|
end
|
465
|
+
# if invoice['currency'].nil? || invoice['currency'] == 'USD'
|
466
|
+
# description_cols.delete("Currency")
|
467
|
+
# end
|
468
|
+
# if invoice['actualConversionRate'].nil? || invoice['actualConversionRate'] == 1
|
469
|
+
# description_cols.delete("Conversion Rate")
|
470
|
+
# end
|
460
471
|
print_description_list(description_cols, invoice)
|
461
|
-
=begin
|
462
|
-
print_h2 "Costs"
|
463
|
-
cost_columns = {
|
464
|
-
"Compute" => lambda {|it| format_money(it['computeCost'], 'usd', {sigdig:options[:sigdig]}) },
|
465
|
-
"Memory" => lambda {|it| format_money(it['memoryCost'], 'usd', {sigdig:options[:sigdig]}) },
|
466
|
-
"Storage" => lambda {|it| format_money(it['storageCost'], 'usd', {sigdig:options[:sigdig]}) },
|
467
|
-
"Network" => lambda {|it| format_money(it['networkCost'], 'usd', {sigdig:options[:sigdig]}) },
|
468
|
-
"License" => lambda {|it| format_money(it['licenseCost'], 'usd', {sigdig:options[:sigdig]}) },
|
469
|
-
"Extra" => lambda {|it| format_money(it['extraCost'], 'usd', {sigdig:options[:sigdig]}) },
|
470
|
-
"Running" => lambda {|it| format_money(it['runningCost'], 'usd', {sigdig:options[:sigdig]}) },
|
471
|
-
"Total Cost" => lambda {|it| format_money(it['totalCost'], 'usd', {sigdig:options[:sigdig]}) },
|
472
|
-
}
|
473
|
-
print as_pretty_table([invoice], cost_columns, options)
|
474
|
-
|
475
|
-
print_h2 "Prices"
|
476
|
-
price_columns = {
|
477
|
-
"Compute" => lambda {|it| format_money(it['computePrice'], 'usd', {sigdig:options[:sigdig]}) },
|
478
|
-
"Memory" => lambda {|it| format_money(it['memoryPrice'], 'usd', {sigdig:options[:sigdig]}) },
|
479
|
-
"Storage" => lambda {|it| format_money(it['storagePrice'], 'usd', {sigdig:options[:sigdig]}) },
|
480
|
-
"Network" => lambda {|it| format_money(it['networkPrice'], 'usd', {sigdig:options[:sigdig]}) },
|
481
|
-
"License" => lambda {|it| format_money(it['licensePrice'], 'usd', {sigdig:options[:sigdig]}) },
|
482
|
-
"Extra" => lambda {|it| format_money(it['extraPrice'], 'usd', {sigdig:options[:sigdig]}) },
|
483
|
-
"Running" => lambda {|it| format_money(it['runningPrice'], 'usd', {sigdig:options[:sigdig]}) },
|
484
|
-
"Total Price" => lambda {|it| format_money(it['totalPrice'], 'usd', {sigdig:options[:sigdig]}) },
|
485
|
-
}
|
486
|
-
print as_pretty_table([invoice], price_columns, options)
|
487
|
-
=end
|
488
|
-
|
489
|
-
# current_date = Time.now
|
490
|
-
# current_period = "#{current_date.year}#{current_date.month.to_s.rjust(2, '0')}"
|
491
|
-
|
492
|
-
|
493
472
|
|
494
473
|
# Line Items
|
495
474
|
line_items = invoice['lineItems']
|
@@ -507,9 +486,9 @@ EOT
|
|
507
486
|
{"USAGE" => lambda {|it| it['itemUsage'] } },
|
508
487
|
{"RATE" => lambda {|it| it['itemRate'] } },
|
509
488
|
{"UNIT" => lambda {|it| it['rateUnit'] } },
|
510
|
-
{"COST" => lambda {|it| format_money(it['itemCost'], '
|
511
|
-
{"PRICE" => lambda {|it| format_money(it['itemPrice'], '
|
512
|
-
#{"TAX" => lambda {|it| format_money(it['itemTax'], '
|
489
|
+
{"COST" => lambda {|it| format_money(it['itemCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
490
|
+
{"PRICE" => lambda {|it| format_money(it['itemPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
491
|
+
#{"TAX" => lambda {|it| format_money(it['itemTax'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
513
492
|
# {"TERM" => lambda {|it| it['itemTerm'] } },
|
514
493
|
{"ITEM ID" => lambda {|it| truncate_string_right(it['itemId'], 65) } },
|
515
494
|
{"ITEM NAME" => lambda {|it| it['itemName'] } },
|
@@ -529,36 +508,37 @@ EOT
|
|
529
508
|
print_h2 "Invoice Totals"
|
530
509
|
|
531
510
|
cost_rows = [
|
532
|
-
{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']},
|
511
|
+
{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'], currency: invoice['currency']},
|
533
512
|
]
|
534
513
|
if options[:show_costs] # && json_response['masterAccount'] != false
|
535
514
|
cost_rows += [
|
536
|
-
{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']},
|
515
|
+
{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'], currency: invoice['currency']},
|
537
516
|
]
|
538
517
|
end
|
539
518
|
if options[:show_estimates]
|
540
519
|
cost_rows += [
|
541
|
-
{label: 'Metered Price'.upcase, compute: invoice['estimatedComputePrice'], memory: invoice['estimatedMemoryPrice'], storage: invoice['estimatedStoragePrice'], network: invoice['estimatedNetworkPrice'], license: invoice['estimatedLicensePrice'], extra: invoice['estimatedExtraPrice'], running: invoice['estimatedRunningPrice'], total: invoice['estimatedTotalPrice']}
|
520
|
+
{label: 'Metered Price'.upcase, compute: invoice['estimatedComputePrice'], memory: invoice['estimatedMemoryPrice'], storage: invoice['estimatedStoragePrice'], network: invoice['estimatedNetworkPrice'], license: invoice['estimatedLicensePrice'], extra: invoice['estimatedExtraPrice'], running: invoice['estimatedRunningPrice'], total: invoice['estimatedTotalPrice'], currency: invoice['estimatedCurrency']}
|
542
521
|
]
|
543
522
|
if options[:show_costs] # && json_response['masterAccount'] != false
|
544
523
|
cost_rows += [
|
545
|
-
{label: 'Metered Cost'.upcase, compute: invoice['estimatedComputeCost'], memory: invoice['estimatedMemoryCost'], storage: invoice['estimatedStorageCost'], network: invoice['estimatedNetworkCost'], license: invoice['estimatedLicenseCost'], extra: invoice['estimatedExtraCost'], running: invoice['estimatedRunningCost'], total: invoice['estimatedTotalCost']},
|
524
|
+
{label: 'Metered Cost'.upcase, compute: invoice['estimatedComputeCost'], memory: invoice['estimatedMemoryCost'], storage: invoice['estimatedStorageCost'], network: invoice['estimatedNetworkCost'], license: invoice['estimatedLicenseCost'], extra: invoice['estimatedExtraCost'], running: invoice['estimatedRunningCost'], total: invoice['estimatedTotalCost'], currency: invoice['estimatedCurrency']},
|
546
525
|
]
|
547
526
|
end
|
548
527
|
end
|
549
528
|
cost_columns = {
|
550
529
|
"" => lambda {|it| it[:label] },
|
551
|
-
"Compute"
|
552
|
-
"Memory"
|
553
|
-
"Storage"
|
554
|
-
"Network"
|
555
|
-
"License"
|
556
|
-
"Extra"
|
557
|
-
"MTD" => lambda {|it| format_money(it[:running], '
|
558
|
-
"Total"
|
559
|
-
format_money(it[:total], '
|
530
|
+
"Compute" => lambda {|it| format_money(it[:compute], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
531
|
+
"Memory" => lambda {|it| format_money(it[:memory], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
532
|
+
"Storage" => lambda {|it| format_money(it[:storage], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
533
|
+
"Network" => lambda {|it| format_money(it[:network], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
534
|
+
"License" => lambda {|it| format_money(it[:license], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
535
|
+
"Extra" => lambda {|it| format_money(it[:extra], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
536
|
+
"MTD" => lambda {|it| format_money(it[:running], it[:currency] || 'USD', {sigdig:options[:sigdig]}) },
|
537
|
+
"Total" => lambda {|it|
|
538
|
+
format_money(it[:total], it[:currency] || 'USD', {sigdig:options[:sigdig]}) + ((it[:total].to_f > 0 && it[:total] != it[:running]) ? " (Projected)" : "")
|
560
539
|
},
|
561
|
-
|
540
|
+
"Currency" => lambda {|it| it[:currency] },
|
541
|
+
}.upcase_keys!
|
562
542
|
# remove columns that rarely have data...
|
563
543
|
if cost_rows.sum { |it| it[:memory].to_f } == 0
|
564
544
|
cost_columns.delete("Memory".upcase)
|
@@ -888,10 +868,10 @@ EOT
|
|
888
868
|
{"USAGE" => lambda {|it| it['itemUsage'] } },
|
889
869
|
{"RATE" => lambda {|it| it['itemRate'] } },
|
890
870
|
{"UNIT" => lambda {|it| it['rateUnit'] } },
|
891
|
-
{"PRICE" => lambda {|it| format_money(it['itemPrice'], '
|
871
|
+
{"PRICE" => lambda {|it| format_money(it['itemPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
892
872
|
] + (options[:show_costs] ? [
|
893
|
-
{"COST" => lambda {|it| format_money(it['itemCost'], '
|
894
|
-
{"TAX" => lambda {|it| format_money(it['itemTax'], '
|
873
|
+
{"COST" => lambda {|it| format_money(it['itemCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
874
|
+
{"TAX" => lambda {|it| format_money(it['itemTax'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
895
875
|
] : []) + [
|
896
876
|
{"ITEM ID" => lambda {|it| truncate_string_right(it['itemId'], 65) } },
|
897
877
|
{"ITEM NAME" => lambda {|it| it['itemName'] } },
|
@@ -923,10 +903,10 @@ EOT
|
|
923
903
|
invoice_totals_columns = [
|
924
904
|
{"Items" => lambda {|it| format_number(json_response['meta']['total']) rescue '' } },
|
925
905
|
#{"Usage" => lambda {|it| it['itemUsage'] } },
|
926
|
-
{"Price" => lambda {|it| format_money(it['itemPrice'], '
|
906
|
+
{"Price" => lambda {|it| format_money(it['itemPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
927
907
|
] + (options[:show_costs] ? [
|
928
|
-
{"Cost" => lambda {|it| format_money(it['itemCost'], '
|
929
|
-
#{"Tax" => lambda {|it| format_money(it['itemTax'], '
|
908
|
+
{"Cost" => lambda {|it| format_money(it['itemCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
909
|
+
#{"Tax" => lambda {|it| format_money(it['itemTax'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) } },
|
930
910
|
|
931
911
|
] : [])
|
932
912
|
print_description_list(invoice_totals_columns, line_item_totals)
|
@@ -993,9 +973,9 @@ EOT
|
|
993
973
|
"Usage Category" => lambda {|it| it['usageCategory'] },
|
994
974
|
"Item Usage" => lambda {|it| it['itemUsage'] },
|
995
975
|
"Item Rate" => lambda {|it| it['itemRate'] },
|
996
|
-
"Item Cost" => lambda {|it| format_money(it['itemCost'], '
|
997
|
-
"Item Price" => lambda {|it| format_money(it['itemPrice'], '
|
998
|
-
#"Item Tax" => lambda {|it| format_money(it['itemTax'], '
|
976
|
+
"Item Cost" => lambda {|it| format_money(it['itemCost'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) },
|
977
|
+
"Item Price" => lambda {|it| format_money(it['itemPrice'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) },
|
978
|
+
#"Item Tax" => lambda {|it| format_money(it['itemTax'], it['currency'] || 'USD', {sigdig:options[:sigdig]}) },
|
999
979
|
#"Tax Type" => lambda {|it| it['taxType'] },
|
1000
980
|
"Item Term" => lambda {|it| it['itemTerm'] },
|
1001
981
|
"Item ID" => lambda {|it| it['itemId'] },
|
@@ -161,6 +161,7 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
|
|
161
161
|
"Workflow" => lambda {|it| it['taskSets'] && it['taskSets'].count > 0 ? it['taskSets'][0]['name'] : nil},
|
162
162
|
"Description" => lambda {|it| it['description']},
|
163
163
|
"Horizontal Scaling" => lambda {|it| format_boolean(it['hasAutoScale'])},
|
164
|
+
"Install Docker" => lambda {|it| it['installContainerRuntime'].nil? ? nil : format_boolean(it['installContainerRuntime'])},
|
164
165
|
}
|
165
166
|
|
166
167
|
print_description_list(description_cols, layout)
|
@@ -248,6 +249,13 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
|
|
248
249
|
opts.on('-s', '--auto-scale [on|off]', String, "Can be used to enable / disable horizontal scaling. Default is on") do |val|
|
249
250
|
params['hasAutoScale'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
250
251
|
end
|
252
|
+
opts.on('--install-docker [on|off]', String, "Install Docker container runtime. Default is off.") do |val|
|
253
|
+
params['installContainerRuntime'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
254
|
+
end
|
255
|
+
opts.on('--install-container-runtime [on|off]', String, "Install Docker container runtime. Default is off.") do |val|
|
256
|
+
params['installContainerRuntime'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
257
|
+
end
|
258
|
+
opts.add_hidden_option('--install-container-runtime')
|
251
259
|
opts.on('--evars-json JSON', String, 'Environment variables JSON: {"name":"Foo", "value":"Bar", "masked":true, "export":true}' ) do |val|
|
252
260
|
begin
|
253
261
|
evars = JSON.parse(val.to_s)
|
@@ -374,6 +382,11 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
|
|
374
382
|
params['hasAutoScale'] = Morpheus::Cli::OptionTypes.confirm("Enable scaling?", {:default => false}) == true
|
375
383
|
end
|
376
384
|
|
385
|
+
# install docker
|
386
|
+
if params['installContainerRuntime'].nil?
|
387
|
+
params['installContainerRuntime'] = Morpheus::Cli::OptionTypes.confirm("Install Docker?", {:default => false}) == true
|
388
|
+
end
|
389
|
+
|
377
390
|
# evars?
|
378
391
|
if params['environmentVariables'].nil?
|
379
392
|
evars = []
|
@@ -506,6 +519,13 @@ class Morpheus::Cli::LibraryClusterLayoutsCommand
|
|
506
519
|
opts.on('-s', '--auto-scale [on|off]', String, "Can be used to enable / disable horizontal scaling. Default is on") do |val|
|
507
520
|
params['hasAutoScale'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
508
521
|
end
|
522
|
+
opts.on('--install-docker [on|off]', String, "Install Docker container runtime. Default is off.") do |val|
|
523
|
+
params['installContainerRuntime'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
524
|
+
end
|
525
|
+
opts.on('--install-container-runtime [on|off]', String, "Install Docker container runtime. Default is off.") do |val|
|
526
|
+
params['installContainerRuntime'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
527
|
+
end
|
528
|
+
opts.add_hidden_option('--install-container-runtime')
|
509
529
|
opts.on('--evars-json JSON', String, 'Environment variables JSON: {"name":"Foo", "value":"Bar", "masked":true, "export":true}' ) do |val|
|
510
530
|
begin
|
511
531
|
evars = JSON.parse(val.to_s)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# require 'yaml'
|
2
|
+
require 'io/console'
|
3
|
+
require 'rest_client'
|
4
|
+
require 'optparse'
|
5
|
+
require 'morpheus/cli/cli_command'
|
6
|
+
|
7
|
+
class Morpheus::Cli::LoadBalancerTypes
|
8
|
+
include Morpheus::Cli::CliCommand
|
9
|
+
include Morpheus::Cli::RestCommand
|
10
|
+
include Morpheus::Cli::LoadBalancersHelper
|
11
|
+
|
12
|
+
set_command_name :'load-balancer-types'
|
13
|
+
register_subcommands :list, :get
|
14
|
+
|
15
|
+
# register_interfaces :load_balancer_types
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def load_balancer_type_column_definitions
|
20
|
+
{
|
21
|
+
"ID" => 'id',
|
22
|
+
"Name" => 'name',
|
23
|
+
"Code" => 'code'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_balancer_type_list_column_definitions
|
28
|
+
load_balancer_type_column_definitions
|
29
|
+
end
|
30
|
+
|
31
|
+
# overridden to support name or code
|
32
|
+
def find_load_balancer_type_by_name_or_id(name)
|
33
|
+
load_balancer_type_for_name_or_id(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -1,161 +1,106 @@
|
|
1
1
|
# require 'yaml'
|
2
|
-
require 'io/console'
|
3
|
-
require 'rest_client'
|
4
|
-
require 'optparse'
|
5
2
|
require 'morpheus/cli/cli_command'
|
6
3
|
|
7
4
|
class Morpheus::Cli::LoadBalancers
|
8
5
|
include Morpheus::Cli::CliCommand
|
6
|
+
include Morpheus::Cli::RestCommand
|
7
|
+
include Morpheus::Cli::LoadBalancersHelper
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def initialize()
|
14
|
-
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
15
|
-
end
|
16
|
-
|
17
|
-
def connect(opts)
|
18
|
-
@api_client = establish_remote_appliance_connection(opts)
|
19
|
-
@load_balancers_interface = @api_client.load_balancers
|
20
|
-
end
|
9
|
+
set_command_name :'load-balancers'
|
10
|
+
register_subcommands :list, :get, :add, :update, :remove
|
21
11
|
|
12
|
+
# deprecated the `load-balancers types` command in 5.3.2, it moved to `load-balancer-types list`
|
13
|
+
register_subcommands :types
|
14
|
+
set_subcommands_hidden :types
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
# RestCommand settings
|
17
|
+
register_interfaces :load_balancers, :load_balancer_types
|
18
|
+
set_rest_has_type true
|
19
|
+
# set_rest_type :load_balancer_types
|
26
20
|
|
27
|
-
def
|
28
|
-
options
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
if options[:json]
|
47
|
-
puts as_json(json_response, options, "loadBalancers")
|
48
|
-
return 0
|
49
|
-
elsif options[:csv]
|
50
|
-
puts records_as_csv(json_response["loadBalancers"], options)
|
51
|
-
return 0
|
52
|
-
elsif options[:yaml]
|
53
|
-
puts as_yaml(json_response, options, "loadBalancers")
|
54
|
-
return 0
|
55
|
-
else
|
56
|
-
lbs = json_response['loadBalancers']
|
57
|
-
print_h1 "Morpheus Load Balancers"
|
58
|
-
if lbs.empty?
|
59
|
-
print cyan,"No load balancers found.",reset,"\n"
|
60
|
-
else
|
61
|
-
columns = [
|
62
|
-
{"ID" => 'id'},
|
63
|
-
{"Name" => 'name'},
|
64
|
-
{"Type" => lambda {|it| it['type'] ? it['type']['name'] : '' } },
|
65
|
-
{"Cloud" => lambda {|it| it['cloud'] ? it['cloud']['name'] : '' } },
|
66
|
-
{"Host" => lambda {|it| it['host'] } },
|
67
|
-
]
|
68
|
-
print as_pretty_table(lbs, columns, options)
|
69
|
-
end
|
70
|
-
print reset,"\n"
|
71
|
-
return 0
|
21
|
+
def render_response_for_get(json_response, options)
|
22
|
+
render_response(json_response, options, rest_object_key) do
|
23
|
+
record = json_response[rest_object_key]
|
24
|
+
print_h1 rest_label, [], options
|
25
|
+
print cyan
|
26
|
+
print_description_list(rest_column_definitions, record, options)
|
27
|
+
# show LB Ports
|
28
|
+
ports = record['ports']
|
29
|
+
if ports && ports.size > 0
|
30
|
+
print_h2 "LB Ports", options
|
31
|
+
columns = [
|
32
|
+
{"ID" => 'id'},
|
33
|
+
{"Name" => 'name'},
|
34
|
+
#{"Description" => 'description'},
|
35
|
+
{"Port" => lambda {|it| it['port'] } },
|
36
|
+
{"Protocol" => lambda {|it| it['proxyProtocol'] } },
|
37
|
+
{"SSL" => lambda {|it| it['sslEnabled'] ? "Yes (#{it['sslCert'] ? it['sslCert']['name'] : 'none'})" : "No" } },
|
38
|
+
]
|
39
|
+
print as_pretty_table(ports, columns, options)
|
72
40
|
end
|
73
|
-
|
74
|
-
print_rest_exception(e, options)
|
75
|
-
return 1
|
41
|
+
print reset,"\n"
|
76
42
|
end
|
77
43
|
end
|
78
44
|
|
79
|
-
|
45
|
+
=begin
|
46
|
+
|
47
|
+
# now using RestCommand
|
48
|
+
|
49
|
+
def add(args)
|
50
|
+
lb_type_name = nil
|
80
51
|
options = {}
|
81
52
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
82
|
-
opts.banner = subcommand_usage("[name]")
|
83
|
-
|
53
|
+
opts.banner = subcommand_usage("[name] -t LB_TYPE")
|
54
|
+
opts.on( '-t', '--type CODE', "Load Balancer Type" ) do |val|
|
55
|
+
lb_type_name = val
|
56
|
+
end
|
57
|
+
#build_option_type_options(opts, options, add_load_balancer_option_types)
|
58
|
+
build_standard_add_options(opts, options)
|
84
59
|
end
|
85
60
|
optparse.parse!(args)
|
86
|
-
|
61
|
+
lb_name = args[0]
|
62
|
+
# verify_args!(args:args, optparse:optparse, min:0, max: 1)
|
63
|
+
verify_args!(args:args, optparse:optparse, min:1, max: 1)
|
64
|
+
if lb_type_name.nil?
|
65
|
+
raise_command_error "Load Balancer Type is required.\n#{optparse}"
|
87
66
|
puts optparse
|
88
67
|
exit 1
|
89
68
|
end
|
90
|
-
lb_name = args[0]
|
91
69
|
connect(options)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
if lb_name.to_s =~ /\A\d{1,}\Z/
|
96
|
-
print_dry_run @load_balancers_interface.dry.get(lb_name.to_i)
|
97
|
-
else
|
98
|
-
print_dry_run @load_balancers_interface.dry.list({name:lb_name})
|
99
|
-
end
|
100
|
-
return
|
101
|
-
end
|
102
|
-
lb = find_lb_by_name_or_id(lb_name)
|
103
|
-
exit 1 if lb.nil?
|
104
|
-
# refetch
|
105
|
-
json_response = @load_balancers_interface.get(lb['id'])
|
106
|
-
lb_type = load_balancer_type_for_name_or_id(lb['type']['code'])
|
107
|
-
#puts "LB TYPE: #{lb_type}"
|
108
|
-
if options[:json]
|
109
|
-
puts JSON.pretty_generate({loadBalancer: lb})
|
110
|
-
puts as_json(json_response, options, "loadBalancer")
|
111
|
-
return 0
|
112
|
-
elsif options[:csv]
|
113
|
-
puts records_as_csv(json_response["loadBalancer"], options)
|
114
|
-
return 0
|
115
|
-
elsif options[:yaml]
|
116
|
-
puts as_yaml(json_response, options, "loadBalancer")
|
117
|
-
return 0
|
118
|
-
else
|
119
|
-
print_h1 "Load Balancer Details"
|
120
|
-
description_cols = {
|
121
|
-
"ID" => 'id',
|
122
|
-
"Name" => 'name',
|
123
|
-
"Description" => 'description',
|
124
|
-
"Type" => lambda {|it| it['type'] ? it['type']['name'] : '' },
|
125
|
-
"Cloud" => lambda {|it| it['cloud'] ? it['cloud']['name'] : '' },
|
126
|
-
"Visibility" => 'visibility',
|
127
|
-
"IP" => 'ip',
|
128
|
-
"Host" => 'host',
|
129
|
-
"Port" => 'port',
|
130
|
-
"Username" => 'username',
|
131
|
-
# "SSL Enabled" => lambda {|it| format_boolean it['sslEnabled'] },
|
132
|
-
# "SSL Cert" => lambda {|it| it['sslCert'] ? it['sslCert']['name'] : '' },
|
133
|
-
# "SSL" => lambda {|it| it['sslEnabled'] ? "Yes (#{it['sslCert'] ? it['sslCert']['name'] : 'none'})" : "No" },
|
134
|
-
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
135
|
-
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
|
136
|
-
}
|
137
|
-
print_description_list(description_cols, lb)
|
138
|
-
|
139
|
-
|
140
|
-
if lb['ports'] && lb['ports'].size > 0
|
141
|
-
print_h2 "LB Ports"
|
142
|
-
columns = [
|
143
|
-
{"ID" => 'id'},
|
144
|
-
{"Name" => 'name'},
|
145
|
-
#{"Description" => 'description'},
|
146
|
-
{"Port" => lambda {|it| it['port'] } },
|
147
|
-
{"Protocol" => lambda {|it| it['proxyProtocol'] } },
|
148
|
-
{"SSL" => lambda {|it| it['sslEnabled'] ? "Yes (#{it['sslCert'] ? it['sslCert']['name'] : 'none'})" : "No" } },
|
149
|
-
]
|
150
|
-
print as_pretty_table(lb['ports'], columns, options)
|
151
|
-
end
|
152
|
-
print reset,"\n"
|
153
|
-
return 0
|
154
|
-
end
|
155
|
-
rescue RestClient::Exception => e
|
156
|
-
print_rest_exception(e, options)
|
70
|
+
lb_type = load_balancer_type_for_name_or_id(lb_type_name)
|
71
|
+
if lb_type.nil?
|
72
|
+
print_red_alert "LB Type #{lb_type_name} not found!"
|
157
73
|
exit 1
|
158
74
|
end
|
75
|
+
passed_options = parse_passed_options(options)
|
76
|
+
payload = {}
|
77
|
+
if options[:payload]
|
78
|
+
payload = options[:payload]
|
79
|
+
payload.deep_merge!({load_balancer_object_key => passed_options})
|
80
|
+
else
|
81
|
+
load_balancer_payload = {'name' => lb_name, 'type' => {'code' => lb_type['code'], 'id' => lb_type['id']}}
|
82
|
+
load_balancer_payload.deep_merge!({load_balancer_object_key => passed_options})
|
83
|
+
# options by type
|
84
|
+
my_option_types = lb_type['optionTypes']
|
85
|
+
if my_option_types && !my_option_types.empty?
|
86
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, options[:params])
|
87
|
+
v_prompt.deep_compact!
|
88
|
+
load_balancer_payload.deep_merge!(v_prompt)
|
89
|
+
end
|
90
|
+
payload[load_balancer_object_key] = load_balancer_payload
|
91
|
+
end
|
92
|
+
@load_balancers_interface.setopts(options)
|
93
|
+
if options[:dry_run]
|
94
|
+
print_dry_run @load_balancers_interface.dry.create(payload)
|
95
|
+
return
|
96
|
+
end
|
97
|
+
json_response = @load_balancers_interface.create(payload)
|
98
|
+
render_response(json_response, options, load_balancer_object_key) do
|
99
|
+
load_balancer = json_response[load_balancer_object_key]
|
100
|
+
print_green_success "Added load balancer #{load_balancer['name']}"
|
101
|
+
return _get(load_balancer["id"], {}, options)
|
102
|
+
end
|
103
|
+
return 0, nil
|
159
104
|
end
|
160
105
|
|
161
106
|
def update(args)
|
@@ -163,8 +108,8 @@ class Morpheus::Cli::LoadBalancers
|
|
163
108
|
options = {}
|
164
109
|
account_name = nil
|
165
110
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
166
|
-
opts.banner = subcommand_usage("[
|
167
|
-
|
111
|
+
opts.banner = subcommand_usage("[lb] [options]")
|
112
|
+
build_standard_update_options(opts, options)
|
168
113
|
end
|
169
114
|
optparse.parse!(args)
|
170
115
|
if args.count < 1
|
@@ -172,141 +117,47 @@ class Morpheus::Cli::LoadBalancers
|
|
172
117
|
exit 1
|
173
118
|
end
|
174
119
|
connect(options)
|
175
|
-
begin
|
176
|
-
|
177
|
-
lb = find_lb_by_name_or_id(lb_name)
|
178
|
-
exit 1 if lb.nil?
|
179
|
-
lb_type = load_balancer_type_for_name_or_id(lb['type']['code'])
|
180
|
-
|
181
|
-
#params = Morpheus::Cli::OptionTypes.prompt(add_load_balancer_option_types, options[:options], @api_client, options[:params]) # options[:params] is mysterious
|
182
|
-
params = options[:options] || {}
|
183
|
-
|
184
|
-
if params.empty?
|
185
|
-
puts optparse
|
186
|
-
option_lines = update_task_option_types(lb_type).collect {|it| "\t-O #{it['fieldContext'] ? (it['fieldContext'] + '.') : ''}#{it['fieldName']}=\"value\"" }.join("\n")
|
187
|
-
puts "\nAvailable Options:\n#{option_lines}\n\n"
|
188
|
-
exit 1
|
189
|
-
end
|
190
120
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
if params['taskOptions']
|
201
|
-
task_payload['taskOptions'].merge!(params['taskOptions'])
|
202
|
-
end
|
203
|
-
payload = {task: task_payload}
|
204
|
-
@load_balancers_interface.setopts(options)
|
205
|
-
if options[:dry_run]
|
206
|
-
print_dry_run @load_balancers_interface.dry.update(task['id'], payload)
|
207
|
-
return
|
121
|
+
passed_options = parse_passed_options(options)
|
122
|
+
payload = nil
|
123
|
+
if options[:payload]
|
124
|
+
payload = options[:payload]
|
125
|
+
payload.deep_merge!({load_balancer_object_key => passed_options}) unless passed_options.empty?
|
126
|
+
else
|
127
|
+
load_balancer_payload = passed_options
|
128
|
+
if tenants_list
|
129
|
+
load_balancer_payload['accounts'] = tenants_list
|
208
130
|
end
|
209
|
-
|
210
|
-
if options[:
|
211
|
-
|
212
|
-
if !response['success']
|
213
|
-
exit 1
|
214
|
-
end
|
131
|
+
# metadata tags
|
132
|
+
if options[:tags]
|
133
|
+
load_balancer_payload['tags'] = parse_metadata(options[:tags])
|
215
134
|
else
|
216
|
-
|
135
|
+
# tags = prompt_metadata(options)
|
136
|
+
# payload[load_balancer_object_key]['tags'] = tags of tags
|
217
137
|
end
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
|
225
|
-
def lb_types(args)
|
226
|
-
options = {}
|
227
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
228
|
-
opts.banner = subcommand_usage()
|
229
|
-
build_common_options(opts, options, [:json, :dry_run, :remote])
|
230
|
-
end
|
231
|
-
optparse.parse!(args)
|
232
|
-
connect(options)
|
233
|
-
begin
|
234
|
-
@load_balancers_interface.setopts(options)
|
235
|
-
if options[:dry_run]
|
236
|
-
print_dry_run @load_balancers_interface.dry.load_balancer_types()
|
237
|
-
return
|
138
|
+
# metadata tags
|
139
|
+
if options[:add_tags]
|
140
|
+
load_balancer_payload['addTags'] = parse_metadata(options[:add_tags])
|
238
141
|
end
|
239
|
-
|
240
|
-
|
241
|
-
print JSON.pretty_generate(json_response)
|
242
|
-
else
|
243
|
-
lb_types = json_response['loadBalancerTypes']
|
244
|
-
print_h1 "Morpheus Load Balancer Types"
|
245
|
-
if lb_types.nil? || lb_types.empty?
|
246
|
-
print cyan,"No load balancer types found.",reset,"\n"
|
247
|
-
else
|
248
|
-
print cyan
|
249
|
-
lb_table_data = lb_types.collect do |lb_type|
|
250
|
-
{name: lb_type['name'], id: lb_type['id'], code: lb_type['code']}
|
251
|
-
end
|
252
|
-
print as_pretty_table(lb_table_data, [:id, :name, :code], options)
|
253
|
-
end
|
254
|
-
|
255
|
-
print reset,"\n"
|
142
|
+
if options[:remove_tags]
|
143
|
+
load_balancer_payload['removeTags'] = parse_metadata(options[:remove_tags])
|
256
144
|
end
|
257
|
-
|
258
|
-
|
259
|
-
exit 1
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
# JD: This is broken.. copied from tasks? should optionTypes exist?
|
264
|
-
def add(args)
|
265
|
-
lb_type_name = nil
|
266
|
-
options = {}
|
267
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
268
|
-
opts.banner = subcommand_usage("[name] -t LB_TYPE")
|
269
|
-
opts.on( '-t', '--type LB_TYPE', "Load Balancer Type" ) do |val|
|
270
|
-
lb_type_name = val
|
145
|
+
if load_balancer_payload.empty?
|
146
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
271
147
|
end
|
272
|
-
|
273
|
-
end
|
274
|
-
optparse.parse!(args)
|
275
|
-
lb_name = args[0]
|
276
|
-
if args.count < 1
|
277
|
-
puts optparse
|
278
|
-
exit 1
|
148
|
+
payload = {'virtualImage' => load_balancer_payload}
|
279
149
|
end
|
280
|
-
|
281
|
-
|
282
|
-
|
150
|
+
@load_balancers_interface.setopts(options)
|
151
|
+
if options[:dry_run]
|
152
|
+
print_dry_run @load_balancers_interface.dry.update(load_balancer['id'], payload)
|
153
|
+
return
|
283
154
|
end
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
print_red_alert "LB Type #{lb_type_name} not found!"
|
289
|
-
exit 1
|
290
|
-
end
|
291
|
-
|
292
|
-
payload = {loadBalancer: {name: lb_name, type: {code: lb_type['code'], id: lb_type['id']}}}
|
293
|
-
# todo: The options available here are specific by type...
|
294
|
-
#input_options = Morpheus::Cli::OptionTypes.prompt(lb_type['optionTypes'],options[:options],@api_client, options[:params])
|
295
|
-
@load_balancers_interface.setopts(options)
|
296
|
-
if options[:dry_run]
|
297
|
-
print_dry_run @load_balancers_interface.dry.create(payload)
|
298
|
-
return
|
299
|
-
end
|
300
|
-
json_response = @load_balancers_interface.create(payload)
|
301
|
-
if options[:json]
|
302
|
-
print JSON.pretty_generate(json_response)
|
303
|
-
else
|
304
|
-
print "\n", cyan, "LB #{json_response['loadBalancer']['name']} created successfully", reset, "\n\n"
|
305
|
-
end
|
306
|
-
rescue RestClient::Exception => e
|
307
|
-
print_rest_exception(e, options)
|
308
|
-
exit 1
|
155
|
+
json_response = @load_balancers_interface.update(load_balancer['id'], payload)
|
156
|
+
render_response(json_response, options, 'virtualImage') do
|
157
|
+
print_green_success "Updated virtual image #{load_balancer['name']}"
|
158
|
+
_get(load_balancer["id"], {}, options)
|
309
159
|
end
|
160
|
+
return 0, nil
|
310
161
|
end
|
311
162
|
|
312
163
|
def remove(args)
|
@@ -323,7 +174,7 @@ class Morpheus::Cli::LoadBalancers
|
|
323
174
|
end
|
324
175
|
connect(options)
|
325
176
|
begin
|
326
|
-
lb =
|
177
|
+
lb = find_load_balancer_by_name_or_id(lb_name)
|
327
178
|
exit 1 if lb.nil?
|
328
179
|
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the load balancer #{lb['name']}?")
|
329
180
|
exit
|
@@ -344,67 +195,51 @@ class Morpheus::Cli::LoadBalancers
|
|
344
195
|
exit 1
|
345
196
|
end
|
346
197
|
end
|
198
|
+
=end
|
347
199
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
if val.to_s =~ /\A\d{1,}\Z/
|
353
|
-
return find_lb_by_id(val)
|
354
|
-
else
|
355
|
-
return find_lb_by_name(val)
|
356
|
-
end
|
200
|
+
# deprecated, to be removed in the future.
|
201
|
+
def types(args)
|
202
|
+
print_error yellow,"[DEPRECATED] The command `load-balancers types` is deprecated and replaced by `load-balancer-types list`.",reset,"\n"
|
203
|
+
my_terminal.execute("load-balancer-types list #{args.join(' ')}")
|
357
204
|
end
|
358
205
|
|
359
|
-
|
360
|
-
begin
|
361
|
-
json_response = @load_balancers_interface.get(id.to_i)
|
362
|
-
return json_response['loadBalancer']
|
363
|
-
rescue RestClient::Exception => e
|
364
|
-
if e.response && e.response.code == 404
|
365
|
-
print_red_alert "Load Balancer not found by id #{id}"
|
366
|
-
else
|
367
|
-
raise e
|
368
|
-
end
|
369
|
-
end
|
370
|
-
end
|
206
|
+
protected
|
371
207
|
|
372
|
-
def
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
print reset,"\n\n"
|
381
|
-
return nil
|
382
|
-
else
|
383
|
-
return lbs[0]
|
384
|
-
end
|
208
|
+
def load_balancer_list_column_definitions()
|
209
|
+
{
|
210
|
+
"ID" => 'id',
|
211
|
+
"Name" => 'name',
|
212
|
+
"Type" => lambda {|it| it['type'] ? it['type']['name'] : '' },
|
213
|
+
"Cloud" => lambda {|it| it['cloud'] ? it['cloud']['name'] : '' },
|
214
|
+
"Host" => lambda {|it| it['host'] }
|
215
|
+
}
|
385
216
|
end
|
386
217
|
|
387
|
-
def
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
218
|
+
def load_balancer_column_definitions()
|
219
|
+
{
|
220
|
+
"ID" => 'id',
|
221
|
+
"Name" => 'name',
|
222
|
+
"Description" => 'description',
|
223
|
+
"Type" => lambda {|it| it['type'] ? it['type']['name'] : '' },
|
224
|
+
"Cloud" => lambda {|it| it['cloud'] ? it['cloud']['name'] : '' },
|
225
|
+
"Visibility" => 'visibility',
|
226
|
+
"IP" => 'ip',
|
227
|
+
"Host" => 'host',
|
228
|
+
"Port" => 'port',
|
229
|
+
"Username" => 'username',
|
230
|
+
# "SSL Enabled" => lambda {|it| format_boolean it['sslEnabled'] },
|
231
|
+
# "SSL Cert" => lambda {|it| it['sslCert'] ? it['sslCert']['name'] : '' },
|
232
|
+
# "SSL" => lambda {|it| it['sslEnabled'] ? "Yes (#{it['sslCert'] ? it['sslCert']['name'] : 'none'})" : "No" },
|
233
|
+
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
234
|
+
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
|
235
|
+
}
|
392
236
|
end
|
393
237
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
else
|
398
|
-
return load_balancer_type_for_name(val)
|
399
|
-
end
|
238
|
+
# overridden to work with name or code
|
239
|
+
def find_load_balancer_type_by_name_or_id(name)
|
240
|
+
load_balancer_type_for_name_or_id(name)
|
400
241
|
end
|
401
242
|
|
402
|
-
def load_balancer_type_for_id(id)
|
403
|
-
return get_available_load_balancer_types().find { |z| z['id'].to_i == id.to_i}
|
404
|
-
end
|
405
243
|
|
406
|
-
def load_balancer_type_for_name(name)
|
407
|
-
return get_available_load_balancer_types().find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase}
|
408
|
-
end
|
409
244
|
|
410
245
|
end
|