简体   繁体   中英

How get the softlayer storage credendials?

I'm trying to get the Username,password and host IQN of a authorized Softlayer Network Storage. I used this python script, but the shell returns []

    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)

What's wrong in my code? Regards

try this:

"""
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))

You can use “SoftLayer_Network_Storage::getObject” using some mask to get more information. Below is an example that show you: “ Username ”, “ Password ”, “ Host IQN ” for authorized hosts ( Bare Metal Server, Virtual Server, IP Address ).

Python example:

# 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))

References:

http://developer.softlayer.com/article/Object-Masks http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/getObject https://softlayer.github.io/python/list_packages/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM