0
votes

I am trying to obtain an identifier for a iscsi disk I have provisioned using SL API. What is the best approach to do this? I can use the device name (as seen from the SL Portal) or wwn (600*) or even iqn. I just need a method to get this identifier for the just provisioned disk.

I will use either Python or Java.

2

2 Answers

0
votes

Try the following python script:

"""
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. <[email protected]>
"""
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)

For more information please see below:

http://sldn.softlayer.com/reference/services/SoftLayer_Account/getIscsiNetworkStorage

http://developer.softlayer.com/article/object-filters

0
votes

Here is the code that provides a partial value of the wwn or page83 id of the provisioned disk.

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