我正在运行一个程序来检索我最新的定期发票,然后我想查看发票中的每个项目并获取主机名列表。这是简化的形式:
account = SoftLayer::Service.new("SoftLayer_Account",:username => user, :api_key => api_key, :timeout => 999999999)
softlayer_client = SoftLayer::Client.new(:username => user, :api_key => api_key)
billing_invoice_service = softlayer_client.service_named("Billing_Invoice")
object_filter = SoftLayer::ObjectFilter.new
object_filter.set_criteria_for_key_path('invoices.createDate', 'operation' => 'betweenDate', 'options' => [{'name' => 'startDate', 'value' => ["01/01/2016"]}, {'name' => 'endDate', 'value' => ["01/02/2016"]}])
invoices = account.result_limit(0,10000).object_filter(object_filter).object_mask("mask[id,typeCode,itemCount,invoiceTotalAmount,closedDate,createDate]").getInvoices
invoices.each do | invoice |
if invoice["typeCode"] == "RECURRING"
invoice_reference = billing_invoice_service.object_with_id(invoice["id"])
invoice_object = invoice_reference.object_mask("mask[itemCount]").getObject
billing_items_count = invoice_object["itemCount"]
for i in 0..(billing_items_count/10000.0).ceil - 1
billing_items = invoice_reference.result_limit(i*10000, 10000).object_mask("mask[id,hostName]").getItems()
billing_items.each do | billing_item |
if billing_item["hostName"]
pp billing_item
end
end
end
end
end
这是文档的相应链接:http: //sldn.softlayer.com/reference/services/SoftLayer_Billing_Invoice/getItems
结果是主机名列表,但值已被小写。这阻止了我,因为我稍后会调用 find_servers 并从上面传递这个“hostName”值。由于大小写不匹配,因此无法找到服务器详细信息。我已经进行了如下测试以确认此行为:
softlayer_client = SoftLayer::Client.new(:username => user, :api_key => api_key)
found_downcased_version = SoftLayer::VirtualServer.find_servers({ :client => softlayer_client, :hostname => "host-hadr-1" })
if !found_downcased_version.empty?
pp "FOUND DOWNCASED VERSION OF HOSTNAME"
end
found_unchanged_case_version = SoftLayer::VirtualServer.find_servers({ :client => softlayer_client, :hostname => "host-HADR-1" })
if !found_unchanged_case_version.empty?
pp "FOUND UNCHANGED CASE VERSION OF HOSTNAME"
end
这似乎是一个问题,SoftLayer 将返回一个更改了主机名大小写的结果。
1)有没有办法让我的 find_servers 调用不区分大小写?
或者
2) 有没有办法从发票中获取 virtual_guest/hardware ID?因此,我可以使用 server_with_id 而不是使用带有主机名参数的 find_server 。
谢谢!