This page describes how to add a hard disk to a VM.
You will need the following resources.
|
Your user role must have at least the following privileges:
Feature description and UI documentation:
To add a hard disk to a VM through the API, the main steps are as follows.
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. |
The steps in this diagram link to the pages of the API reference guide for resources and data entities.
@startuml (*) --> "Requires a VM" as A1 A1 --> "[[https://wiki.abiquo.com/api/latest/AllVirtualMachinesResource.html#list-virtual-machines-of-the-user Get VMs from the cloud]]" as A2 A2 --> "[[https://wiki.abiquo.com/api/latest/VirtualDatacentersResource.html#get-a-virtual-datacenter Get the virtual datacenter of the VM]]" as A3 A3 --> "[[https://wiki.abiquo.com/api/latest/harddisk.html Create a data object\nfor the hard disk]]" as A4 A4 --> "[[https://wiki.abiquo.com/api/latest/DisksManResource.html#create-a-hard-disk-in-a-virtual-datacenter Create a hard disk\nin a virtual datacenter]]" as A5 A5 --> "If necessary, power off the VM" as A6 A6 --> "Optionally get the VM again\nfrom its edit link" as A7 A7 --> "Change the edit link of the\nhard disk to a diskX link\nand add to the VM" as A8 A8 --> "[[https://wiki.abiquo.com/api/latest/VirtualMachinesResource.html#update-a-virtual-machine Update VM to add\nthe hard disk]]" as A9 A9 --> (*) @enduml |
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 only
|
Keep 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
Sample hard disk entity
{ "links":[], "sizeInMb":20, "sequence":2, "allocation":"THIN", "diskControllerType":"SCSI", "label":"test disk 04", "diskController":"lsilogic" } |
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
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 |
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
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".
|
To check that the hard disk is attached, get the VM object again and check that the disk link is correct.
|
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.