1
votes

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.

2

2 Answers

3
votes

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

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
        }
      ]
    }
  ]
}
1
votes

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.