...
Send a GET request to the API login resource to obtain the token from the X-Abiquo-Token header for authentication
Code Block curl --verbose -X GET "https://nardo40.bcn.abiquo.com:443/api/login" -u adminuser:password -k | jq .
Get VMs from the cloud and separate the VM entity. Filter the VMs by vmlabel, for example, as shown in the following cURL. If the request is successful, the status code is 200. This request returns a collection of VMs, so you will need to get the VM from within the collection or use the edit link to obtain the VM by itself.
Code Block curl --verbose -k -X GET "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualmachines?vmlabel=yVM_addDisk" \ -H "Accept: application/vnd.abiquo.virtualmachines+json;version=5.0" \ -H "Authorization: Token a2e1981..." | jq .
Reference: https://wiki.abiquo.com/api/latest/AllVirtualMachinesResource.html#list-virtual-machines-of-the-userKeep the VM entity to create the VM object for the update. As well as the VM edit link, you will also need the harddisks, datastore tiers, diskX, and virtualdatacenter links.
VM edit link
Code Block { "title": "ABQ_f5067776-9b43-4105-bb5a-4478ecf9b96c", "rel": "edit", "type": "application/vnd.abiquo.virtualmachine+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19477" },
harddisks link
Code Block { "title": "disks", "rel": "harddisks", "type": "application/vnd.abiquo.harddisks+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19477/storage/disks" },
diskX links for all hard disks and volumes that are already attached to the VM. In this case, there is one HD in position 0 of the boot order and one volume in position 1. Add the new disk in the next position.
Code Block { "diskControllerType": "IDE", "length": "10", "title": "testvol1", "rel": "disk1", "type": "application/vnd.abiquo.volume+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/locations/1/volumes/18087" }, { "diskControllerType": "IDE", "diskLabel": "Hard disk 1", "length": "64", "title": "2129870d-8f49-4486-90e9-c5f14f661d35", "rel": "disk0", "type": "application/vnd.abiquo.harddisk+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/disks/18086" },
datastoretierX for hard disks
Code Block { "title": "datastoretierESXI6.0_2.29", "rel": "datastoretier0", "type": "application/vnd.abiquo.datastoretier+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/locations/1/datastoretiers/58" },
virtualdatacenter
Code Block { "title": "vdc_api_tutorial", "rel": "virtualdatacenter", "type": "application/vnd.abiquo.virtualdatacenter+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486" },
Use the VDC link from the VM to get the VDC, for example, using cURL. If the request is successful, the status code is 200.
Code Block curl --verbose -k -X GET "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486" \ -H 'Accept: application/vnd.abiquo.virtualdatacenter+json;version=5.0' \ -H 'Authorization: Token XXXX' | jq .
From the virtual datacenter save the link with a rel value of "disks"
Code Block { "title": "disks", "rel": "disks", "type": "application/vnd.abiquo.harddisks+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/disks" },
Create a data object for the hard disk, for example.
Code Block { "links":[], "sizeInMb":20, "sequence":2, "allocation":"THIN", "diskControllerType":"SCSI", "label":"test disk 04", "diskController":"lsilogic" }
- You can also specify a datastore tier with a link. Note that the datastore tier must be compatible with the datastore tier of the boot disk
- Reference: https://wiki.abiquo.com/api/latest/harddisk.html
Create the hard disk in the VDC.
Send a POST request to the virtual datacenter disks link with the disk data object, for example, with cURL
Code Block curl --verbose -k -X POST "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/disks" \ -H "Accept: application/vnd.abiquo.harddisk+json;version=5.0" \ -H "Content-Type: application/vnd.abiquo.harddisk+json;version=5.0" \ -H "Authorization: Token XXXX" \ -d '{ "links":[ ], "sizeInMb":20, "sequence":2, "allocation":"THIN", "diskControllerType":"SCSI", "label":"testDisk02", "diskController":"lsilogic" }' | jq .
If the request is successful, the status code will be 201.
Keep the edit link to use to assign the hard disk to the VM
Code Block { "diskAllocation": "THIN", "diskController": "lsilogic", "diskControllerType": "SCSI", "diskLabel": "testDisk02", "rel": "edit", "type": "application/vnd.abiquo.harddisk+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/disks/18092" }
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"
Code Block { "diskAllocation": "THIN", "diskController": "lsilogic", "diskControllerType": "SCSI", "diskLabel": "testDisk02", "rel": "disk2", "type": "application/vnd.abiquo.harddisk+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/disks/18092" }
Power off If the VM if it is deployed without hot reconfigure, power off the VM
Send a PUT request to the VM state link from the VM object. 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.
Code Block curl --verbose -X PUT "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19477/state" \ -H "Content-Type: application/vnd.abiquo.virtualmachinestate+json;version=5.0" \ -d '{"state": "OFF", "gracefulShutdown": true}' \ -H "Authorization: Token XXXX" -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 (you can check in the VM data object from the next GET request)
- Reference: https://wiki.abiquo.com/api/latest/VirtualMachinesResource.html#change-the-state-of-a-virtual-machine
Get the VM again using the VM edit link
Code Block curl -X GET "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19477" \ -H "Accept: application/vnd.abiquo.virtualmachine+json;version=5.0" \ -u user:password | jq .
This step is included in the walkthrough to ensure that your VM object is up to date and that the VM is in the OFF state!
Reference: https://wiki.abiquo.com/api/latest/VirtualMachinesResource.html#get-a-virtual-machineUpdate the VM with a the VM entity data object containing the new disk link
For example, using cURL, and with the VM data object in a file named "virtualMachineHD.json".
Code Block curl --verbose -X PUT \ 'https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19477' \ -H 'Accept:application/vnd.abiquo.acceptedrequest+json;version=5.0' \ -H 'Content-type:application/vnd.abiquo.virtualmachine+json;version=5.0' \ -H 'Authorization: Token XXXX' \ -d @virtualMachineHD.json | jq .
Reference: https://wiki.abiquo.com/api/latest/VirtualMachinesResource.html#update-a-virtual-machine
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.
...