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 state of the VM.

    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/6/state",
      "type": "application/vnd.abiquo.virtualmachinestate+json",
      "rel": "state",
      "title": "ON"
    },

Examples of virtualmachinestate objects

Azure power off and deallocate

Azure has two power off states - powered off and deallocated.

Example of VM hard power off via API

The API will return a link where you can monitor the progress of this operation.

See https://wiki.abiquo.com/api/latest/VirtualMachinesResource.html#change-the-state-of-a-virtual-machine

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. 


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

cURL:

curl -X POST http://localhost:9000/api/cloud/virtualdatacenters/2210/virtualappliances/1085/virtualmachines/1126/action/reset \ 
	 -H 'Accept:application/vnd.abiquo.acceptedrequest+json; version=4.2' \ 
	 -u user:password --verbose 

Success status code: 202

Request payload:

--none--

Response payload:

{
  "message": "You can keep track of the progress in the link", 
  "links": [
    {
      "href": "http://localhost:9009/api/cloud/virtualdatacenters/2210/virtualappliances/1085/virtualmachines/1126/tasks/1fd663d5-1e66-4443-b94c-f78d13c9e62f", 
      "rel": "status"
    }
  ]
}