Div | ||
---|---|---|
| ||
API Reconfigure Tutorial 2 |
Div | ||
---|---|---|
| ||
|
Overview
This simple walkthrough shows how to reconfigure a virtual machine, in this case we will add a volume of external storage using the API. The basic procedure for adding a volume to a virtual machine is:
- Retrieve the virtual machine
- Retrieve an available volume
- Add the volume to the virtual machine
- Reconfigure the virtual machine
Prerequisites
This tutorial should be used in a test environment. You can set up the following basic environment in the GUI and then work on the tutorial using the API. After you have finished, you should see the new volume on your virtual machine.
Environment
You will need:
- A deployed virtual machine that is powered off
- the VM used in this tutorial is configured with the following disks:
- disk1 - system hard disk on the hypervisor datastore
- disk2 - a volume attached to the virtual machine
- the VM used in this tutorial is configured with the following disks:
- A storage device and a volume that is not attached to a virtual machine
- tip: for a test system, enable the creation of small volumes through the GUI by setting 0.1, 0.2 GB in Configuration view
- The ID number of your enterprise and datacenter
- this tutorial uses an environment with: Abiquo Enterprise 1 and Datacenter 1
- Privileges as described below
- if you are a CLOUD_ADMIN or ENTERPRISE_ADMIN user, no extra privileges are required
In an Abiquo test environment do these steps using the Abiquo GUI
- Create a virtual appliance and virtual machine
- Deploy the virtual appliance
- Power off the virtual machine
- Create two volumes
- Attach one volume to the virtual machine
Privileges Required
This tutorial is designed to be used by an Enterprise Administrator or Cloud Administrator in a test environment.
ROLE_VDC_ENUMERATE
ROLE_VAPP_CUSTOMISE_SETTINGS
ROLE_VDC_MANAGE_VAPP
VDC_MANAGE_STORAGE
Preparation
First, you can use the AllVirtualMachinesResource to retrieve all the virtual machines.
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
|
The following links will provide information about the disks attached to the virtual machine:
Code Block |
---|
{ "title": "Devol1", "rel": "disk1", "type": "application/vnd.abiquo.volume+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes/2" }, { "diskController": "lsilogic", "diskControllerType": "SCSI", "diskLabel": "scsi0:0", "length": "26", "title": "8f62ef08-8f6a-4f08-9cd1-999b7b9c98dc", "rel": "disk0", "type": "application/vnd.abiquo.harddisk+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/disks/4" }, |
From this response we can see that the disks attached are:
- a hard disk with an ID of "4".
- a volume with an ID of "2"
Retrieve Available Volumes in an Enterprise's Virtual Datacenter
In the virtual machine DTO above, look for the link to the virtual datacenter.
Code Block |
---|
{ "title": "ESXBC", "rel": "virtualdatacenter", "type": "application/vnd.abiquo.virtualdatacenter+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3" }, |
Get all the available volumes in the virtual datacenter by requesting all volumes with the parameter available = true.
cURL:
Code Block |
---|
curl -X GET http://mjsabq.bcn.abiquo.com/api/cloud/virtualdatacenters/2/volumes?available=true \ -H 'Accept: application/vnd.abiquo.volumes+json;version=3.6' \ -u admin:xabiquo --verbose |
Success status code: 200
Request payload:
--none--
Response payload:
Code Block |
---|
{ "links": [ { "rel": "first", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes?available=true&limit=25&by=id" }, { "rel": "last", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes?available=true&startwith=0&limit=25&by=id" } ], "collection": [ { "links": [ { "title": "Devol2", "rel": "edit", "type": "application/vnd.abiquo.volume+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes/3" }, { "title": "Default Tier 1", "rel": "tier", "type": "application/vnd.abiquo.tier+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/tiers/1" }, { "title": "initiator mappings", "rel": "initiatormappings", "type": "application/vnd.abiquo.initiatormappings+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes/3/action/initiatormappings" }, { "title": "ESXBC", "rel": "virtualdatacenter", "type": "application/vnd.abiquo.virtualdatacenter+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3" } ], "id": 3, "name": "Devol2", "description": "Dev volume 2", "state": "DETACHED", "sizeInMB": 102, "sequence": 0, "allowResize": true, "diskControllerType": "IDE", "bootable": false } ], "totalSize": 1 } |
From the above response, we can see that there are two volumes, one of which is already attached to a virtual machine. We will work with the other volume "Devol2", which has an ID of "3".
Edit the Virtual Machine
Copy the volume edit link from the volume you wish to attach to the virtual machine from the above response object.
Code Block |
---|
{ "title": "Devol2", "rel": "edit", "type": "application/vnd.abiquo.volume+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes/3" }, |
Check how many disks are on the virtual machine already. The example machine has two disks:
- disk0 - the system hard disk on the hypervisor datastore
- disk1 - another volume
Change the "rel" link to the disk's new sequence number. In this case it will be disk2
Code Block |
---|
{ "title": "Devol2", "rel": "disk2", "type": "application/vnd.abiquo.volume+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes/3" }, |
Add this new link to the virtual machine from above.
Remember that the virtual machine is part of a collection and you need to work with only the virtual machine
Be careful not to remove any existing volume or NIC links, or you will remove the volume or NIC from the virtual machine!
Your new virtual machine DTO should look similar to the following example.
Div | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
|
Reconfigure the Virtual Machine
Perform a put request on the virtual machine with the virtual machine that you edited to include the new link
Div | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||
|
The request will return a link that can be used to check the progress of the task.
Div | |||||
---|---|---|---|---|---|
| |||||
|
Check Progress
We can check the progress of the task using:
Div | |||||
---|---|---|---|---|---|
| |||||
|
Expand | ||
---|---|---|
|
Check the Volume is Attached
Get the virtual machine and check that the disk2 link is present.
Expand | ||
---|---|---|
|
In the above virtual machine you can see the volume link, which is shown here.
Code Block |
---|
{ "title": "Devol2", "rel": "disk2", "type": "application/vnd.abiquo.volume+json", "href": "https://mjsabq.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/volumes/3" }, |
Detach the Volume
To detach a volume, remove the volume link from the DTO and perform a put request for the virtual machine.
cURL:
Code Block |
---|
curl -X PUT https://mjspac.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/6/virtualmachines/116 \ -H 'Accept: application/vnd.abiquo.acceptedrequest+json;version=3.2' \ -H 'Content-type: application/vnd.abiquo.virtualmachine+json;version=3.2' \ -d @virtualmachine_minus_volume.json \ -u admin:xabiquo --verbose |
Expand | ||||
---|---|---|---|---|
Request payload: This is the original virtual machine that we retrieved before we added a disk.
Success status code: 200 Response payload:
|
To check the volume has been detached get the available volumes, virtual machine or the volume. For example, the available volumes.
Expand | ||||
---|---|---|---|---|
cURL:
Success status code: 200 Request payload: -- none -- Response payload:
|