November 27, 2018

Working with Network Storage

A few examples on interacting with network storage. Ordring volumes and setting notes from that orderId
import SoftLayer
import time
from pprint import pprint as pp

class example():

    def __init__(self):
        self.client = SoftLayer.Client()
        debugger = SoftLayer.DebugTransport(self.client.transport)
        self.client.transport = debugger

    def main(self):
        block_manager = SoftLayer.BlockStorageManager(self.client)

        # This block will actually order storage, make sure to uncomment the other order block
        # order = block_manager.order_block_volume(
        #     storage_type="endurance",
        #     location='dal13',
        #     size=100,
        #     tier_level=float(4),
        #     os_type='LINUX',
        #     snapshot_size=None,
        #     service_offering='storage_as_a_service',
        #     hourly_billing_flag=True
        # )

        # Used to test setting a note without actually placing an order
        # This is the basic structure returned from an order
        order = {
            'orderDate': '2018-11-27T12:03:50-06:00',
            'orderId': 31323125,
            'placedOrder': {
                'id': 31323125,
                'items': [
                    {'categoryCode': 'storage_as_a_service',
                     'description': 'Storage as a Service'},
                    {'categoryCode': 'storage_block',
                     'description': 'Block Storage'},
                    {'categoryCode': 'performance_storage_space',
                     'description': '100 GBs'},
                    {'categoryCode': 'storage_tier_level',
                     'description': '4 IOPS per GB'}
        if 'placedOrder' in order:
            print("OrderID: #{0}".format(order['placedOrder']['id']))
            for item in order['placedOrder']['items']:
                print(" > {0}".format(item['description']))
            return order['placedOrder']['id']

    def getStorageFromOrder(self, orderId):
        """This will get all of the storage volumes that were ordered as part of orderId
        mask = "mask[id, capacityGb, username, notes]"
        _filter =  {
            'networkStorage': {
                'billingItem': {
                    'orderItem': {
                        'order': {
                            'id': {
                                'operation': orderId

        orders ='Account', 'getNetworkStorage', filter=_filter, mask=mask)
        return orders

    def setStorageNote(self, storageId, note):
        storage_object = {
            'notes': note
        result ='Network_Storage', 'editObject', storage_object, id=storageId)

    def getStorageObject(self, storageId):
        result ='Network_Storage', 'getObject', id=storageId)
        print("{0} -> {1}".format(result['username'], result['notes']))

    def debug(self):
        for call in self.client.transport.get_last_calls():

if __name__ == "__main__":
    main = example()
    orderId = main.main()
    print("Sleeping for 60s to wait for volume to be ready")
    volumes = main.getStorageFromOrder(orderId)
    for storage in volumes:
        main.setStorageNote(storage['id'], 'This is a test note')


Actual API calls

Resolves the DC shortname, dal13 to its locationId.

curl -u $SL_USER:$SL_APIKEY -X GET -H  ''

Gets the storage package information used in ordering

curl -u $SL_USER:$SL_APIKEY -X GET -H   ''

Orders the storage volume

curl -u $SL_USER:$SL_APIKEY -X POST -H -d '{"parameters": [{"complexType": "SoftLayer_Container_Product_Order_Network_Storage_AsAService", "packageId": 759, "prices": [{"id": 189433}, {"id": 189443}, {"id": 194763}, {"id": 194703}], "quantity": 1, "location":1854895, "useHourlyPricing": true, "volumeSize": 100, "osFormatType": {"keyName": "LINUX"}}]}' ''

Searches network storage volumes for one with a matching orderId. Will return a list of storage volumes. The number of volumes in this list should match how many you requested in the initial order.

curl -u $SL_USER:$SL_APIKEY -X GET -H  ''

Sets the notes for the the storage volume 123456789

curl -u $SL_USER:$SL_APIKEY -X POST -H "Accept: */*" -H "Accept-Encoding: gzip, deflate, compress" -d '{"parameters": [{"notes": "This is a test note"}]}' ''

Gets the object for storage volume 123456789

curl -u $SL_USER:$SL_APIKEY -X GET -H "Accept: */*" -H "Accept-Encoding: gzip, deflate, compress"  ''


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue