在SoftLayer中订购EVault备份的示例代码 [英] Sample code for ordering an EVault backup in SoftLayer

查看:42
本文介绍了在SoftLayer中订购EVault备份的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Does anyone have or can provide a sample code for ordering an EVault backup in SoftLayer? It looks little different from regular ordering where you select the item to order, then pick some options then make a verifyOrder() call. For EVault, I first have to go to one of the server devices then add (kind of like an upgrade, but different because it's not listed as upgradable item).

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

When I try to see what SoftLayer UI calls, it does a POST and passes whole bunch of data as request body. I seriously doubt I need to gather all that and pass.

因此,如果有人已经知道或有示例,您是否可以共享示例代码来订购或验证向设备添加EVault备份的价格?最好使用PHP代码示例,但是任何可以向我展示过程逻辑和需要提供的输入的东西,都很棒.

So if someone already knows this or have sample, could you please share a sample code that will order or verify the price for adding EVault backup to a device? A PHP code sample is preferred, but anything that will show me the process logic and the input that I need to provide, that will be great.

谢谢.

推荐答案

尝试以下操作:

<?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的有效商品价格:

Additionally, this is a REST request to get valid item prices for 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

编辑

这是硬件(金属条)的Evault订单的示例.我将一些变量名更改为以前的脚本(可能需要改进).

This is an example of an Evault order for Hardware (Bar metal). I changed some variable names to the previous script (maybe it needs to be improved).

<?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"),使用此属性,订单可以验证值是否符合订单的类型.

To clarify some doubts, the order template that we are using is a generic template for verifyOrder/placeOrder method. This template is used to order different kind of items (Virtual Guests, Hardware, network storage, execute upgrades, etc.). When using this template, we are not entirely free to change the format; only, we can restrict the values that we will use in a specific order. Maybe there is confusion when we see that "virtualGuests"property is an array in our example; one reason we are able to order multiple Virtual guests at the same time with the same template. But in our case we need to configure only one Virtual Guest to order Evault, but we don’t need to change the template. The only thing that the order needs to identity what kind of order is the container (in our case: "SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault"), using this property, the order can verify if the values are according to the type of order.

为了更好地了解模板的结构,下面有使用 REST 的相同订单示例:

For better understanding of the structure of template, Below there are the same order examples using 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 for Hardware:

{
  "parameters": [
    {
      "complexType": "SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault",
      "quantity": 1,
      "location": "DALLAS06",
      "packageId": 0,
      "prices": [
        {
          "id": 1045
        }
      ],
      "hardware": [
        {
          "id": 487260
        }
      ]
    }
  ]
}

这篇关于在SoftLayer中订购EVault备份的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆