Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To perform a power action 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 state of the VM.

Code Block
           {  
               "title":"PAUSED",
               "rel":"state",
               "type":"application/vnd.abiquo.virtualmachinestate+json",
               "href":"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/state"
            },

Examples of virtualmachinestate objects

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

Example of VM hard power off via API

To hard power off a VM using the API, perform a request like the one shown below.

...

titleClick here to show or hide the request example

...

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. 

...

titleClick here to show or hide the request example
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"
      },
      {
         "rel":"acknowledge",
         "href":"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763/tasks/8812ddf4-a372-40af-81ee-5f5d1e53454c/action/ack"
      },
      {
         "title":"cloudadmin",
         "rel":"user",
         "type":"application/vnd.abiquo.user+json",
         "href":"https://38testing.bcn.abiquo.com:443/api/admin/enterprises/74/users/17"
      },
      {
         "title":"ABQ_5e57c34d-5dcb-482b-be0f-a78931f4abd0",
         "rel":"virtualmachine",
         "type":"application/vnd.abiquo.virtualmachine+json",
         "href":"https://38testing.bcn.abiquo.com:443/api/cloud/virtualdatacenters/55/virtualappliances/200/virtualmachines/1763"
      }
   ],
   "taskId":"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",
            "description":"Shutdown task's shutdown on virtual machine with id 1763",
            "state":"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.

...