January 29, 2016

Calculating month-to-date cost of a Virtual_Guest

Determine the month-to-date cost of an hourly Virtual_Guest using getBillingItem and an objectMask
require 'softlayer_api' # Requires softlayer_api >= 3.2
require 'pp' # used to display results

# Create a client
client = SoftLayer::Client.new

# add your server id, can be found with the following script: https://softlayer.github.io/ruby/list_instances/
virtual_server_id = 12345678
item = client[:Virtual_Guest].object_mask("mask[billingItem[createDate,hoursUsed,hourlyRecurringFee,currentHourlyCharge]]").object_with_id(virtual_server_id).getObject
puts "Billing Item for Virtual Server:"
pp item['billingItem']

Example Output

Billing Item for Virtual Server:


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue