有没有人或者可以提供用于在SoftLayer中订购EVault备份的示例代码?它看起来与您选择要订购的项目的常规订单略有不同,然后选择一些选项然后进行verifyOrder()调用。 对于EVault,我首先必须转到其中一个服务器设备然后添加(有点像升级,但不同,因为它没有列为可升级项目。)
当我尝试查看SoftLayer UI调用的内容时,它会执行POST并将整组数据作为请求正文传递。我非常怀疑我需要收集所有这些并通过。
因此,如果有人已经知道这个或有样本,请您分享一个示例代码,该代码将订购或验证将EVault备份添加到设备的价格? PHP代码示例是首选,但任何能够向我显示流程逻辑和我需要提供的输入的内容都会很棒。
提前谢谢。
答案 0 :(得分:3)
尝试以下方法:
<?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();
}
此外,这是获取Evault有效商品价格的REST请求:
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" } } } }
方法:GET
修改强>
这是硬件(金属条)的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,但我们不需要更改模板。订单唯一需要识别哪种订单是容器(在我们的例子中:“SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault”),使用此属性,订单可以验证值是否符合订单类型。
为了更好地理解模板的结构,下面是使用 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
}
]
}
]
}
答案 1 :(得分:1)
它与订单相同,您只需使用http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault容器并指定virtualGuests或您希望附加到Evault的硬件。