Excerpt |
---|
name | VM power actions using the API |
---|
|
To perform a power action (except for reset) on a VM using the API: Perform a GET request to obtain the VM object and find the VM state link Create a virtualmachinestate object Send a PUT request to the VM state link
The VM state link is a link in the VM object with the "rel" attribute set to state. The "title" attribute contains the current state. You can send a PUT request of a virtualmachine state object to the link (in the "href" attribute) to change the power state of the VM. hrefhttps://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/6/statetypeapplication/vnd.abiquo.virtualmachinestate+jsonrelstateapplication/vnd.abiquo.virtualmachinestate+json",
" | titleONhttps://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/state"
}, |
|
...
Here are some examples of virtualmachinestate objects and notes about changing VM states Hard power off Code Block |
---|
{"state": "OFF"} |
|
Graceful shutdown
Code Block |
---|
{"state": "OFF", "gracefulShutdown": true} |
Power on
Code Block |
---|
{"state": "ON"} |
Pause
Code Block |
---|
{"state": "PAUSED"} |
Azure power off and deallocate
Azure has two power off states - powered off and deallocated.
- To power off a VM in Azure via the Abiquo API, use the graceful shutdown
- To deallocate a VM in Azure via the Abiquo API, use the hard power off
- The deallocated VM will have a "deallocated" attribute that is set to "true".
Example of VM hard power off via API
...
...
...
Graceful shutdown Code Block |
---|
{"state": "OFF", "gracefulShutdown": true} |
To perform a graceful shutdown, your VM will need to have guest extensions installed on it. After an operation completes, you can view the status of the task by going to the link in the accepted request link of the response. In this case, the graceful shutdown was
|
...
...
Code Block | {
"links":[
{
"rel":"self",
"href":"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks/8812ddf4-a372-40af-81ee-5f5d1e53454c"
},
{
"rel":"parent",
"href":"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks"
}, |
Expand |
---|
title | Click here to show or hide the request example |
---|
|
Code Block |
---|
curl -X PUT 'https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/state' \
-k --verbose \
-H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=5.0' \
-H 'Content-Type: application/vnd.abiquo.virtualmachinestate+json; version=5.0' \
-d '{"state": "OFF", "gracefulShutdown": true}' \
-u user:password | jq . |
Code Block |
---|
{
"taskId": "d62be542-f34c-4fed-b9f8-6443f2db4cc1",
"userId": "10",
"type": "SHUTDOWN",
"ownerId": "19454",
"state": "FINISHED_SUCCESSFULLY",
"creationTimestamp": 1596040226,
"timestamp": 1596040226,
"jobs": {
"links": [],
"collection": [
{
|
rel"acknowledge "d62be542-f34c-4fed-b9f8-6443f2db4cc1.2cd94a0c-179d-4506-a71d-fabaf29a4d43",
|
href"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks/8812ddf4-a372-40af-81ee-5f5d1e53454c/action/ack" "d62be542-f34c-4fed-b9f8-6443f2db4cc1",
|
}{ "description": "Shutdown task's shutdown on virtual machine with id |
"title":"cloudadmin" reluser
type"application/vnd.abiquo.user+json href":"https://38testing.bcn.abiquo.com:443/api/admin/enterprises/74/users/17"creationTimestamp": 1596040226,
"timestamp": |
}{ "title":"ABQ_5e57c34d-5dcb-482b-be0f-a78931f4abd0",rel"virtualmachine",type"application/vnd.abiquo.virtualmachine+json
38testingnardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
55200/1763/19454/tasks/d62be542-f34c-4fed-b9f8-6443f2db4cc1"
|
],"taskId":"8812ddf4-a372-40af-81ee-5f5d1e53454c",userId17"type":"SHUTDOWN", ownerId"1763", "state":"FINISHED_UNSUCCESSFULLY","https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/tasks"
|
"creationTimestamp":1458647896"timestamp":1458647897,
"jobs":links[
]collection[
{ "application/vnd.abiquo.virtualmachine+json",
|
"links[
"https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454"
|
] id"8812ddf4-a372-40af-81ee-5f5d1e53454c.191e44d9-74fa-453a-b7e0-596237618fcf",
parentTaskId"8812ddf4-a372-40af-81ee-5f5d1e53454c",
"SHUTDOWN "application/vnd.abiquo.user+json",
|
"description":"Shutdown task's shutdown on virtual machine with id 1763""href": "https://nardo40.bcn.abiquo.com:443/api/admin/enterprises/336/users/10"
},
|
state"FAILED",
"ABQ_2fb11009-8157-4d61-915d-40fa45f440ac",
|
rollbackStateROLLBACK_DONE "creationTimestamp":1458647896"type": "application/vnd.abiquo.virtualmachine+json",
|
"timestamp1458647897
"https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454"
|
}
} |
...
To reset a VM using the API, use a POST request to the reset action link. If you are using a test environment, you may wish to add the --insecure option. |
...
expandcURL: Code Block |
---|
curl -X POST http'https://mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22486/virtualappliances/12990/virtualmachines/4719454/action/reset' \
-k --verbose \
-H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=5.0' \
-u user:password --verbose | jq . |
Success status code: 202 Request payload: --none-- Response payload: Code Block |
---|
{
"message": "You can keep track of the progress in the link",
"links": [
{
"title": "status",
"rel": "status",
"type": "application/vnd.abiquo.task+json",
"href": "https://mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22486/virtualappliances/12990/virtualmachines/4719454/tasks/af40013cedec6cf1-ed148874-4872451d-8906a4c0-0dc698df46c857f4c24da371"
}
]
} |
|