I'm using:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
to get a list of all network storages.
But, in http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage , I don't see a way to get the datacenter details to which the network storage belongs to.
But, 'slcli iscsi list' (for example) is showing 'datacenter' column.
How can I get the same via Ruby SoftLayer API?
You should use an object mask to get datacenter value
e.g.: mask[serviceResource[datacenter[name]]]
Also, you can try the following ruby script to get that kind of information
# 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. <[email protected]>
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
References: