Ruby SoftLayer API 调用 SoftLayer_Billing_Invoice::getItems returns 已小写的主机名值
Ruby SoftLayer API call SoftLayer_Billing_Invoice::getItems returns a hostName value that has been downcased
我正在 运行 安装一个程序来检索我最新的经常性发票,然后我想查看发票中的每个项目并获取主机名列表。这是它的简化形式:
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
这里是对应的 link 文档:
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 将 return 结果是它更改了主机名的大小写。
1) 有没有办法让我的 find_servers 调用不区分大小写?
或
2) 有没有办法从发票中获取 virtual_guest/hardware ID?因此,我可以潜在地使用 server_with_id,而不是将 find_server 与主机名参数一起使用。
谢谢!
方法 getItems returns SoftLayer_Billing_Invoice_Item 的数组,此对象具有 属性 billingItemId(参见 http://sldn.softlayer.com/reference/datatypes/SoftLayer_Billing_Invoice_Item),这是此发票项目的开票项目被生成。现在 billingItemId 必须与关联的 billingItemId 匹配,或者是您帐户中的服务器或 VSI。因此,您可以使用 billingItemId
找到您的服务器或 VSI
看看这段代码:
# To get the VSI
billingItemId = invoiceItem["billingItemId"]
account_service = softlayer_client.service_named("Account")
filter = SoftLayer::ObjectFilter.new {|f| f.accept("virtualGuests.billingItem.id").when_it is(billingItemId)}
# The method returns an array of VSIs, but because the filter the arrays should contain only one VSI
vsis = account_service.object_filter(filter).getVirtualGuests()
myVSI = vsi[0]
# To get the Server
billingItemId = invoiceItem["billingItemId"]
filter = SoftLayer::ObjectFilter.new {|f| f.accept("hardware.billingItem.id").when_it is(billingItemId)}
hardwares = account_service.object_filter(filter).getHardware()
myHardware = hardwares[0]
希望对你有帮助
我正在 运行 安装一个程序来检索我最新的经常性发票,然后我想查看发票中的每个项目并获取主机名列表。这是它的简化形式:
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
这里是对应的 link 文档: 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 将 return 结果是它更改了主机名的大小写。
1) 有没有办法让我的 find_servers 调用不区分大小写?
或
2) 有没有办法从发票中获取 virtual_guest/hardware ID?因此,我可以潜在地使用 server_with_id,而不是将 find_server 与主机名参数一起使用。
谢谢!
方法 getItems returns SoftLayer_Billing_Invoice_Item 的数组,此对象具有 属性 billingItemId(参见 http://sldn.softlayer.com/reference/datatypes/SoftLayer_Billing_Invoice_Item),这是此发票项目的开票项目被生成。现在 billingItemId 必须与关联的 billingItemId 匹配,或者是您帐户中的服务器或 VSI。因此,您可以使用 billingItemId
找到您的服务器或 VSI看看这段代码:
# To get the VSI
billingItemId = invoiceItem["billingItemId"]
account_service = softlayer_client.service_named("Account")
filter = SoftLayer::ObjectFilter.new {|f| f.accept("virtualGuests.billingItem.id").when_it is(billingItemId)}
# The method returns an array of VSIs, but because the filter the arrays should contain only one VSI
vsis = account_service.object_filter(filter).getVirtualGuests()
myVSI = vsi[0]
# To get the Server
billingItemId = invoiceItem["billingItemId"]
filter = SoftLayer::ObjectFilter.new {|f| f.accept("hardware.billingItem.id").when_it is(billingItemId)}
hardwares = account_service.object_filter(filter).getHardware()
myHardware = hardwares[0]
希望对你有帮助