1

We are using Softlayer APIs to check the status of the VMs we create. Below are the APIs we are using now, and we have to check the status for one VM at a time. Is there a Softlayer API that can retrieve the status of a list of VMs?

Here are the APIs we are calling to get the status of one VM each time: 1. Get the VM id api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/findByIpAddress/x.x.x.x 2. Get the VM status api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/vmID/getPowerState.json

2 Answers2

1

Well, there is no api method to get those values, but they are:

Power State:

  • Running
  • Halted
  • Paused
  • Suspended
  • Unknown

Status

  • Id: 1001 - Active
  • Id: 1002 - Disabled
  • Id: 1003 - Inactive
  • Id: 1004 - Deleted
  • Id: 1006 - Disconnected
0

To get the VM status from all your virtual servers:

https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[powerState]

Method: Get

Note: Replace $user and $apiKey with your own information


To get the VM status from a list:

https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[powerState]&objectFilter={"virtualGuests":{"id":{"operation":"in","options":[{"name":"data","value":[$vsiId1, $vsiId2, $vsiId3]}]}}}

Method: Get

Note: Replace $user, $apiKey, $vsiId1, $vsiId2, $vsiId3 with your own information, you can add more ids, separating by ","


Updated

cURL

If you are using curl, you should send the command encoded, because we are using filters in the request, so it should look like this:

curl "https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask%5BpowerState%5D&objectFilter=%7B%22virtualGuests%22%3A%7B%22id%22%3A%7B%22operation%22%3A%22in%22%2C%22options%22%3A%5B%7B%22name%22%3A%22data%22%2C%22value%22%3A%5B25129322%2C15535999%5D%7D%5D%7D%7D%7D"

Replace: $user, $apiKey, 25129322 and 15535999 with you own information

The VSI identifiers that I'm looking for are: 25129322 and 15535999, as you can see, they are encoded in the command

  • Hi, thanks for your reply. A few things to confirm: * For the first API call, does it return status for all the VMs that were created using the same Softlayer userid and apikey, or all the VMs that are in the same account? – Little Fish Oct 27 '16 at 04:13
  • * For the first API call, when I pass "objectMask=mask" it works, but when I add something after mask[attribute], the call failed. I tried to follow the format described in http://sldn.softlayer.com/article/Object-Masks, but it did not help. curl --user $user:$apikey -X GET -H "Accept: application/json" "https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[powerState]" curl: (3) [globbing] error: bad range specification after pos 86 * I have not got luck with the second API call yet, got errors. – Little Fish Oct 27 '16 at 04:13
  • The first request will retrieve all virtual servers from your account – Ruber Cuellar Valenzuela Oct 27 '16 at 13:11
  • For your second question, see the **Updated** section in my answer please – Ruber Cuellar Valenzuela Oct 27 '16 at 13:46
  • Thanks again for your reply. I thought by specifying objectMask=mask[powerState] would limit the attributes returned, but it is not the case for me. Can you please comment? – Little Fish Oct 27 '16 at 15:41
  • I also posted a question above regarding the powerState and status attributes, can you please comment? – Little Fish Oct 27 '16 at 15:42
  • You can limit or extend the response using ObjectMask, to get more information about this review: [Object Masks](http://sldn.softlayer.com/article/Object-Masks) – Ruber Cuellar Valenzuela Oct 27 '16 at 15:50