I have a PHP code that I used to call verifyOrder for an Endurance Block storage and it works fine for it. I would have thought it would work for Performance Block storage as well by just changing the price IDs. But it doesn't seem to be that simple. I see from SoftLayer that it's using following price IDs: 40678, 40688, 40798 So I replaced the price ID list with above along with package ID to 222. But I end up getting an error like this:
PHP Fatal error: Uncaught exception 'Exception' with message 'There was an error querying the SoftLayer API: Invalid pr
ice Block Storage (Performance) (40678) provided on the order container.'
And I have no idea why. Are there any good working sample of verifying order for a Performance Block storage order in SoftLayer?
Below is the basic flow of code that I have for Endurance storage.
$priceIds = array (
45064,
45104,
45074,
45124,
46156
);
$orderPrices = array();
foreach ($priceIds as $priceId){
$price = new stdClass();
$price->id = $priceId;
$orderPrices[] = $price;
}
$osFormatType = new stdClass();
$osFormatType->id = 12;
$osFormatType->keyName = 'LINUX';
$orderTemplate = new stdClass();
$orderTemplate->location = $location;
$orderTemplate->packageId = $packageId;
$orderTemplate->osFormatType = $osFormatType;
$orderTemplate->complexType = 'SoftLayer_Container_Product_Order_Network_Storage_Enterprise';
$orderTemplate->prices = $orderPrices;
$orderTemplate->quantity = 1;
$productOrderClient = SoftLayer_SoapClient::getClient
(
'SoftLayer_Product_Order',
null,
$apiUsername,
$apiKey
);
$my_template = new SoapVar($orderTemplate, SOAP_ENC_OBJECT, 'SoftLayer_Container_Product_Order_Network_Storage_Enterprise', 'http://api.service.softlayer.com/soap/v3/');
$result = $productOrderClient->verifyOrder($my_template);
To order a Performance Block Storage, use package 222. Below is an example:
<?php
require_once dirname(__FILE__) . "/SoftLayer/SoapClient.class.php";
$username = "set me";
$apiKey = "set me";
$location = 449506; // Frankfurt 2
$packageId = 222; // The packageID for order Performance
$quantity = 1;
// Create a SoftLayer API client object for "SoftLayer_Product_Order" service
$client = SoftLayer_SoapClient::getClient('SoftLayer_Product_Order', null, $username, $apiKey);
/**
* Build a skeleton SoftLayer_Product_Item_Price objects. These objects contain
* much more than ids, but SoftLayer's ordering system only needs the price's id
* to know what you want to order.
* To get the list of valid prices for the package
* use the SoftLayer_Product_Package:getItemPrices method
*/
$prices = array(
40672, // Block Storage (Performance)
62875, // 500 GB Storage Space
61509 // 500 IOPS
);
$orderPrices = array();
foreach ($prices as $priceId) {
$price = new stdClass();
$price -> id = $priceId;
$orderPrices[] = $price;
}
$osFormatType = new stdClass();
$osFormatType -> id = 12;
$osFormatType -> keyName = "LINUX";
// Build a SoftLayer_Container_Product_Order_Network_Storage_Enterprise object containing
// the order you want to place.
$orderContainer = new stdClass();
$orderContainer -> location = $location;
$orderContainer -> packageId = $packageId;
$orderContainer -> prices = $orderPrices;
$orderContainer -> quantity = $quantity;
$orderContainer -> osFormatType = $osFormatType;
// Re-declare the order template as a SOAP variable, so the SoftLayer ordering system knows what type of order you're placing.
$orderTemplate = new SoapVar($orderContainer, SOAP_ENC_OBJECT, 'SoftLayer_Container_Product_Order_Network_PerformanceStorage_Iscsi', 'http://api.service.softlayer.com/soap/v3/');
try {
/**
* We will use verifyOrder() method to check for errors. Replace this with placeOrder() when you are ready to order.
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
*/
$result = $client -> verifyOrder($orderTemplate);
print_r($result);
} catch(Exception $e) {
echo "Unable to order Consistent Performance Block Storage" . $e -> getMessage();
}
To get valid price ids for your account:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/ 222/getItemPrices?objectMask=mask[id,item[keyName,description],pricingLocationGroup[locations[id, name, longName]]]
Note: A price id with a locationGroupId = null is considered "A standard price" and the API will internally switch the prices for the customer. But we recommend to execute first the verifyOrder in order to see if the wanted order is ok (the fee can vary). Also, you can review: http://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You