1

I am trying to create Virtual Server with WHM/cPanel on Softlayer,

Unfortunately, Softlayer API doesn't Support code Examples and any API Call will incur charges on my account.

And the service generateOrderTemplate will not validate but required parameters only.

What is the problem with the following code?

try {
        $client = \libraries\SoftLayer\SoapClient::getClient('SoftLayer_Virtual_Guest', null, $apiUsername, $apiKey);

    }   catch (Exception $e) {
        die('Unable to create service client: ' . $e->getMessage());
    }

    try {
        $virtualGuest = new \stdClass();
        $virtualGuest->datacenter->name = 'ams01';
        $virtualGuest->hostname = 'test';
        $virtualGuest->domain = 'myDomain.com';
        $virtualGuest->startCpus = 1;
        $virtualGuest->maxMemory = 1024;
        $virtualGuest->hourlyBillingFlag = false;
        $virtualGuest->localDiskFlag = true;
        $virtualGuest->operatingSystemReferenceCode = 'CENTOS_7_64';

        $virtualGuest->softwareComponents[0]->softwareDescription->id = 46;
        $virtualGuest->softwareComponents[0]->softwareDescription->controlPanel = 1;
        $virtualGuest->softwareComponents[0]->softwareDescription->virtualLicense = 1;
        $virtualGuest->softwareComponents[0]->softwareDescription->manufacturer = "cPanel";

        $virtualGuest->blockDevices[0]->device = 0;
        $virtualGuest->blockDevices[0]->diskImage->capacity = 25;

        $call = $client->generateOrderTemplate($virtualGuest);
        $call = $client->createObject($virtualGuest);
        print_r($call);

    } catch (Exception $e) {
        die('Unable to create Virtual Guest: ' . $e->getMessage());
    }

Thanks

1 Answers1

0

Unfortunately, it's not possible to set softwareComponents using SoftLayer_Virtual_Guest::createObject, this method provides a simplified way to order a vsi(So it only provides the most common options for it. In other words means that generateOrderTemplate will validate the same options than SoftLayer_Virtual_Guest::createObject method), to get all the options which work for this method, you need to use the following method:

If you wish to order a Control Panel Software for your VSI, you need to add the price of this item in the result of SoftLayer_Virtual_Guest::generateOrderTemplate

To find the priceId for Control Panel Software, you can make a call to SoftLayer_Product_Package::getItemPrices, I can provide a script that will help to find prices for that:

<?php
/**
 * Get item prices(Standard) for Control Panel Software from specific package
 *
 * @see http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
 * @see http://sldn.softlayer.com/article/object-filters
 * 
 * @license <http://sldn.softlayer.com/wiki/index.php/License>
 * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
 */
require_once '\vendor\autoload.php';

// Define you SoftLayer's username and apiKey
$apiUsername = 'set me';
$apiKey = 'set me';

// Define the package
$packageId = 46;

// Create a SoftLayer API client object to the "SoftLayer_Product_Package" service
$client = \SoftLayer\SoapClient::getClient('SoftLayer_Product_Package', $packageId, $apiUsername, $apiKey);

// Declare an object filter to get Standard - Control Panel Software item prices 
$filter = new stdClass();
$filter->itemPrices = new stdClass();
$filter->itemPrices->item = new stdClass();
$filter->itemPrices->item -> categories = new stdClass();
$filter->itemPrices->item -> categories -> name = new stdClass();
$filter->itemPrices->item -> categories -> name -> operation = 'Control Panel Software';
$filter->itemPrices -> locationGroupId = new stdClass();
$filter->itemPrices -> locationGroupId -> operation = "is null";
$client->setObjectFilter($filter);

try{
    foreach($client->getItemPrices() as $price){
        print_r("PriceId:  " . $price -> id . "    ItemId: ". $price -> itemId . "   Description:  " . $price -> item -> description ."\n");    
    }

} catch (Exception $e) {
    var_dump($e -> getMessage());
}

?>

I hope it helps, let me know if you need further assistance