Class: Morpheus::Cli::InvoicesCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::InvoicesCommand
- Includes:
- CliCommand, OptionSourceHelper, ProvisioningHelper
- Defined in:
- lib/morpheus/cli/invoices_command.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
- #_get(id, options) ⇒ Object
- #_get_line_item(id, options) ⇒ Object
- #connect(opts) ⇒ Object
- #get(args) ⇒ Object
- #get_line_item(args) ⇒ Object
- #handle(args) ⇒ Object
- #list(args) ⇒ Object
- #list_line_items(args) ⇒ Object
- #refresh(args) ⇒ Object
Methods included from OptionSourceHelper
#find_available_user_option, #find_cloud_option, #find_group_option, #find_tenant_option, #get_available_user_options, #get_cloud_options, #get_group_options, #get_tenant_options, included, #load_option_source_data, #options_interface, #parse_cloud_id_list, #parse_group_id_list, #parse_option_source_id_list, #parse_project_id_list, #parse_tenant_id_list, #parse_user_id_list
Methods included from ProvisioningHelper
#accounts_interface, #add_perms_options, #api_client, #apps_interface, #cloud_datastores_interface, #clouds_interface, #datastores_interface, #find_app_by_id, #find_app_by_name, #find_app_by_name_or_id, #find_cloud_by_id_for_provisioning, #find_cloud_by_name_for_provisioning, #find_cloud_by_name_or_id_for_provisioning, #find_cloud_resource_pool_by_name_or_id, #find_group_by_id_for_provisioning, #find_group_by_name_for_provisioning, #find_group_by_name_or_id_for_provisioning, #find_host_by_id, #find_host_by_name, #find_host_by_name_or_id, #find_instance_by_id, #find_instance_by_name, #find_instance_by_name_or_id, #find_instance_type_by_code, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_instance_type_layout_by_id, #find_server_by_id, #find_server_by_name, #find_server_by_name_or_id, #find_workflow_by_id, #find_workflow_by_name, #find_workflow_by_name_or_id, #format_blueprint_type, #format_metadata, #get_available_accounts, #get_available_clouds, #get_available_environments, #get_available_groups, #get_available_plans, #get_provision_type_for_zone_type, #get_static_environments, included, #instance_type_layouts_interface, #instance_types_interface, #instances_interface, #load_balance_protocols_dropdown, #options_interface, #parse_blueprint_type, #parse_host_id_list, #parse_instance_id_list, #parse_metadata, #parse_resource_id_list, #parse_server_id_list, #print_permissions, #prompt_evars, #prompt_exposed_ports, #prompt_instance_load_balancer, #prompt_metadata, #prompt_network_interfaces, #prompt_new_instance, #prompt_permissions, #prompt_resize_volumes, #prompt_security_groups, #prompt_volumes, #provision_types_interface, #reject_service_plan_option_types, #servers_interface
Methods included from CliCommand
#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_name, #default_refresh_interval, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #render_with_format, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #verify_args!, #visible_subcommands
Instance Method Details
#_get(id, options) ⇒ Object
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/morpheus/cli/invoices_command.rb', line 393 def _get(id, ) params = {} if [:show_raw_data] params['rawData'] = true end begin @invoices_interface.setopts() if [:dry_run] print_dry_run @invoices_interface.dry.get(id, params) return end json_response = @invoices_interface.get(id, params) invoice = json_response['invoice'] render_result = render_with_format(json_response, , 'invoice') return 0 if render_result print_h1 "Invoice Details" print cyan description_cols = { "Invoice ID" => lambda {|it| it['id'] }, "Type" => lambda {|it| format_invoice_ref_type(it) }, "Ref ID" => lambda {|it| it['refId'] }, "Ref Name" => lambda {|it| it['refName'] }, "Plan" => lambda {|it| it['plan'] ? it['plan']['name'] : '' }, "Power State" => lambda {|it| format_server_power_state(it) }, "Tenant" => lambda {|it| it['account'] ? it['account']['name'] : '' }, "Active" => lambda {|it| format_boolean(it['active']) }, "Estimate" => lambda {|it| format_boolean(it['estimate']) }, #"Cost Type" => lambda {|it| it['costType'].to_s.capitalize }, "Period" => lambda {|it| format_invoice_period(it) }, #"Interval" => lambda {|it| it['interval'] }, "Start" => lambda {|it| format_date(it['startDate']) }, "End" => lambda {|it| format_date(it['endDate']) }, "Ref Start" => lambda {|it| format_dt(it['refStart']) }, "Ref End" => lambda {|it| format_dt(it['refEnd']) }, "Items" => lambda {|it| it['lineItems'].size rescue '' }, "Project ID" => lambda {|it| it['project'] ? it['project']['id'] : '' }, "Project Name" => lambda {|it| it['project'] ? it['project']['name'] : '' }, "Project Tags" => lambda {|it| it['project'] ? (it['project']['tags']) : '' }, "Created" => lambda {|it| format_local_dt(it['dateCreated']) }, "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) } } # remove columns that do not apply if invoice['plan'].nil? description_cols.delete("Plan") end if invoice['project'].nil? description_cols.delete("Project ID") description_cols.delete("Project Name") description_cols.delete("Project Tags") end if !['ComputeServer','Instance','Container'].include?(invoice['refType']) description_cols.delete("Power State") end print_description_list(description_cols, invoice) =begin print_h2 "Costs" cost_columns = { "Compute" => lambda {|it| format_money(it['computeCost'], 'usd', {sigdig:options[:sigdig]}) }, "Memory" => lambda {|it| format_money(it['memoryCost'], 'usd', {sigdig:options[:sigdig]}) }, "Storage" => lambda {|it| format_money(it['storageCost'], 'usd', {sigdig:options[:sigdig]}) }, "Network" => lambda {|it| format_money(it['networkCost'], 'usd', {sigdig:options[:sigdig]}) }, "License" => lambda {|it| format_money(it['licenseCost'], 'usd', {sigdig:options[:sigdig]}) }, "Other" => lambda {|it| format_money(it['extraCost'], 'usd', {sigdig:options[:sigdig]}) }, "Running" => lambda {|it| format_money(it['runningCost'], 'usd', {sigdig:options[:sigdig]}) }, "Total Cost" => lambda {|it| format_money(it['totalCost'], 'usd', {sigdig:options[:sigdig]}) }, } print as_pretty_table([invoice], cost_columns, options) print_h2 "Prices" price_columns = { "Compute" => lambda {|it| format_money(it['computePrice'], 'usd', {sigdig:options[:sigdig]}) }, "Memory" => lambda {|it| format_money(it['memoryPrice'], 'usd', {sigdig:options[:sigdig]}) }, "Storage" => lambda {|it| format_money(it['storagePrice'], 'usd', {sigdig:options[:sigdig]}) }, "Network" => lambda {|it| format_money(it['networkPrice'], 'usd', {sigdig:options[:sigdig]}) }, "License" => lambda {|it| format_money(it['licensePrice'], 'usd', {sigdig:options[:sigdig]}) }, "Other" => lambda {|it| format_money(it['extraPrice'], 'usd', {sigdig:options[:sigdig]}) }, "Running" => lambda {|it| format_money(it['runningPrice'], 'usd', {sigdig:options[:sigdig]}) }, "Total Price" => lambda {|it| format_money(it['totalPrice'], 'usd', {sigdig:options[:sigdig]}) }, } print as_pretty_table([invoice], price_columns, options) =end # current_date = Time.now # current_period = "#{current_date.year}#{current_date.month.to_s.rjust(2, '0')}" # Line Items line_items = invoice['lineItems'] if line_items && line_items.size > 0 && [:hide_line_items] != true line_items_columns = [ {"ID" => lambda {|it| it['id'] } }, #{"REF TYPE" => lambda {|it| format_invoice_ref_type(it) } }, #{"REF ID" => lambda {|it| it['refId'] } }, #{"REF NAME" => lambda {|it| it['refName'] } }, #{"REF CATEGORY" => lambda {|it| it['refCategory'] } }, {"START" => lambda {|it| format_dt(it['startDate']) } }, {"END" => lambda {|it| format_dt(it['endDate']) } }, {"USAGE TYPE" => lambda {|it| it['usageType'] } }, {"USAGE CATEGORY" => lambda {|it| it['usageCategory'] } }, {"USAGE" => lambda {|it| it['itemUsage'] } }, {"RATE" => lambda {|it| it['itemRate'] } }, {"COST" => lambda {|it| format_money(it['itemCost'], 'usd', {sigdig:[:sigdig]}) } }, {"PRICE" => lambda {|it| format_money(it['itemPrice'], 'usd', {sigdig:[:sigdig]}) } }, #{"TAX" => lambda {|it| format_money(it['itemTax'], 'usd', {sigdig:options[:sigdig]}) } }, # {"TERM" => lambda {|it| it['itemTerm'] } }, {"ITEM ID" => lambda {|it| truncate_string_right(it['itemId'], 65) } }, {"ITEM NAME" => lambda {|it| it['itemName'] } }, {"ITEM TYPE" => lambda {|it| it['itemType'] } }, {"ITEM DESCRIPTION" => lambda {|it| it['itemDescription'] } }, {"PRODUCT CODE" => lambda {|it| it['productCode'] } }, {"CREATED" => lambda {|it| format_local_dt(it['dateCreated']) } }, {"UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } } ] if [:show_raw_data] line_items_columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }] end print_h2 "Line Items" #max_line_items = options[:max_line_items] ? options[:max_line_items].to_i : 5 paged_line_items = line_items #.first(max_line_items) print as_pretty_table(paged_line_items, line_items_columns, ) print_results_pagination({total: line_items.size, size: paged_line_items.size}, {:label => "line item", :n_label => "line items"}) end # cost_types = ["Costs"] # cost_types << "Prices" if options[:show_prices] # cost_types << "Estimates" if options[:show_estimates] # print_h2 cost_types.size == 1 ? "Totals" : "Total #{anded_list(cost_types)}" print_h2 "Invoice Totals" cost_rows = [ {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']}, ] if [:show_prices] cost_rows += [ {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']}, ] end if [:show_estimates] cost_rows += [ {label: 'Estimated 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']}, {label: 'Estimated 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']}, ] end cost_columns = { "" => lambda {|it| it[:label] }, "Compute".upcase => lambda {|it| format_money(it[:compute], 'usd', {sigdig:[:sigdig]}) }, "Memory".upcase => lambda {|it| format_money(it[:memory], 'usd', {sigdig:[:sigdig]}) }, "Storage".upcase => lambda {|it| format_money(it[:storage], 'usd', {sigdig:[:sigdig]}) }, "Network".upcase => lambda {|it| format_money(it[:network], 'usd', {sigdig:[:sigdig]}) }, "License".upcase => lambda {|it| format_money(it[:license], 'usd', {sigdig:[:sigdig]}) }, "Other".upcase => lambda {|it| format_money(it[:extra], 'usd', {sigdig:[:sigdig]}) }, "MTD" => lambda {|it| format_money(it[:running], 'usd', {sigdig:[:sigdig]}) }, "Total".upcase => lambda {|it| format_money(it[:total], 'usd', {sigdig:[:sigdig]}) + ((it[:total].to_f > 0 && it[:total] != it[:running]) ? " (Projected)" : "") }, } # remove columns that rarely have data... if cost_rows.sum { |it| it[:memory].to_f } == 0 cost_columns.delete("Memory".upcase) end if cost_rows.sum { |it| it[:license].to_f } == 0 cost_columns.delete("License".upcase) end if cost_rows.sum { |it| it[:extra].to_f } == 0 cost_columns.delete("Other".upcase) end print as_pretty_table(cost_rows, cost_columns, ) if [:show_raw_data] print_h2 "Raw Data" puts as_json(invoice['rawData'], {pretty_json:false}.merge()) end print reset,"\n" return 0 rescue RestClient::Exception => e print_rest_exception(e, ) return 1 end end |
#_get_line_item(id, options) ⇒ Object
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
# File 'lib/morpheus/cli/invoices_command.rb', line 932 def _get_line_item(id, ) params = {} if [:show_raw_data] params['rawData'] = true end @invoice_line_items_interface.setopts() if [:dry_run] print_dry_run @invoice_line_items_interface.dry.get(id, params) return end json_response = @invoice_line_items_interface.get(id, params) line_item = json_response['lineItem'] render_response(json_response, , 'lineItem') do print_h1 "Line Item Details" print cyan description_cols = { "ID" => lambda {|it| it['id'] }, "Invoice ID" => lambda {|it| it['invoiceId'] }, "Type" => lambda {|it| format_invoice_ref_type(it) }, "Ref ID" => lambda {|it| it['refId'] }, "Ref Name" => lambda {|it| it['refName'] }, "Start" => lambda {|it| format_date(it['startDate']) }, "End" => lambda {|it| it['endDate'] ? format_date(it['endDate']) : '' }, "Usage Type" => lambda {|it| it['usageType'] }, "Usage Category" => lambda {|it| it['usageCategory'] }, "Item Usage" => lambda {|it| it['itemUsage'] }, "Item Rate" => lambda {|it| it['itemRate'] }, "Item Cost" => lambda {|it| format_money(it['itemCost'], 'usd', {sigdig:[:sigdig]}) }, "Item Price" => lambda {|it| format_money(it['itemPrice'], 'usd', {sigdig:[:sigdig]}) }, #"Item Tax" => lambda {|it| format_money(it['itemTax'], 'usd', {sigdig:options[:sigdig]}) }, #"Tax Type" => lambda {|it| it['taxType'] }, "Item Term" => lambda {|it| it['itemTerm'] }, "Item ID" => lambda {|it| it['itemId'] }, "Item Name" => lambda {|it| it['itemName'] }, "Item Type" => lambda {|it| it['itemType'] }, "Item Description" => lambda {|it| it['itemDescription'] }, "Product Code" => lambda {|it| it['productCode'] }, "Created" => lambda {|it| format_local_dt(it['dateCreated']) }, "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) } } print_description_list(description_cols, line_item, ) if [:show_raw_data] print_h2 "Raw Data" puts as_json(line_item['rawData'], {pretty_json:false}.merge()) end print reset,"\n" end return 0, nil end |
#connect(opts) ⇒ Object
14 15 16 17 18 |
# File 'lib/morpheus/cli/invoices_command.rb', line 14 def connect(opts) @api_client = establish_remote_appliance_connection(opts) @invoices_interface = @api_client.invoices @invoice_line_items_interface = @api_client.invoice_line_items end |
#get(args) ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/morpheus/cli/invoices_command.rb', line 347 def get(args) = {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage("[id]") opts.on('-a', '--all', "Display all details, costs and prices." ) do [:show_estimates] = true # options[:show_costs] = true [:show_prices] = true # options[:show_raw_data] = true [:max_line_items] = 10000 end opts.on('--prices', '--prices', "Display prices: Total, Compute, Storage, Network, Other" ) do [:show_prices] = true end opts.on('--estimates', '--estimates', "Display all estimated costs, from usage info: Compute, Storage, Network, Other" ) do [:show_estimates] = true end opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val| [:show_raw_data] = true end opts.on('--pretty-raw-data', '--raw-data', "Display Raw Data that is a bit more pretty") do |val| [:show_raw_data] = true [:pretty_json] = true end opts.on('--no-line-items', '--no-line-items', "Do not display line items.") do |val| [:hide_line_items] = true end opts.on('--sigdig DIGITS', "Significant digits when rounding cost values for display as currency. Default is 2. eg. $3.50") do |val| [:sigdig] = val.to_i end (opts, ) opts. = "Get details about a specific invoice." opts. = <<-EOT Get details about a specific invoice. [id] is required. This is the id of an invoice. EOT end optparse.parse!(args) verify_args!(args:args, optparse:optparse, min:1) connect() id_list = parse_id_list(args) return run_command_for_each_arg(id_list) do |arg| _get(arg, ) end end |
#get_line_item(args) ⇒ Object
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/morpheus/cli/invoices_command.rb', line 902 def get_line_item(args) = {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage("[id]") opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val| [:show_raw_data] = true end opts.on('--pretty-raw-data', '--raw-data', "Display Raw Data that is a bit more pretty") do |val| [:show_raw_data] = true [:pretty_json] = true end opts.on('--sigdig DIGITS', "Significant digits when rounding cost values for display as currency. Default is 2. eg. $3.50") do |val| [:sigdig] = val.to_i end (opts, ) opts. = "Get details about a specific invoice line item." opts. = <<-EOT Get details about a specific invoice line item. [id] is required. This is the id of an invoice line item. EOT end optparse.parse!(args) verify_args!(args:args, optparse:optparse, min:1) connect() id_list = parse_id_list(args) return run_command_for_each_arg(id_list) do |arg| _get_line_item(arg, ) end end |
#handle(args) ⇒ Object
20 21 22 |
# File 'lib/morpheus/cli/invoices_command.rb', line 20 def handle(args) handle_subcommand(args) end |
#list(args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/morpheus/cli/invoices_command.rb', line 24 def list(args) = {} params = {} ref_ids = [] optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage() opts.on('-a', '--all', "Display all details, costs and prices." ) do [:show_all] = true [:show_estimates] = true # options[:show_costs] = true [:show_prices] = true # options[:show_raw_data] = true end opts.on('--estimates', '--estimates', "Display all estimated costs, from usage info: Compute, Storage, Network, Other" ) do [:show_estimates] = true end # opts.on('--costs', '--costs', "Display all costs: Compute, Storage, Network, Other" ) do # options[:show_costs] = true # end opts.on('--prices', '--prices', "Display prices: Total, Compute, Storage, Network, Other" ) do [:show_prices] = true end opts.on('--type TYPE', String, "Filter by Ref Type eg. ComputeSite (Group), ComputeZone (Cloud), ComputeServer (Host), Instance, Container, User") do |val| params['refType'] ||= [] values = val.split(",").collect {|it| it.strip }.select {|it| it != "" } values.each { |it| params['refType'] << parse_invoice_ref_type(it) } end opts.on('--id ID', String, "Filter by Ref ID") do |val| ref_ids << val end opts.on('--ref-id ID', String, "Filter by Ref ID") do |val| ref_ids << val end opts.add_hidden_option('--ref-id') opts.on('--group ID', String, "Filter by Group") do |val| [:groups] ||= [] [:groups] << val end opts.on( '-c', '--cloud CLOUD', "Filter by Cloud" ) do |val| [:clouds] ||= [] [:clouds] << val end opts.on('--instance ID', String, "Filter by Instance") do |val| [:instances] ||= [] [:instances] << val end opts.on('--container ID', String, "Filter by Container") do |val| params['containerId'] ||= [] params['containerId'] << val end opts.on('--server ID', String, "Filter by Server (Host)") do |val| [:servers] ||= [] [:servers] << val end opts.on('--user ID', String, "Filter by User") do |val| [:users] ||= [] [:users] << val end opts.on('--project PROJECT', String, "View invoices for a project.") do |val| [:projects] ||= [] [:projects] << val end # opts.on('--cluster ID', String, "Filter by Cluster") do |val| # params['clusterId'] ||= [] # params['clusterId'] << val # end opts.on('--start DATE', String, "Start date in the format YYYY-MM-DD.") do |val| params['startDate'] = val #parse_time(val).utc.iso8601 end opts.on('--end DATE', String, "End date in the format YYYY-MM-DD. Default is now.") do |val| params['endDate'] = val #parse_time(val).utc.iso8601 end opts.on('--period PERIOD', String, "Period in the format YYYYMM. This can be used instead of start/end.") do |val| params['period'] = parse_period(val) end opts.on('--active [true|false]',String, "Filter by active.") do |val| params['active'] = (val.to_s != 'false' && val.to_s != 'off') end opts.on('--estimate [true|false]',String, "Filter by estimate.") do |val| params['estimate'] = (val.to_s != 'false' && val.to_s != 'off') end opts.on('--tenant ID', String, "View invoices for a tenant. Default is your own account.") do |val| params['accountId'] = val end opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val| [:show_raw_data] = true end opts.on('--totals', "View total costs and prices for all the invoices found.") do |val| params['includeTotals'] = true [:show_invoice_totals] = true end opts.on('--totals-only', "View totals only") do |val| params['includeTotals'] = true [:show_invoice_totals] = true [:totals_only] = true end opts.on('--sigdig DIGITS', "Significant digits when rounding cost values for display as currency. Default is 2. eg. $3.50") do |val| [:sigdig] = val.to_i end (opts, ) opts. = "List invoices." end optparse.parse!(args) connect() # verify_args!(args:args, optparse:optparse, count:0) if args.count > 0 [:phrase] = args.join(" ") end # construct params params.merge!(()) if [:clouds] cloud_ids = parse_cloud_id_list([:clouds]) return 1, "clouds not found for #{[:clouds]}" if cloud_ids.nil? params['zoneId'] = cloud_ids end if [:groups] group_ids = parse_group_id_list([:groups]) return 1, "groups not found for #{[:groups]}" if group_ids.nil? params['siteId'] = group_ids end if [:instances] instance_ids = parse_instance_id_list([:instances]) return 1, "instances not found for #{[:instances]}" if instance_ids.nil? params['instanceId'] = instance_ids end if [:servers] server_ids = parse_server_id_list([:servers]) return 1, "servers not found for #{[:servers]}" if server_ids.nil? params['serverId'] = server_ids end if [:users] user_ids = parse_user_id_list([:users]) return 1, "users not found for #{[:users]}" if user_ids.nil? params['userId'] = user_ids end if [:projects] project_ids = parse_project_id_list([:projects]) return 1, "projects not found for #{[:projects]}" if project_ids.nil? params['projectId'] = project_ids end params['rawData'] = true if [:show_raw_data] params['refId'] = ref_ids unless ref_ids.empty? @invoices_interface.setopts() if [:dry_run] print_dry_run @invoices_interface.dry.list(params) return end json_response = @invoices_interface.list(params) invoices = json_response['invoices'] render_response(json_response, , 'invoices') do title = "Morpheus Invoices" subtitles = [] if params['startDate'] subtitles << "Start Date: #{params['startDate']}" end if params['endDate'] subtitles << "End Date: #{params['endDate']}" end subtitles += parse_list_subtitles() print_h1 title, subtitles if invoices.empty? unless [:totals_only] print cyan,"No invoices found.",reset,"\n" end else # current_date = Time.now # current_period = "#{current_date.year}#{current_date.month.to_s.rjust(2, '0')}" show_projects = invoices.find {|it| it['project'] } || (params['projectId'] || params['projectName'] || params['projectTag']) columns = [ {"INVOICE ID" => lambda {|it| it['id'] } }, {"TYPE" => lambda {|it| format_invoice_ref_type(it) } }, {"REF ID" => lambda {|it| it['refId'] } }, {"REF NAME" => lambda {|it| if [:show_all] it['refName'] else truncate_string_right(it['refName'], 100) end } }, #{"INTERVAL" => lambda {|it| it['interval'] } }, {"CLOUD" => lambda {|it| it['cloud'] ? it['cloud']['name'] : '' } }, #{"TENANT" => lambda {|it| it['account'] ? it['account']['name'] : '' } }, #{"COST TYPE" => lambda {|it| it['costType'].to_s.capitalize } }, {"PERIOD" => lambda {|it| format_invoice_period(it) } }, {"START" => lambda {|it| format_date(it['startDate']) } }, {"END" => lambda {|it| format_date(it['endDate']) } }, ] + ([:show_all] ? [ {"REF START" => lambda {|it| format_dt(it['refStart']) } }, {"REF END" => lambda {|it| format_dt(it['refEnd']) } }, ] : []) + [ {"COMPUTE" => lambda {|it| format_money(it['computeCost'], 'usd', {sigdig:[:sigdig]}) } }, # {"MEMORY" => lambda {|it| format_money(it['memoryCost']) } }, {"STORAGE" => lambda {|it| format_money(it['storageCost'], 'usd', {sigdig:[:sigdig]}) } }, {"NETWORK" => lambda {|it| format_money(it['networkCost'], 'usd', {sigdig:[:sigdig]}) } }, {"OTHER" => lambda {|it| format_money(it['extraCost'], 'usd', {sigdig:[:sigdig]}) } }, {"MTD" => lambda {|it| format_money(it['runningCost'], 'usd', {sigdig:[:sigdig]}) } }, {"TOTAL" => lambda {|it| format_money(it['totalCost'], 'usd', {sigdig:[:sigdig]}) + ((it['totalCost'].to_f > 0 && it['totalCost'] != it['runningCost']) ? " (Projected)" : "") } } ] if [:show_prices] columns += [ {"COMPUTE PRICE" => lambda {|it| format_money(it['computePrice'], 'usd', {sigdig:[:sigdig]}) } }, # {"MEMORY PRICE" => lambda {|it| format_money(it['memoryPrice'], 'usd', {sigdig:options[:sigdig]}) } }, {"STORAGE PRICE" => lambda {|it| format_money(it['storagePrice'], 'usd', {sigdig:[:sigdig]}) } }, {"NETWORK PRICE" => lambda {|it| format_money(it['networkPrice'], 'usd', {sigdig:[:sigdig]}) } }, {"OTHER PRICE" => lambda {|it| format_money(it['extraPrice'], 'usd', {sigdig:[:sigdig]}) } }, {"MTD PRICE" => lambda {|it| format_money(it['runningPrice'], 'usd', {sigdig:[:sigdig]}) } }, {"TOTAL PRICE" => lambda {|it| format_money(it['totalPrice'], 'usd', {sigdig:[:sigdig]}) + ((it['totalCost'].to_f > 0 && it['totalCost'] != it['runningCost']) ? " (Projected)" : "") } } ] end if [:show_estimates] columns += [ {"COMPUTE EST." => lambda {|it| format_money(it['estimatedComputeCost'], 'usd', {sigdig:[:sigdig]}) } }, # {"MEMORY EST." => lambda {|it| format_money(it['estimatedMemoryCost'], 'usd', {sigdig:options[:sigdig]}) } }, {"STORAGE EST." => lambda {|it| format_money(it['estimatedStorageCost'], 'usd', {sigdig:[:sigdig]}) } }, {"NETWORK EST." => lambda {|it| format_money(it['estimatedNetworkCost'], 'usd', {sigdig:[:sigdig]}) } }, {"OTHER EST." => lambda {|it| format_money(it['estimatedExtraCost'], 'usd', {sigdig:[:sigdig]}) } }, {"MTD EST." => lambda {|it| format_money(it['estimatedRunningCost'], 'usd', {sigdig:[:sigdig]}) } }, {"TOTAL EST." => lambda {|it| format_money(it['estimatedTotalCost'], 'usd', {sigdig:[:sigdig]}) + ((it['estimatedTotalCost'].to_f > 0 && it['estimatedTotalCost'] != it['estimatedRunningCost']) ? " (Projected)" : "") } }, ] end columns += [ {"ESTIMATE" => lambda {|it| format_boolean(it['estimate']) } }, {"ACTIVE" => lambda {|it| format_boolean(it['active']) } }, {"ITEMS" => lambda {|it| it['lineItems'].size rescue '' } }, ] if show_projects columns += [ {"PROJECT ID" => lambda {|it| it['project'] ? it['project']['id'] : '' } }, {"PROJECT NAME" => lambda {|it| it['project'] ? it['project']['name'] : '' } }, {"PROJECT TAGS" => lambda {|it| it['project'] ? truncate_string((it['project']['tags']), 50) : '' } }, ] end columns += [ {"CREATED" => lambda {|it| format_local_dt(it['dateCreated']) } }, {"UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } } ] if [:show_raw_data] columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }] end unless [:totals_only] print as_pretty_table(invoices, columns, ) print_results_pagination(json_response, {:label => "invoice", :n_label => "invoices"}) end if [:show_invoice_totals] invoice_totals = json_response['invoiceTotals'] print_h2 "Line Item Totals" unless [:totals_only] invoice_totals_columns = [ {"Invoices" => lambda {|it| format_number(json_response['meta']['total']) rescue '' } }, {"Compute" => lambda {|it| format_money(it['actualComputeCost'], 'usd', {sigdig:[:sigdig]}) } }, {"Storage" => lambda {|it| format_money(it['actualStorageCost'], 'usd', {sigdig:[:sigdig]}) } }, {"Network" => lambda {|it| format_money(it['actualNetworkCost'], 'usd', {sigdig:[:sigdig]}) } }, {"Extra" => lambda {|it| format_money(it['actualExtraCost'], 'usd', {sigdig:[:sigdig]}) } }, ] + ([:show_prices] ? [ {"Compute Price" => lambda {|it| format_money(it['actualComputePrice'], 'usd', {sigdig:[:sigdig]}) } }, {"Storage Price" => lambda {|it| format_money(it['actualStoragePrice'], 'usd', {sigdig:[:sigdig]}) } }, {"Network Price" => lambda {|it| format_money(it['actualNetworkPrice'], 'usd', {sigdig:[:sigdig]}) } }, {"Extra Price" => lambda {|it| format_money(it['actualExtraPrice'], 'usd', {sigdig:[:sigdig]}) } }, ] : []) print_description_list(invoice_totals_columns, line_item_totals) end if [:show_invoice_totals] invoice_totals = json_response['invoiceTotals'] print_h2 "Invoice Totals (#{format_number(json_response['meta']['total']) rescue ''})" if invoice_totals cost_rows = [ {label: 'Cost', 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']}, ] if [:show_prices] cost_rows += [ {label: 'Price', 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']}, ] end if [:show_estimates] cost_rows += [ {label: 'Estimated 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']}, {label: 'Estimated 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']}, ] end cost_columns = { "" => lambda {|it| it[:label] }, "Compute".upcase => lambda {|it| format_money(it[:compute], 'usd', {sigdig:[:sigdig]}) }, "Memory".upcase => lambda {|it| format_money(it[:memory], 'usd', {sigdig:[:sigdig]}) }, "Storage".upcase => lambda {|it| format_money(it[:storage], 'usd', {sigdig:[:sigdig]}) }, "Network".upcase => lambda {|it| format_money(it[:network], 'usd', {sigdig:[:sigdig]}) }, "License".upcase => lambda {|it| format_money(it[:license], 'usd', {sigdig:[:sigdig]}) }, "Other".upcase => lambda {|it| format_money(it[:extra], 'usd', {sigdig:[:sigdig]}) }, "MTD" => lambda {|it| format_money(it[:running], 'usd', {sigdig:[:sigdig]}) }, "Total".upcase => lambda {|it| format_money(it[:total], 'usd', {sigdig:[:sigdig]}) + ((it[:total].to_f > 0 && it[:total] != it[:running]) ? " (Projected)" : "") }, } # remove columns that rarely have data... if cost_rows.sum { |it| it[:memory].to_f } == 0 cost_columns.delete("Memory".upcase) end if cost_rows.sum { |it| it[:license].to_f } == 0 cost_columns.delete("License".upcase) end if cost_rows.sum { |it| it[:extra].to_f } == 0 cost_columns.delete("Other".upcase) end print as_pretty_table(cost_rows, cost_columns, ) else print "\n" print yellow, "No invoice totals data", reset, "\n" end end end print reset,"\n" return 0, nil end end |
#list_line_items(args) ⇒ Object
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
# File 'lib/morpheus/cli/invoices_command.rb', line 655 def list_line_items(args) = {} params = {} ref_ids = [] optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage() opts.on('-a', '--all', "Display all details, costs and prices." ) do [:show_actual_costs] = true [:show_costs] = true [:show_prices] = true # options[:show_raw_data] = true end # opts.on('--actuals', '--actuals', "Display all actual costs: Compute, Storage, Network, Other" ) do # options[:show_actual_costs] = true # end # opts.on('--costs', '--costs', "Display all costs: Compute, Storage, Network, Other" ) do # options[:show_costs] = true # end opts.on('--prices', '--prices', "Display prices: Total, Compute, Storage, Network, Other" ) do [:show_prices] = true end opts.on('--invoice-id ID', String, "Filter by Invoice ID") do |val| params['invoiceId'] ||= [] params['invoiceId'] << val end opts.on('--external-id ID', String, "Filter by External ID") do |val| params['externalId'] ||= [] params['externalId'] << val end opts.on('--type TYPE', String, "Filter by Ref Type eg. ComputeSite (Group), ComputeZone (Cloud), ComputeServer (Host), Instance, Container, User") do |val| params['refType'] ||= [] values = val.split(",").collect {|it| it.strip }.select {|it| it != "" } values.each { |it| params['refType'] << parse_invoice_ref_type(it) } end opts.on('--id ID', String, "Filter by Ref ID") do |val| ref_ids << val end opts.on('--ref-id ID', String, "Filter by Ref ID") do |val| ref_ids << val end opts.add_hidden_option('--ref-id') opts.on('--group ID', String, "Filter by Group") do |val| [:groups] ||= [] [:groups] << val end opts.on( '-c', '--cloud CLOUD', "Filter by Cloud" ) do |val| [:clouds] ||= [] [:clouds] << val end opts.on('--instance ID', String, "Filter by Instance") do |val| [:instances] ||= [] [:instances] << val end opts.on('--container ID', String, "Filter by Container") do |val| params['containerId'] ||= [] params['containerId'] << val end opts.on('--server ID', String, "Filter by Server (Host)") do |val| [:servers] ||= [] [:servers] << val end opts.on('--user ID', String, "Filter by User") do |val| [:users] ||= [] [:users] << val end opts.on('--project PROJECT', String, "View invoices for a project.") do |val| [:projects] ||= [] [:projects] << val end # opts.on('--cluster ID', String, "Filter by Cluster") do |val| # params['clusterId'] ||= [] # params['clusterId'] << val # end opts.on('--start DATE', String, "Start date in the format YYYY-MM-DD.") do |val| params['startDate'] = val #parse_time(val).utc.iso8601 end opts.on('--end DATE', String, "End date in the format YYYY-MM-DD. Default is now.") do |val| params['endDate'] = val #parse_time(val).utc.iso8601 end opts.on('--period PERIOD', String, "Period in the format YYYYMM. This can be used instead of start/end.") do |val| params['period'] = parse_period(val) end opts.on('--active [true|false]',String, "Filter by active.") do |val| params['active'] = (val.to_s != 'false' && val.to_s != 'off') end opts.on('--estimate [true|false]',String, "Filter by estimate.") do |val| params['estimate'] = (val.to_s != 'false' && val.to_s != 'off') end opts.on('--tenant ID', String, "View invoice line items for a tenant. Default is your own account.") do |val| params['accountId'] = val end opts.on('--raw-data', '--raw-data', "Display Raw Data, the cost data from the cloud provider's API.") do |val| [:show_raw_data] = true end opts.on('--totals', "View total costs and prices for all the invoices found.") do |val| params['includeTotals'] = true [:show_invoice_totals] = true end opts.on('--totals-only', "View totals only") do |val| params['includeTotals'] = true [:show_invoice_totals] = true [:totals_only] = true end opts.on('--sigdig DIGITS', "Significant digits when rounding cost values for display as currency. Default is 2. eg. $3.50") do |val| [:sigdig] = val.to_i end (opts, ) opts. = "List invoice line items." end optparse.parse!(args) connect() # verify_args!(args:args, optparse:optparse, count:0) if args.count > 0 [:phrase] = args.join(" ") end # construct params params.merge!(()) if [:clouds] cloud_ids = parse_cloud_id_list([:clouds]) return 1, "clouds not found for #{[:clouds]}" if cloud_ids.nil? params['zoneId'] = cloud_ids end if [:groups] group_ids = parse_group_id_list([:groups]) return 1, "groups not found for #{[:groups]}" if group_ids.nil? params['siteId'] = group_ids end if [:instances] instance_ids = parse_instance_id_list([:instances]) return 1, "instances not found for #{[:instances]}" if instance_ids.nil? params['instanceId'] = instance_ids end if [:servers] server_ids = parse_server_id_list([:servers]) return 1, "servers not found for #{[:servers]}" if server_ids.nil? params['serverId'] = server_ids end if [:users] user_ids = parse_user_id_list([:users]) return 1, "users not found for #{[:users]}" if user_ids.nil? params['userId'] = user_ids end if [:projects] project_ids = parse_project_id_list([:projects]) return 1, "projects not found for #{[:projects]}" if project_ids.nil? params['projectId'] = project_ids end params['rawData'] = true if [:show_raw_data] params['refId'] = ref_ids unless ref_ids.empty? @invoice_line_items_interface.setopts() if [:dry_run] print_dry_run @invoice_line_items_interface.dry.list(params) return end json_response = @invoice_line_items_interface.list(params) line_items = json_response['lineItems'] render_response(json_response, , 'lineItems') do title = "Morpheus Line Items" subtitles = [] if params['startDate'] subtitles << "Start Date: #{params['startDate']}" end if params['endDate'] subtitles << "End Date: #{params['endDate']}" end subtitles += parse_list_subtitles() print_h1 title, subtitles if line_items.empty? print yellow,"No line items found.",reset,"\n" else # current_date = Time.now # current_period = "#{current_date.year}#{current_date.month.to_s.rjust(2, '0')}" columns = [ {"ID" => lambda {|it| it['id'] } }, {"INVOICE ID" => lambda {|it| it['invoiceId'] } }, {"TYPE" => lambda {|it| format_invoice_ref_type(it) } }, {"REF ID" => lambda {|it| it['refId'] } }, {"REF NAME" => lambda {|it| it['refName'] } }, #{"REF CATEGORY" => lambda {|it| it['refCategory'] } }, {"START" => lambda {|it| format_date(it['startDate']) } }, {"END" => lambda {|it| format_date(it['endDate']) } }, {"USAGE TYPE" => lambda {|it| it['usageType'] } }, {"USAGE CATEGORY" => lambda {|it| it['usageCategory'] } }, {"USAGE" => lambda {|it| it['itemUsage'] } }, {"RATE" => lambda {|it| it['itemRate'] } }, {"COST" => lambda {|it| format_money(it['itemCost'], 'usd', {sigdig:[:sigdig]}) } }, ] + ([:show_prices] ? [ {"PRICE" => lambda {|it| format_money(it['itemPrice'], 'usd', {sigdig:[:sigdig]}) } }, {"TAX" => lambda {|it| format_money(it['itemTax'], 'usd', {sigdig:[:sigdig]}) } }, ] : []) + [ {"ITEM ID" => lambda {|it| truncate_string_right(it['itemId'], 65) } }, {"ITEM NAME" => lambda {|it| it['itemName'] } }, {"ITEM TYPE" => lambda {|it| it['itemType'] } }, {"ITEM DESCRIPTION" => lambda {|it| it['itemDescription'] } }, {"PRODUCT CODE" => lambda {|it| it['productCode'] } }, "CREATED" => lambda {|it| format_local_dt(it['dateCreated']) }, "UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } ] if [:show_raw_data] columns += [{"RAW DATA" => lambda {|it| truncate_string(it['rawData'].to_s, 10) } }] end # if options[:show_invoice_totals] # line_item_totals = json_response['lineItemTotals'] # if line_item_totals # totals_row = line_item_totals.clone # totals_row['id'] = 'TOTAL:' # #totals_row['usageCategory'] = 'TOTAL:' # line_items = line_items + [totals_row] # end # end unless [:totals_only] print as_pretty_table(line_items, columns, ) print_results_pagination(json_response, {:label => "line item", :n_label => "line items"}) end if [:show_invoice_totals] line_item_totals = json_response['lineItemTotals'] if line_item_totals print_h2 "Line Item Totals" unless [:totals_only] invoice_totals_columns = [ {"Items" => lambda {|it| format_number(json_response['meta']['total']) rescue '' } }, #{"Usage" => lambda {|it| it['itemUsage'] } }, {"Cost" => lambda {|it| format_money(it['itemCost'], 'usd', {sigdig:[:sigdig]}) } }, ] + ([:show_prices] ? [ {"Price" => lambda {|it| format_money(it['itemPrice'], 'usd', {sigdig:[:sigdig]}) } }, #{"Tax" => lambda {|it| format_money(it['itemTax'], 'usd', {sigdig:options[:sigdig]}) } }, ] : []) print_description_list(invoice_totals_columns, line_item_totals) else print "\n" print yellow, "No line item totals data", reset, "\n" end end end print reset,"\n" end if line_items.empty? return 1, "no line items found" else return 0, nil end end |
#refresh(args) ⇒ Object
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/morpheus/cli/invoices_command.rb', line 578 def refresh(args) = {} params = {} payload = {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage("[--daily] [--costing] [--current] [-c CLOUD]") opts.on( '--daily', "Refresh Daily Invoices" ) do payload[:daily] = true end opts.on( '--costing', "Refresh Costing Data" ) do payload[:costing] = true end opts.on( '--current', "Collect the most up to date costing data." ) do payload[:current] = true end 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| payload[:date] = val.to_s end opts.on( '-c', '--cloud CLOUD', "Specify cloud(s) to refresh costing for." ) do |val| payload[:clouds] ||= [] payload[:clouds] << val end opts.on( '--all', "Refresh costing for all clouds." ) do payload[:all] = true end # opts.on( '-f', '--force', "Force Refresh" ) do # query_params[:force] = 'true' # end (opts, , [:query, :auto_confirm]) opts. = <<-EOT Refresh invoices. By default, nothing is changed. Include --daily to regenerate invoice records. Include --costing to refresh actual costing data. Include --current to refresh costing data for the actual current time. To get the latest invoice costing data, include --daily --costing --current --all EOT end optparse.parse!(args) verify_args!(args:args, optparse:optparse, count:0) connect() params.merge!(()) if [:payload] payload = [:payload] end payload.deep_merge!(()) # --clouds if payload[:clouds] payload[:clouds] = parse_id_list(payload[:clouds]).collect {|cloud_id| if cloud_id.to_s =~ /\A\d{1,}\Z/ cloud_id else cloud = find_cloud_option(cloud_id) return 1 if cloud.nil? cloud['id'] end } end # are you sure? unless [:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to refresh invoices?") return 9, "aborted command" end # ok, make the request @invoices_interface.setopts() if [:dry_run] print_dry_run @invoices_interface.dry.refresh(params, payload) return end json_response = @invoices_interface.refresh(params, payload) # render the result render_result = render_with_format(json_response, ) return 0 if render_result # print output print_green_success(json_response['msg'] || "Refreshing invoices") return 0 end |