Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获得softlayer存储credendials?_Python_Storage_Credentials_Ibm Cloud Infrastructure - Fatal编程技术网

Python 如何获得softlayer存储credendials?

Python 如何获得softlayer存储credendials?,python,storage,credentials,ibm-cloud-infrastructure,Python,Storage,Credentials,Ibm Cloud Infrastructure,我正在尝试获取授权Softlayer网络存储的用户名、密码和主机IQN。 我使用了这个python脚本,但是shell返回[] import SoftLayer API_USERNAME = 'xxx' API_KEY = 'yyyy' storageId = zzzz client = SoftLayer.Client( username=API_USERNAME, api_key=API_KEY ) cli

我正在尝试获取授权Softlayer网络存储的用户名、密码和主机IQN。 我使用了这个python脚本,但是shell返回[]

    import SoftLayer
    API_USERNAME = 'xxx'
    API_KEY = 'yyyy'
    storageId = zzzz
    client = SoftLayer.Client(
       username=API_USERNAME,
       api_key=API_KEY
     )
    client['SoftLayer_Network_Storage'].getCredentials(id=storageId)
我的代码出了什么问题? 关于

试试这个:

"""
Get all the authorized hosts for a iSCSI.

Important manual pages:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/getObject

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

USERNAME = 'set me'
API_KEY = 'set me'

iscsiId = 6548079

# Declares the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
networkStorageService = client['SoftLayer_Network_Storage']

objectMask = "mask[id,username,allowedVirtualGuests[fullyQualifiedDomainName,allowedHost[name,credential[username,password]]],allowedHardware[fullyQualifiedDomainName,allowedHost[name,credential[username,password]]]]"

try:
    response = networkStorageService.getObject(id=iscsiId, mask=objectMask)
    print(response)
except SoftLayer.SoftLayerAPIError as e:
    # If there was an error returned from the SoftLayer API then bomb out with the
    # error message.
    print("Unable to retrieve the network storage. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
“”“
获取iSCSI的所有授权主机。
重要手册页:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/getObject
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
导入软层
用户名='设置我'
API_KEY='设置我'
ISCSID=6548079
#声明API客户端
client=SoftLayer.client(用户名=用户名,api\U密钥=api\U密钥)
networkStorageService=客户端['SoftLayer\u Network\u Storage']
objectMask=“mask[id,用户名,allowedVirtualGuests[FullyQualifiedDomain,allowedHost[name,credential[username,password]],allowedHardware[FullyQualifiedDomain,allowedHost[name,credential[username,password]]”
尝试:
response=networkStorageService.getObject(id=iscsiId,mask=objectMask)
打印(答复)
除SoftLayer.SoftLayer外,错误为e:
#如果SoftLayer API返回错误,则使用
#错误消息。
打印(“无法检索网络存储。faultCode=%s,faultString=%s”%(e.faultCode,e.faultString))

您可以使用一些掩码使用“SoftLayer\u Network\u Storage::getObject”来获取更多信息。 下面的示例向您展示了授权主机(裸机服务器、虚拟服务器、IP地址)的“用户名””、“密码””、“主机IQN

Python示例:

# So we can talk to the SoftLayer API:
import SoftLayer

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'

# Set the network storage id in order to  get the associated authorized hosts:
iscsiId = 6550721

mask = 'mask[id,username,allowedVirtualGuests[fullyQualifiedDomainName,allowedHost[name,credential[username,password]]],allowedHardware[fullyQualifiedDomainName,allowedHost[name,credential[username,password]]],allowedIpAddresses[ipAddress,allowedHost[name,credential[username,password]]]]'

# Set up your API client
client = SoftLayer.Client(
    username=API_USERNAME,
    api_key=API_KEY
)

try:
    # The expected result after executing the script is: true
    result = client['SoftLayer_Network_Storage'].getObject(mask=mask,id=iscsiId)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to get authorized hosts information faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))
参考资料: