Попробуйте следующее:
<?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. <[email protected]>
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" } } } }
Метод: GET
EDIT
Это пример Евы (для металлических изделий). Я изменил некоторые имена переменных на предыдущий скрипт (возможно, его нужно улучшить).
<?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 - Заказать EVault для VSI:
{
"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
}
]
}
]
}
Отличный образец с очень полезными комментариями! Спасибо. Я попробую это, как только я буду готов. – KHP
@KHP, Cool! ... дайте мне знать, если у вас есть какие-либо комментарии/вопросы :) – mcruz
Привет. Так что этот образец отлично работал. Мне просто пришлось сменить пару идентификационных номеров, и все это работает для виртуальных гостей. Я прочитал API-документ, и похоже, что вместо «$ orderTemplate-> virtualGuests» вместо «$ orderTemplate-> virtualGuests» я использую «$ orderTemplate-> hardware», который будет обрабатывать как голый металлический сервер, так и виртуальные серверы. Поэтому я обновил $ orderVirtualGuest, чтобы включить свойства «domain» и «hostname» вместе с «id», поскольку в документе говорится, что домен и имя хоста требуются. И использовал этот «$ orderTemplate-> hardware = $ orderVirtualGuest;» и он жалуется, что: «Заказы EVault должны быть привязаны к точно одному серверу». – KHP