...
Before you get started, make sure you are familiar with the capture process in the UI. Also you will need to prepare a suitable environment, with a virtual datacenter and a matching network for the VM. See Import and Capture Virtual Machinescapture virtual machines. Note that the Abiquo UI enables you to create a virtual appliance or a network address as part of the capture process but these steps are not included in this tutorial.
...
To capture a VM using the API:
Retrieve the virtual appliance that the VM will be captured into
Retrieve the VM with resources from the hypervisor in Abiquo
Retrieve the network addresses from the platform and add them to the VM object
Send a POST request with the VM object to virtual machines URL of the virtual appliance
Retrieve the virtual appliance
The first step is to List virtual appliances in your virtual datacenter and locate the virtual appliance where you will add the VM.
Tip |
---|
If you don't have the link to virtual appliances, first List virtual datacenters, and look for the "href" value of the virtualappliances link |
Code Block |
---|
curl -X GET https://example.com/api/cloud/virtualdatacenters/2/virtualappliances \
-H 'Accept:application/vnd.abiquo.virtualappliances+json; version=4.2' \
-u user:password --verbose |
From the virtual appliance objects, look for your virtual appliance, and find the virtualmachines link.
...
Code Block |
---|
curl -X GET https://example.com/api/admin/datacenters/4/racks/4/machines/2/virtualmachines?sync=true \ -H 'Accept:application/vnd.abiquo.virtualmachines+json; version=4.2' \ -u user:password --verbose |
Then search for your VM in the response and obtain the "virtualmachine" link
Expand | ||
---|---|---|
|
...
Code Block |
---|
curl -X GET https://example.com/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265?sync=true \ -H 'Accept:application/vnd.abiquo.virtualmachineflat+json; version=4.2' \ -u user:password --verbose |
This is our base virtualmachine flat object and as you can see there is no IP address for the NIC, so we will add that next.
Expand | ||
---|---|---|
|
...
Code Block |
---|
{ "title": "external networks", "rel": "externalnetworks", "type": "application/vnd.abiquo.vlans+json", "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks" }, |
Then perform a get request to retrieve the external networks.
Code Block |
---|
curl -X GET https://example.com/api/admin/enterprises/2/limits/5/externalnetworks \ -H 'Accept:application/vnd.abiquo.vlans+json; version=4.2' \ -u user:password --verbose |
...
Code Block |
---|
curl -X GET https://example.com/api/admin/enterprises/2/limits/5/externalnetworks/7/ips \ -H 'Accept:application/vnd.abiquo.externalips+json; version=4.2' \ -u user:password --verbose |
Expand | |
---|---|
|
...
|
Select the IP address that you would like to add to the VM.
...
Now go back and get the virtualmachineflat object that you retrieved from the hypervisor. Find the edit link (the "rel" value will be edit and copy it to create two links. Change the "rel" value of the first link to "virtualmachine" and the second one to "imported".
Expand | ||||
---|---|---|---|---|
The original link with a "rel" value of "edit".
The two new links to replace it
|
...
Code Block |
---|
curl -X POST http://example.com/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines \ -H 'Accept:application/vnd.abiquo.virtualmachineflat+json; version=4.2' \ -H 'Content-Type:application/vnd.abiquo.virtualmachineflat+json; version=4.2' \ -d @requestpayload.json \ -u user:password --verbose |
The virtualmachineflat object that you should send in the requestpayload.json file should be similar to the following example.
Expand | ||
---|---|---|
|
...