Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt
nameVM power actions using the API

To perform a power action (except for reset) on a VM using the API:

  1. Perform a GET request to obtain the VM object and find the VM state link

  2. Create a virtualmachinestate object

  3. 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.

Code Block
    {

      "title": "ON",

      "rel": "state",

      "type": "application/vnd.abiquo.virtualmachinestate+json",

      "href": "https://
mjsabiquo
nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/
26
2486/virtualappliances/
37
2990/virtualmachines/
198
19454/state"

    }, 

...

Here are some examples of virtualmachinestate objects and notes about changing VM states

...

Power on

Code Block
{"state": "ON"}

Pause

...

  • }

...

  • To

...

{
Expand
titleClick 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.

    Code Block
    curl -X PUT 
http
  • 'https://
localhost:9000
  • nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/
2205
  • 2486/virtualappliances/
1080
  • 2990/virtualmachines/
1121
  • 19454/state' \
      -k --verbose \
     
  •  -H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=
4
  • 5.
2
  • 0' \
     
  •  -H 'Content-Type: application/vnd.abiquo.virtualmachinestate+json; version=
4
  • 5.
2
  • 0' \
     
  •  -d
@requestpayload.json
  •  '{"state": "OFF", "gracefulShutdown": true}' \
     
  •  -u user:password | 
--verbose
  • jq .
Success status
  • Code Block

: 202

Request payload:

Code Block
{
  "taskId": "d62be542-f34c-4fed-b9f8-6443f2db4cc1",
  "

state
  • userId": "

OFF
  • 10",
      "type": "SHUTDOWN",
      "

links
  • ownerId":

[] }

Response payload:

Code Block{
  •  "19454",
      "state": "FINISHED_SUCCESSFULLY",
      "

message
  • creationTimestamp": 1596040226,
     

"You can keep track of the progress in the link",
  •  "timestamp": 1596040226,
      "jobs": {
        "links": [],
        "

links
  • collection": [
          {
            "

href
  • id": "

http://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",
            "

rel
  • parentTaskId": "

status"
  • 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
titleClick here to show or hide the request example
Code Block
"type": "SHUTDOWN",
        "

links
  • description":

[ {
  •  "Shutdown task's shutdown on virtual machine with id 19454",
            "

rel
  • state": "

self
  • DONE",
            

  • "

href
  • rollbackState":

"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks/8812ddf4-a372-40af-81ee-5f5d1e53454c"
  •  "UNKNOWN",
            "creationTimestamp": 

}
  • 1596040226,
           

{
  •  "timestamp": 1596040226,
            "

rel
  • links":

"parent",
  •  []
          

"href":"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks"
  • }
        ]
      },
      "links": 

  • [
     

{
  •    {
          "rel": "

acknowledge
  • self",

  • 
          

  • "href": "https://

38testing
  • nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/

55
  • 2486/virtualappliances/

200
  • 2990/virtualmachines/

1763
  • 19454/tasks/

8812ddf4
  • d62be542-

a372
  • f34c-

40af
  • 4fed-

81ee-5f5d1e53454c/action/ack"
  • b9f8-6443f2db4cc1"
        },

  • 
        

  • {

"title":"cloudadmin",
  • 
          

  • "rel":

"user", "type":"application/vnd.abiquo.user+json",
  •  "parent",
          

  • "href": "https://

38testing
  • nardo40.bcn.abiquo.com:443/api

/admin/enterprises/74/users/17"
  • /cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/tasks"
        

  • },

  • 
        {

  • 
          "

title
  • rel":

"ABQ_5e57c34d-5dcb-482b-be0f-a78931f4abd0",
  •  

  • "

rel":"virtualmachine
  • result",

  • 
          

  • "type": "application/vnd.abiquo.virtualmachine+json",

  • 
          "href": "https://

38testing
  • nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/

55
  • 2486/virtualappliances/

200
  • 2990/virtualmachines/

1763
  • 19454"

  • 
        

  • },
       

],
  •  {
      

"taskId":"8812ddf4-a372-40af-81ee-5f5d1e53454c",
  •     "

userId
  • title":

"17",
  •  "

type":"SHUTDOWN
  • user",
      

"ownerId":"1763",
  •     "

state
  • rel":

"FINISHED_UNSUCCESSFULLY",
  •  "

creationTimestamp
  • user"

:1458647896
  • ,
      

"timestamp":1458647897,
  •     "

jobs
  • type":

{
  •  

"links":[ ]
  • "application/vnd.abiquo.user+json",
          "

collection
  • href":

[ { "links":[
  •  "https://nardo40.bcn.abiquo.com:443/api/admin/enterprises/336/users/10"
        

]
  • },
        

  • {
          "

id
  • title": "

8812ddf4
  • ABQ_2fb11009-

a372
  • 8157-

40af
  • 4d61-

81ee-5f5d1e53454c.191e44d9-74fa-453a-b7e0-596237618fcf",
  • 915d-40fa45f440ac",
          

  • "

parentTaskId
  • rel":

"8812ddf4-a372-40af-81ee-5f5d1e53454c",
  •  "virtualmachine",
          "type":

"SHUTDOWN",
  •  "application/vnd.abiquo.virtualmachine+json",
          

  • "

description
  • href":

"Shutdown task's shutdown on virtual machine with id 1763",
  •  "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454"
        }
      ]
    

  • } 

  • Power on

    Code Block
    {"state":
"FAILED",
  •  
  • "
rollbackState":"ROLLBACK_DONE", "creationTimestamp":1458647896, "timestamp":1458647897 } ] } }

Reset a VM using the API

...

  • 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".

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"
    }
  ]
}