在 SoftLayer 中订购 EVault 备份的示例代码

Sample code for ordering an EVault backup in SoftLayer

是否有人拥有或可以提供用于在 SoftLayer 中订购 EVault 备份的示例代码?它看起来与您 select 要订购的商品的常规订购略有不同,然后选择一些选项然后进行 verifyOrder() 调用。 对于 EVault,我首先必须转到其中一个服务器设备,然后添加(有点像升级,但有所不同,因为它没有列为可升级项目)。

当我尝试查看 SoftLayer UI 调用的内容时,它会执行 POST 并将整串数据作为请求正文传递。我严重怀疑我是否需要收集所有这些并通过。

因此,如果有人已经知道这一点或有示例,您能否分享一个示例代码,用于订购或验证将 EVault 备份添加到设备的价格? PHP 代码示例是首选,但任何能向我展示流程逻辑和我需要提供的输入的东西都很棒。

提前致谢。

尝试以下操作:

<?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"       }     }   } }

方法:获取

编辑

这是硬件(金属条)的 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
        }
      ]
    }
  ]
}

与订单一样,您只需要使用http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault容器并指定要附加到Evault的virtualGuests或硬件。