0

我有一个 PHP 代码,我曾经调用 verifyOrder 来进行 Endurance Block 存储,它可以正常工作。我原以为只需更改价格 ID,它也适用于性能块存储。但这似乎没有那么简单。我从 SoftLayer 看到它使用以下价格 ID:40678、40688、40798 所以我将上面的价格 ID 列表以及包裹 ID 替换为 222。但我最终得到了这样的错误:

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.'

我不知道为什么。SoftLayer 中是否有任何用于验证性能块存储顺序的良好工作示例?

下面是我为 Endurance 存储所拥有的基本代码流。

$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);
4

1 回答 1

1

要订购性能块存储,请使用包 222。下面是一个示例:

<?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();
}

要为您的帐户获取有效的价格 ID:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/ 222/getItemPrices?objectMask=mask[id,item[keyName,description],pricingLocationGroup[locations[id, name, longName]]]

注意:locationGroupId = null 的价格 ID 被视为“标准价格”,API 将在内部为客户切换价格。但我们建议先执行 verifyOrder 以查看想要的订单是否正常(费用可能会有所不同)。此外,您可以查看: http ://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You

于 2015-11-19T20:14:29.577 回答