问题
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
回答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
回答2:
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
来源:https://stackoverflow.com/questions/40272343/batch-checking-the-vm-status-with-softlayer-api