Introduction
This page describes how to add a hard disk to a VM.
You will need the following resources.
- A VM in a VDC that supports hard disks (private cloud or vCloud Director).
- If deployed without hot-reconfigure, you will need to power off the VM (you can do this with the API)
- If deployed without hot-reconfigure, you will need to power off the VM (you can do this with the API)
Potential data loss
- Abiquo destroys hard disks when you detach them from the VM or when you undeploy or delete the VM
- Always be careful when working with VM objects and put requests. If you accidentally remove a link, this could delete a disk or network interface card, for example
Your user role must have at least the following privileges:
- ROLE_VDC_MANAGE_STORAGE
- ROLE_VDC_MANAGE_STORAGE_CONTROLLER
- ROLE_MANAGE_HARD_DISKS
Feature description and UI documentation:
- Abiquo hard disks are non-persistent disks that are created on the hypervisor datastore.
- See VM storage#CreateHardDisksonHypervisorDatastores.
To add a hard disk to a VM through the API, the main steps are as follows.
- Create a hard disk in the virtual datacenter
- Update the VM to add the hard disk link in the disk sequence
This may appear to be different to how you add a hard disk through the UI, where you work directly in the VM. But behind the scenes, the UI uses the API to create the hard disk in the virtual datacenter and then adds it to the VM.
Summary diagram
The steps in this diagram link to the pages of the API reference guide for resources and data entities.
Detailed steps
- Get VM from the cloud and separate the VM entity
- Filter the VMs by vmlabel, for example
- Reference: https://wiki.abiquo.com/api/latest/AllVirtualMachinesResource.html#list-virtual-machines-of-the-user
cURL
curl -X GET "https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualmachines?vmlabel=yVM_hd" \ -H "Accept: application/vnd.abiquo.virtualmachines+json;version=4.7" \ -u user:password | jq .
Sample response. Success status code: 200
Note that this request returns a collection of VMs, you will need to get the VM from within the collection. You can also use the edit link to obtain the VM by itselfKeep the VM entity to update it. You will need the harddisks, datastore tiers, diskX, and virtualdatacenter links
Use the VDC link from the VM to get the VDC
Reference: https://wiki.abiquo.com/api/latest/VirtualDatacentersResource.html#get-a-virtual-datacenter
cURL
curl -X GET "https://abiquoapi.bcn.abiquo.com/api/cloud/virtualdatacenters/1896" \ -H 'Accept: application/vnd.abiquo.virtualdatacenter+json;version=4.7' \ -u user:password --verbose
Sample response. Success status code: 200
From the virtual datacenter save the link with a rel value of "disks"
{ "title": "disks", "rel": "disks", "type": "application/vnd.abiquo.harddisks+json", "href": "https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1896/disks" },
Create a data object for the hard disk
- Reference: https://wiki.abiquo.com/api/latest/harddisk.html
Sample hard disk entity
{ "links":[], "sizeInMb":20, "sequence":2, "allocation":"THIN", "diskControllerType":"SCSI", "label":"test disk 04", "diskController":"lsilogic" }
- Optionally specify a datastore tier with a link
Create the hard disk in the VDC
Send a POST request to the virtual datacenter disks link with the disk data object.
curl --verbose -X POST "https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1896/disks" \ -H "Accept: application/vnd.abiquo.harddisk+json;version=4.7" \ -H "Content-Type: application/vnd.abiquo.harddisk+json;version=4.7" \ -u user:password -k \ -d '{ "links":[ ], "sizeInMb":20, "sequence":2, "allocation":"THIN", "diskControllerType":"SCSI", "label":"test disk 04", "diskController":"lsilogic" }' | jq .
Sample response. Success status code: 201
Keep the edit link to use to assign the hard disk to the VM
{ "diskAllocation": "THIN", "diskController": "lsilogic", "diskControllerType": "SCSI", "diskLabel": "test disk 04", "rel": "edit", "type": "application/vnd.abiquo.harddisk+json", "href": "https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1896/disks/15010" }
Create disk link and to add to the VM entity
Change the edit link to diskX with the next number in the disk sequence. In this case, for the third disk, we will use "disk2"
{ "diskAllocation": "THIN", "diskController": "lsilogic", "diskControllerType": "SCSI", "diskLabel": "test disk 04", "rel": "disk2", "type": "application/vnd.abiquo.harddisk+json", "href": "https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1896/disks/15010" }
Power off the VM if it is deployed without hot reconfigure
- Send a PUT request to the VM state link.
- To power off, set the state attribute to "OFF". To shut down the VM, add the "gracefulShutdown" attribute and set it to "true". Note that the graceful shutdown may require VM tools.
cURL
curl --verbose -X PUT "https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/4/virtualmachines/182/state" \ -H "Content-Type: application/vnd.abiquo.virtualmachinestate+json;version=4.2" \ -d '{"state": "OFF", "gracefulShutdown": true}' \ -u user:password -k
- If the request returns a status code of 202, that means it was accepted. However, you should always check that the VM is really powered off.
Get the VM again using the VM edit link.
curl -X GET "https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1896/virtualappliances/2377/virtualmachines/16493" \ -H "Accept: application/vnd.abiquo.virtualmachine+json;version=4.7" \ -u user:password | jq .
This step is included in the walkthrough to ensure that your VM object is up to date!
Update the VM with a VM entity containing the new disk link
- Reference: https://wiki.abiquo.com/api/latest/VirtualMachinesResource.html#update-a-virtual-machine
cURL
curl --verbose -X PUT -u user:password \ 'https://abiquoapi.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1896/virtualappliances/2377/virtualmachines/16493' -H 'Accept:application/vnd.abiquo.acceptedrequest+json;version=4.7' \ -H 'Content-type:application/vnd.abiquo.virtualmachine+json;version=4.7' \ -d @virtualMachineHD.json | jsonindent -f -nbe
Request data for this request will be in the local file named "virtualMachineHD.json".
- A successful request will return a 204 no content link if the VM is not deployed. And if the VM is deployed, it will return a 202 - accepted request with a link to follow the progress of the operation.
Check that the hard disk is attached.
To check that the hard disk is attached, get the VM object again and check that the disk link is correct.
Remove an auxiliary hard disk from a VM
To remove the hard disk from the VM, destroying the hard disk and the data on it, remove the link to the hard disk and update the VM.