Search code examples
cloudibm-cloud-infrastructure

API to get instance type of softlayer node


I am trying to write some scripts that could perform a switch statement depending on the type of instances the node is; VM or baremetal.

Is there a way to reliably tell what type of an instance the machine is from within the environment?

My first thinking was the existence of a bond0 interface, but this could potentially be problematic if someone orders a VM with a weird networking config. If there is an easy API call to check the instance type?


Solution

  • you could use this service:

    http://sldn.softlayer.com/reference/services/SoftLayer_Resource_Metadata

    This service is desing to identify the device. the service must run whithin the machine and you do not need specify your username or API key.

    So you can run the method to get the id of the machine e.g.

    curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET https://api.service.softlayer.com/rest/v3/SoftLayer_Resource_Metadata/getId
    

    Once you get the ID of the device you can see if this ID belongs to a bare metal server or VSI, for that you can use the getObject methods.

    http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/getObject http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getObject

    For example if your ID belongs to VSI and you call the SoftLayer_Hardware_Server::getObject method you will get an error like that ID does not exist, and when you call the SoftLayer_Virtual_Guest::getObject method you will able to get information about the machine.

    Also you could list all the bare metal and VSI servers in your account, an verify if your ID belongs to bare metal or VSI, you can use these methods:

    http://sldn.softlayer.com/reference/services/SoftLayer_Account/getVirtualGuests http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware

    Regards