尝试以下操作:
<?php
# Example to order a Evault
# reference pages
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
#
# @license <http://sldn.softlayer.com/article/License>
# @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');
// Your SoftLayer API username and key.
// Generate an API key at the SoftLayer Customer Portal:
// https://manage.softlayer.com/Administrative/apiKeychain
$username = 'set me';
$key = 'set me';
// Create a SoftLayer API client object
$softLayer_product_order = SoftLayer_SoapClient::getClient('SoftLayer_Product_Order', null, $username, $key);
# Build a skeleton SoftLayer_Hardware object.
# The object contains the hardware ID of the
# Bare Metal server wich will contain the Evault
# If you want use a Virtual Server instead a
# Bare Metal server build a skeleton SoftLayer_Virtual_Guest object
$virtualGuests = new stdClass();
$virtualGuests->id = 4241550;
$orderVirtualGuest = array
(
$virtualGuests,
);
# The location for the Evault
$location = "DALLAS06";
$packageId = 0;
$quantity = 1;
// Build a skeleton SoftLayer_Product_Item_Price object.
// The object contains the price ID of the Evaul device
// you wish order.
$prices = array
(
1045,
);
// Convert our item list into an array of 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.
$orderPrices = array();
foreach ($prices as $priceId){
$price = new stdClass();
$price->id = $priceId;
$orderPrices[] = $price;
}
// Build a SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault object containing
// the order you wish to place.
$orderTemplate = new stdClass();
$orderTemplate->location = $location;
$orderTemplate->packageId = $packageId;
$orderTemplate->prices = $orderPrices;
$orderTemplate->quantity = $quantity;
$orderTemplate->virtualGuests = $orderVirtualGuest;
print_r($orderTemplate);
// Place the order.
try {
// 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
(
$orderTemplate,
SOAP_ENC_OBJECT,
'SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault',
'http://api.service.softlayer.com/soap/v3/'
);
// verifyOrder() will check your order for errors. Replace this with a call
// to placeOrder() when you're ready to order. Both calls return a receipt
// object that you can use for your records.
//
// Once your order is placed it'll go through SoftLayer's approval and
// provisioning process.
$receipt = $softLayer_product_order->verifyOrder($orderTemplate);
print_r($receipt);
} catch (Exception $e) {
echo 'Unable to place server order: ' . $e->getMessage();
}
此外,这是一个 REST 请求,用于获取 Evault 的有效商品价格:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/0/getItemPrices?objectMask=mask[id,categories,locationGroupId,item[id,keyName,description],pricingLocationGroup[locations[id, name, longName]]]&objectFilter={ "itemPrices": { "categories": { "categoryCode": { "operation": "evault" } } } }
方法:获取
编辑
这是硬件(金属条)的 Evault 订单示例。我将一些变量名称更改为以前的脚本(可能需要改进)。
<?php
require_once ('Softlayer/SoapClient.class.php');
$username = 'set me';
$key = 'set me';
// Create a SoftLayer API client object
$softLayer_product_order = SoftLayer_SoapClient::getClient('SoftLayer_Product_Order', null, $username, $key);
$hardware = new stdClass();
$hardware->id = 197445;
$orderHardware = array
(
$hardware,
);
# The location for the Evault
$location = "DALLAS06";
$packageId = 0;
$quantity = 1;
// Build a skeleton SoftLayer_Product_Item_Price object.
// The object contains the price ID of the Evault device
// you wish order.
$prices = array
(
1045,
);
$orderPrices = array();
foreach ($prices as $priceId){
$price = new stdClass();
$price->id = $priceId;
$orderPrices[] = $price;
}
// Build a SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault object containing
// the order you wish to place.
$orderTemplate = new stdClass();
$orderTemplate->location = $location;
$orderTemplate->packageId = $packageId;
$orderTemplate->prices = $orderPrices;
$orderTemplate->quantity = $quantity;
$orderTemplate->hardware = $orderHardware;
print_r($orderTemplate);
// Place the order.
try {
// 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
(
$orderTemplate,
SOAP_ENC_OBJECT,
'SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault',
'http://api.service.softlayer.com/soap/v3/'
);
// verifyOrder() will check your order for errors. Replace this with a call
// to placeOrder() when you're ready to order. Both calls return a receipt
// object that you can use for your records.
//
// Once your order is placed it'll go through SoftLayer's approval and
// provisioning process.
$receipt = $softLayer_product_order->verifyOrder($orderTemplate);
print_r($receipt);
} catch (Exception $e) {
echo 'Unable to place server order: ' . $e->getMessage();
}
为了澄清一些疑问,我们使用的订单模板是 verifyOrder/placeOrder 方法的通用模板。此模板用于订购不同种类的物品(虚拟访客、硬件、网络存储、执行升级等)。使用此模板时,我们并非完全可以随意更改格式;只是,我们可以限制我们将按特定顺序使用的值。当我们在示例中看到“virtualGuests”属性是一个数组时,可能会产生混淆;我们能够使用相同的模板同时订购多个虚拟客人的原因之一。但在我们的例子中,我们只需要配置一个虚拟访客来订购 Evault,但我们不需要更改模板。订单唯一需要识别什么样的订单是容器(在我们的例子中:
为了更好地理解模板的结构,下面是使用REST的相同顺序示例:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder.json
方法:POST
Json - 为 VSI 订购 Evault:
{
"parameters": [
{
"complexType": "SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault",
"quantity": 1,
"location": "DALLAS06",
"packageId": 0,
"prices": [
{
"id": 1045
}
],
"virtualGuests": [
{
"id": 11498369
}
]
}
]
}
Json - 为硬件订购 EVault:
{
"parameters": [
{
"complexType": "SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault",
"quantity": 1,
"location": "DALLAS06",
"packageId": 0,
"prices": [
{
"id": 1045
}
],
"hardware": [
{
"id": 487260
}
]
}
]
}