Search code examples
ibm-cloud-infrastructure

SoftLayer_Account::getBareMetalInstances() not working?


In SoftLayer, I can see I have 2 bare metal servers. One I requested to cancel, but other one is all good and there's no pending action and everything is all active. However when I invoke SoftLayer_Account::getBareMetalInstances(), it's returning an empty list. Why?

I have Virtual Guests as well and getVirtualGuests() returns what it's suppose to return. Is it a bug on getBareMetalInstances()? Or is there another API that I should be using to get my bare metal list? Can someone also try this and see if you get same result?

Below is bit of code that I am using for this:

$client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
$result = '{}';
if ($type == 'vg') {
   $result = $client->getVirtualGuests();
}
else if ($type == 'bm') {
   $result = $client->getBareMetalInstances();
}
ApsUtilsDebug::Debug(__METHOD__." type=".$type.". result=".json_encode($result));

Also I've manually tried invoking below using Poster:

GET https://api.softlayer.com/rest/v3/SoftLayer_Account/getBareMetalInstances.json
GET https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests.json

What I have is the hourly bare metal server. So I've also tried getHourlyBareMetalInstances() and still returns empty list.


Solution

  • The SoftLayer_Account::getBareMetalInstances method retrieves bare metals instances. This mean that the bare metals which have "bareMetalInstanceFlag" property as true, will be retrieved.

    You need to consider that "Bare Metal Instances" are different than "Bare Metal Servers".

    This kind of servers (Bare Metal Instances) are not orderable anymore. This method is available for some accounts which have this kind of servers yet.

    So, if you want to retrieve your bare metal servers, the following method will help for this: SoftLayer_Account::getHardware

    If you want to retrieve your bare metal servers hourly, try the following code:

    <?php
    /**
     * Get Hourly Bare Metal Servers
     *
     * Important manual pages:
     * @see http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
     * @see http://sldn.softlayer.com/article/Object-Filters
     * @see http://sldn.softlayer.com/article/Object-Masks
     *
     * @license <http://sldn.softlayer.com/wiki/index.php/license>
     * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
     */
    require_once '\vendor\autoload.php';
    
    /**
     * Your SoftLayer API username
     * @var string
     */
    $username = "set me";
    
    /**
     * Your SoftLayer API key
     * Generate one at: https://control.softlayer.com/account/users
     * @var string
     */
    $apiKey = "set me";
    
    // Create a SoftLayer API client object to the "SoftLayer_Security_Ssh_Key" service
    $client = \SoftLayer\SoapClient::getClient('SoftLayer_Account', null, $username, $apiKey);
    
    // Declare an object mask, to get hourlyBillingFlag property
    $objectMask = "mask[hourlyBillingFlag]";
    $client->setObjectMask($objectMask);
    
    try {
        $hourlyBareMetals = $client -> getHardware();
        foreach($hourlyBareMetals as $server)
        {
            if($server -> hourlyBillingFlag == 1)
            {
                print_r($server);
            }
        }
    
    } catch(Exception $e) {
        echo "Unable to get hourly bare metal servers: " . $e -> getMessage();
    }
    

    Note: The servers which have "hourlyBillingFlag" property as true (1), refers to hourly bare metals servers.