是否有用于在 SoftLayer 中订购性能块存储的示例代码?
Are there any sample code for ordering a performance block storage in SoftLayer?
我有一个 PHP 代码,我曾经为 Endurance Block 存储调用 verifyOrder,它工作正常。我原以为只需更改价格 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);
要订购性能块存储,请使用包 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 被视为 "A standard price",API 将在内部为客户切换价格。但我们建议先执行 verifyOrder 以查看想要的订单是否可以(费用可能会有所不同)。
此外,您还可以查看:
http://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You
我有一个 PHP 代码,我曾经为 Endurance Block 存储调用 verifyOrder,它工作正常。我原以为只需更改价格 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);
要订购性能块存储,请使用包 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 被视为 "A standard price",API 将在内部为客户切换价格。但我们建议先执行 verifyOrder 以查看想要的订单是否可以(费用可能会有所不同)。 此外,您还可以查看: http://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You