我正在尝试获取我使用SL API设置的iscsi磁盘的标识符。最好的方法是什么?我可以使用设备名称(从SL Portal中看到)或wwn(600 *)甚至iqn。我只需要一种方法来获取刚刚配置的磁盘的标识符。
我将使用Python或Java。
答案 0 :(得分:0)
尝试以下python脚本:
"""
Retrieve block volume information.
This script makes a single call to the getIscsiNetworkStorage() method in the
SoftLayer_Account API service and uses a object mask and filters to get more
information about the block volume.
Important manual pages
http://sldn.softlayer.com/reference/services/SoftLayer_Account
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getIscsiNetworkStorage
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
from pprint import pprint as pp
"""
Client configuration
Your SoftLayer API username and key.
"""
USERNAME = 'SET-ME'
API_KEY = 'SET-ME'
# Declare the API client
client = SoftLayer.create_client_from_env(username=USERNAME,
api_key=API_KEY)
accountService = client['SoftLayer_Account']
# Declaring the object mask to get information about the block storage volumes.
objectMask = "mask[id,activeTransactions.transactionGroup,nasType,password,username," \
"hardware[id,fullyQualifiedDomainName],iops,provisionedIops,isReadyForSnapshot,osType," \
"serviceResourceBackendIpAddress,capacityGb,snapshotCapacityGb,createDate,parentVolume.replicationStatus," \
"parentVolume.volumeStatus,permissionsGroups.allowedHosts,replicatingLuns,storageType,storageTierLevel," \
"serviceResource[id,type.type,networkDevice[id,datacenter]],notes,volumeStatus,hasEncryptionAtRest," \
"originalVolumeSize,allowedVirtualGuests[fullyQualifiedDomainName,allowedHost[id,name,resourceTableId," \
"resourceTableName, credential[id,username,password],sourceSubnet]]]"
#Use the following mask to retrieve only the identifier for a iScsi block volume.
# objectMaskIscsi= "mask[id]"
# Declaring a filter, in this example the search is by iscsi name just as portal:
filter_block_username = {"iscsiNetworkStorage": {"username": {"operation": "SL01SEL111111-2"}}}
# Uncomment one of the below, and replace required values to use one of the filters in order to search
# filter_block_iqn = {"iscsiNetworkStorage":{"allowedVirtualGuests":{"allowedHost":{"name":
# {"operation":"iqn.2005-05.com.softlayer:sl01su111111-v1234567"}}}}}
try:
# Retrieve the block volumes for the account.
storageResult = accountService.getIscsiNetworkStorage(mask=objectMask, filter=filter_block_username)
pp(storageResult)
except SoftLayer.SoftLayerAPIError as e:
print("Unable to retrieve the storage volumes %s %s. " % (e.faultCode, e.faultString))
exit(1)
有关更多信息,请参见以下内容:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getIscsiNetworkStorage
答案 1 :(得分:0)
这里是提供已配置磁盘的wwn或page83 id的部分值的代码。
import pprint
import SoftLayer
api_username=<user name>
api_key=<api key>
client = SoftLayer.Client(username=api_username, api_key=api_key)
accountService = client["SoftLayer_Account"]
storageId = <storage id>
networkStorageService = client["SoftLayer_Network_Storage"]
result = networkStorageService.getProperties(id=storageId)
for record in result:
for attribute,value in record.iteritems():
if attribute == "value" and value.isalnum() and len(value) == 24:
print "Page 83 ID for " + str(storageId) + " is " + value