如何使用 SoftLayer Ruby API 获取网络存储属于哪个数据中心?
How to get to which datacenter a network storage belongs to using SoftLayer Ruby API?
我正在使用:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
获取所有网络存储的列表。
但是,在 http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage 中,我没有找到获取网络存储所属数据中心详细信息的方法。
但是,'slcli iscsi list'(例如)显示的是 'datacenter' 列。
如何通过 Ruby SoftLayer API 获得相同的内容?
您应该使用对象掩码来获取数据中心值
e.g.:
mask[serviceResource[datacenter[name]]]
此外,您可以尝试以下 ruby 脚本来获取此类信息
# Get Network Storage
#
# This script retrieves an account's associated storage volumes.
#
# Important manual pages
# http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
#
# @License: http://sldn.softlayer.com/article/License
# @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
require 'rubygems'
require 'softlayer_api'
require 'pp'
# Declare your SoftLayer username and apiKey
SL_API_USERNAME = 'set me'
SL_API_KEY = 'set me'
# Create the client
client = SoftLayer::Client.new(username: SL_API_USERNAME, api_key: SL_API_KEY)
# Define an object mask to get datacenter name
object_mask = 'mask[serviceResource[datacenter[name]]]'
begin
storages = client['SoftLayer_Account'].object_mask(object_mask).getNetworkStorage
print "+------------+---------------------------+------------+-----------------------+\n"
print "| ID | Datacenter | Size | Username |\n"
print "+------------+---------------------------+------------+-----------------------+\n"
storages.each do |storage|
printf('| %-10s ', storage['id'])
if storage['serviceResource'].has_key?('datacenter')
datacenter = storage['serviceResource']['datacenter']['name']
else
datacenter = 'None'
end
printf('| %-25s ', datacenter)
printf('| %-10s ', storage['capacityGb'])
printf("| %-21s | \n", storage['username'])
end
rescue StandardError => exception
puts "Error. : #{exception}"
end
参考文献:
我正在使用:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
获取所有网络存储的列表。
但是,在 http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage 中,我没有找到获取网络存储所属数据中心详细信息的方法。
但是,'slcli iscsi list'(例如)显示的是 'datacenter' 列。
如何通过 Ruby SoftLayer API 获得相同的内容?
您应该使用对象掩码来获取数据中心值
e.g.: mask[serviceResource[datacenter[name]]]
此外,您可以尝试以下 ruby 脚本来获取此类信息
# Get Network Storage
#
# This script retrieves an account's associated storage volumes.
#
# Important manual pages
# http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
#
# @License: http://sldn.softlayer.com/article/License
# @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
require 'rubygems'
require 'softlayer_api'
require 'pp'
# Declare your SoftLayer username and apiKey
SL_API_USERNAME = 'set me'
SL_API_KEY = 'set me'
# Create the client
client = SoftLayer::Client.new(username: SL_API_USERNAME, api_key: SL_API_KEY)
# Define an object mask to get datacenter name
object_mask = 'mask[serviceResource[datacenter[name]]]'
begin
storages = client['SoftLayer_Account'].object_mask(object_mask).getNetworkStorage
print "+------------+---------------------------+------------+-----------------------+\n"
print "| ID | Datacenter | Size | Username |\n"
print "+------------+---------------------------+------------+-----------------------+\n"
storages.each do |storage|
printf('| %-10s ', storage['id'])
if storage['serviceResource'].has_key?('datacenter')
datacenter = storage['serviceResource']['datacenter']['name']
else
datacenter = 'None'
end
printf('| %-25s ', datacenter)
printf('| %-10s ', storage['capacityGb'])
printf("| %-21s | \n", storage['username'])
end
rescue StandardError => exception
puts "Error. : #{exception}"
end
参考文献: