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.
"type": "application/vnd.abiquo.virtualmachinestate+json", |
mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ | 2637198
|
...
Here are some examples of virtualmachinestate objects and notes about changing VM states |
...
Power on
Code Block |
---|
{"state": "ON"} |
Pause
...
...
...
Expand |
---|
title | Click here to show or hide the request example |
---|
|
cURL: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 successful. httplocalhost:9000nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
22051080112119454/state' \
-k --verbose \
|
-H 'Accept: application/vnd.abiquo.acceptedrequest+json; version= |
42 -H 'Content-Type: application/vnd.abiquo.virtualmachinestate+json; version= |
42 @requestpayload.json '{"state": "OFF", "gracefulShutdown": true}' \
|
--verboseSuccess status : 202Request payload: Code Block | { |
---|
{
"taskId": "d62be542-f34c-4fed-b9f8-6443f2db4cc1",
" |
stateOFF10",
"type": "SHUTDOWN",
" |
links []
}Response payload: Code Block | { "19454",
"state": "FINISHED_SUCCESSFULLY",
" |
messagecreationTimestamp": 1596040226,
|
"You can keep track of the progress in the link", "timestamp": 1596040226,
"jobs": {
"links": [],
" |
linkshrefhttp://localhost:9009/api/cloud/virtualdatacenters/2205/virtualappliances/1080/virtualmachines/1121/tasks/1fd663d5-1e66-4443-b94c-f78d13c9e62f",d62be542-f34c-4fed-b9f8-6443f2db4cc1.2cd94a0c-179d-4506-a71d-fabaf29a4d43",
" |
relstatus"d62be542-f34c-4fed-b9f8-6443f2db4cc1",
|
}]
} |
The API will return a link where you can monitor the progress of this operation.
Example of failed graceful shutdown
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 not supported and failed.Ā
Expand |
---|
title | Click here to show or hide the request example |
---|
|
Code Block | {links[
{
"Shutdown task's shutdown on virtual machine with id 19454",
" |
relself href"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks/8812ddf4-a372-40af-81ee-5f5d1e53454c" "UNKNOWN",
"creationTimestamp": |
}{
"timestamp": 1596040226,
" |
rel"parent", "href":"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks" {acknowledge
38testingnardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
5520017638812ddf4a37240af81ee-5f5d1e53454c/action/ack"
"title":"cloudadmin",
"user",
"type":"application/vnd.abiquo.user+json",
38testingnardo40.bcn.abiquo.com:443/api |
/admin/enterprises/74/users/17"
/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/tasks"
|
title"ABQ_5e57c34d-5dcb-482b-be0f-a78931f4abd0",
rel":"virtualmachine
"type": "application/vnd.abiquo.virtualmachine+json", |
38testingnardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
552001763
],"taskId":"8812ddf4-a372-40af-81ee-5f5d1e53454c",userId"17",
type":"SHUTDOWN "ownerId":"1763",state"FINISHED_UNSUCCESSFULLY",
creationTimestamp:1458647896 "timestamp":1458647897,jobs{
"links":[
]"application/vnd.abiquo.user+json",
" |
collection[
{
"links":[ "https://nardo40.bcn.abiquo.com:443/api/admin/enterprises/336/users/10"
|
] id8812ddf4a37240af81ee-5f5d1e53454c.191e44d9-74fa-453a-b7e0-596237618fcf",
parentTaskId"8812ddf4-a372-40af-81ee-5f5d1e53454c",
"virtualmachine",
"type": |
"SHUTDOWN",
"application/vnd.abiquo.virtualmachine+json",
|
description"Shutdown task's shutdown on virtual machine with id 1763", "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454"
}
]
|
"FAILED",
rollbackState":"ROLLBACK_DONE",
"creationTimestamp":1458647896,
"timestamp":1458647897
}
]
}
} |
Reset a VM using the API
...
To reset a VM using the API, use a POST request to the reset action link |
...
expand. If you are using a test environment, you may wish to add the --insecure option. cURL: Code Block |
---|
curl -X POST http'https://localhost:9000nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22102486/virtualappliances/10852990/virtualmachines/112619454/action/reset' \
-k --verbose \
-H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=45.20' \
-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": "httphttps://localhost:9009nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22102486/virtualappliances/10852990/virtualmachines/112619454/tasks/1fd663d5edec6cf1-1e668874-4443451d-b94ca4c0-f78d13c9e62f57f4c24da371",
"rel": "status"
}
]
} |
|