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": "
PAUSED
ON",
      
"rel": "state",
      
"type": "application/vnd.abiquo.virtualmachinestate+json",

      
"href": "https://
38testing
nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/
55
2486/virtualappliances/
200
2990/virtualmachines/
1763
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"}

...

  • When you perform a power off via API

...

  • ,

...

titleClick here to show or hide the request example

...

  • the response will include a link where you can monitor the progress of this operation.

...

Example of failed graceful shutdown

...

  • successful.

...

Code Block
Expand
titleClick 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": [
          {
            "id": "d62be542-f34c-4fed-b9f8-6443f2db4cc1.2cd94a0c-179d-4506-a71d-fabaf29a4d43",
            "parentTaskId": "d62be542-f34c-4fed-b9f8-6443f2db4cc1",
            "type": "SHUTDOWN",
            "description": "Shutdown task's shutdown on virtual machine with id 19454",
            "state": "DONE",
          

"rel":"self",
  •   "rollbackState": "UNKNOWN",
            "creationTimestamp": 1596040226,
            "timestamp": 1596040226,
            "links": []
          }
        ]
      },
      "links": [
        {
          "rel": "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
  • b9f8-

5f5d1e53454c
  • 6443f2db4cc1"

  • 
        },
        

  • {
          

  • "rel": "parent",

  • 
          "href": "https://

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

55
  • 2486/virtualappliances/

200
  • 2990/virtualmachines/

1763
  • 19454/tasks"
        

  • },
        {
     

{
  •      "rel": "result",
          "

rel
  • type":

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

  • 
          "href": "https://

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

55
  • 2486/virtualappliances/

200
  • 2990/virtualmachines/

1763/tasks/8812ddf4-a372-40af-81ee-5f5d1e53454c/action/ack
  • 19454"
        

  • },
        

  • {

  • 
          

  • "title": "

cloudadmin
  • user",

  • 
          

  • "rel": "user",
          

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

  • 
          "href": "https://

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

74
  • 336/users/

17
  • 10"

  • 
        },

  • 
        {

  • 
          "title": "ABQ_

5e57c34d
  • 2fb11009-

5dcb
  • 8157-

482b
  • 4d61-

be0f
  • 915d-

a78931f4abd0
  • 40fa45f440ac",

  • 
          "rel": "virtualmachine",
          

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

  • Power on

    Code Block
    {"state":
"8812ddf4-a372-40af-81ee-5f5d1e53454c", "userId":"17", "type":"SHUTDOWN", "ownerId":"1763", "state":"FINISHED_UNSUCCESSFULLY", "creationTimestamp":1458647896, "timestamp":1458647897, "jobs":{ "links":[ ], "collection":[ { "links":[ ], "id":"8812ddf4-a372-40af-81ee-5f5d1e53454c.191e44d9-74fa-453a-b7e0-596237618fcf", "parentTaskId":"8812ddf4-a372-40af-81ee-5f5d1e53454c", "type":"SHUTDOWN",
  •  "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. If you are using a test environment, you may wish to add the --insecure option.

cURL:

Code Block
curl -X POST 'https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/action/reset' \ 
-k --verbose \
-H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=5.0' \
-u user:password | jq . 

Success status code: 202

Request payload:

--none--

Response payload:

Code Block
{
  "message": "You can keep track of the progress in the link",
  "links": [
    {
      "descriptiontitle":"Shutdown task's shutdown on virtual machine with id 1763",
      "status",
      "staterel": "FAILEDstatus",
            "rollbackState"type":"ROLLBACK_DONE",
      "application/vnd.abiquo.task+json",
      "creationTimestamphref":1458647896,
            "timestamp":1458647897
   "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/tasks/edec6cf1-8874-451d-a4c0-57f4c24da371"
     }
   
  ]
   } }

Reset a VM using the API

To reset a VM using the API, use a POST request to the reset action link.

Ex Reset a virtual machine
Expand
Include Page
Ex Reset a virtual machine