Ibm cloud 从SL API获取iscsi设备的磁盘标识符

Ibm cloud 从SL API获取iscsi设备的磁盘标识符,ibm-cloud,ibm-cloud-infrastructure,iscsi,Ibm Cloud,Ibm Cloud Infrastructure,Iscsi,我正在尝试获取已使用SL API配置的iscsi磁盘的标识符。最好的方法是什么?我可以使用设备名称(从SL门户中看到)或wwn(600*)甚至iqn。我只需要一个方法来获取刚刚配置的磁盘的标识符 import pprint import SoftLayer api_username=<user name> api_key=<api key> client = SoftLayer.Client(username=api_username, api_key=api_key)

我正在尝试获取已使用SL API配置的iscsi磁盘的标识符。最好的方法是什么?我可以使用设备名称(从SL门户中看到)或wwn(600*)甚至iqn。我只需要一个方法来获取刚刚配置的磁盘的标识符

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

我将使用Python或Java。请尝试以下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)
“”“
检索块卷信息。
此脚本在
SoftLayer_帐户API服务,并使用对象掩码和过滤器获取更多信息
有关块卷的信息。
重要手册页
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
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
导入软层
从pprint导入pprint作为pp
"""
客户端配置
您的SoftLayer API用户名和密钥。
"""
用户名='SET-ME'
API_KEY='SET-ME'
#声明API客户端
client=SoftLayer.从_env(username=username)创建_client,
api_键=api_键)
accountService=客户端['SoftLayer\u Account']
#声明对象掩码以获取有关块存储卷的信息。
objectMask=“mask[id,activeTransactions.transactionGroup,nasType,密码,用户名,”\
“硬件[id,FullyQualifiedDomain]、iops、ProvisionideOps、isReadyForSnapshot、osType,”\
serviceResourceBackendIpAddress、capacityGb、snapshotCapacityGb、createDate、parentVolume.replicationStatus、\
parentVolume.volumeStatus,PermissionsGroup.allowedHosts,ReplicatingLUN,storageType,storageTierLevel\
serviceResource[id,type.type,networkDevice[id,数据中心]],notes,volumeStatus,hasEncryptionAtRest\
originalVolumeSize,allowedVirtualGuests[FullyQualifiedDomain,allowedHost[id,name,resourceTableId,”\
resourceTableName,凭据[id,用户名,密码],sourceSubnet]]
#使用以下掩码仅检索iScsi块卷的标识符。
#objectMaskIscsi=“掩码[id]”
#声明筛选器时,在此示例中,按iscsi名称搜索,就像门户:
筛选器_block_username={“iscsiNetworkStorage”:{“username”:{“operation”:“SL01SEL11111-2”}}
#取消注释以下内容之一,并替换所需值以使用其中一个筛选器进行搜索
#筛选器_block_iqn={“iscsiNetworkStorage”:{“allowedVirtualGuests”:{“allowedHost”:{“name”:
#{“操作”:“iqn.2005-05.com.softlayer:sl01su111111-v1234567”}
尝试:
#检索帐户的块卷。
storageResult=accountService.getIscsiNetworkStorage(mask=objectMask,filter=filter\u block\u username)
pp(存储结果)
除SoftLayer.SoftLayer外,错误为e:
打印(“无法检索存储卷%s%s.”%(e.faultCode,e.faultString))
出口(1)
有关更多信息,请参见以下内容:


以下是提供所配置磁盘的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
导入pprint
导入软层
api_用户名=
api_密钥=
client=SoftLayer.client(用户名=api\U用户名,api\U密钥=api\U密钥)
accountService=客户端[“软件层\用户帐户”]
storageId=
networkStorageService=客户端[“软层\网络\存储”]
结果=networkStorageService.getProperties(id=storageId)
记录结果:
对于属性,记录中的值。iteritems()
如果属性==“value”和value.isalnum()以及len(value)==24:
打印“+str(storageId)+”的“第83页ID”是“+value”

您能提供具体错误是什么吗?对我来说,它工作正常。我更新了脚本,在上一个版本上进行了测试,但在返回iscsi块卷的标识符时工作正常,但您可以使用新的掩码,响应将只抛出块卷iscsi存储的id属性。我可以生成输出,但这些字段中的哪一个是磁盘id?我正在寻找可以在目标VM上验证的page83 Id或wwn#之类的内容。您可以使用第二个掩码而不是第一个掩码,它将只获取块卷的Id。我不知道“page83 id”,请您添加更多关于它的详细信息,以及关于wwn的代表内容,因为我无法在门户UI中找到这两个内容,或者如果您可以使用屏幕截图进行更新,指出它们,我可以更好地理解它们,以便提供更好的答案并更新api脚本。