1

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).

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.

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.

Thank you in advance.

KHP
  • 379
  • 1
  • 2
  • 10

2 Answers2

3

Try the following:

<?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();
}

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

Method: GET

EDIT

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();
}

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.

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

Method: POST

Json - Order Evault for 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 - Order 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
        }
      ]
    }
  ]
}
mcruz
  • 1,534
  • 2
  • 11
  • 14
  • Great sample with very helpful comments! Thank you. I will try this as soon as I am ready. – KHP Dec 16 '15 at 19:48
  • @KHP, Cool! ... let me know if you have any comments/questions :) – mcruz Dec 16 '15 at 22:26
  • Hi. So this sample worked great. I just had to change couple of the ID parts and it all works for Virtual Guests. I read the API doc and it looks like if I use the "$orderTemplate->hardware" instead of your "$orderTemplate->virtualGuests" then that would handle both bare metal server and virtual servers. So I updated the $orderVirtualGuest to include "domain" and "hostname" properties along with the "id" as the doc says domain and hostname are required. And used this "$orderTemplate->hardware = $orderVirtualGuest;" and it's complaining that: "EVault orders must be tied to exactly 1 server." – KHP Dec 17 '15 at 21:05
  • Since $orderVirtualGuest is defined as an Array, I thought maybe I try just using $virtualGuests since that's just a StdClass. So the code change would be like this: "$orderTemplate->hardware = $virtualGuests;" And it still complains that "EVault orders must be tied to exactly 1 server." I don't see anywhere I am specifying more than 1 server. Any thoughts on this? And I do really appreciate your help. And sorry that I can't format this properly in the comment section so it may be hard to read the actual code part... – KHP Dec 17 '15 at 21:11
  • @KHP, please see my "EDIT". I added more explanation and some examples. I hope this can help you :) – mcruz Dec 17 '15 at 23:10
  • Thanks for the additional information. So based on your example, it seems I have to use "hardware" for Bare Matal and "virtualGuests" for Virtual Servers. (i.e. I can't use "hardware" for both Bare Metal and Virtual Server orders). I guess that's where my issue was though the API doc seems to say I can use "hardware" to order both cases... Thanks again! – KHP Dec 18 '15 at 14:33
1

It is the same as an order, you just need to use the http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Storage_Backup_Evault_Vault container and specify the virtualGuests or the hardware that you wish to attach to the Evault.