Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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:

  1. Retrieve the virtual appliance that the VM will be captured into

  2. Retrieve the VM with resources from the hypervisor in Abiquo

  3. Retrieve the network addresses from the platform and add them to the VM object

  4. 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
{
    "links": [],
    "collection": [
        {
            "id": 272,
            "uuid": "422f20c1-103b-5c7c-7751-146ca56e207a",
            "name": "Abiquo monolithic 4.2",
            "label": "Abiquo monolithic 4.2",
            "description": "",
            "cpu": 2,
            "coresPerSocket": 1,
            "ram": 2048,
            "vdrpEnabled": false,
            "vdrpPort": 0,
            "idState": 4,
            "state": "ON",
            "idType": 0,
            "type": "NOT_MANAGED",
            "highDisponibility": 0,
            "metadata": null,
            "monitored": false,
            "protected": false,
            "variables": {},
            "creationTimestamp": 1516271725000,
            "backuppolicies": [],
            "lastSynchronize": 1516271725000,
            "generateGuestInitialPassword": false,
            "links": [
                {
                    "title": "VMX_04",
                    "rel": "machine",
                    "type": "application/vnd.abiquo.machine+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2"
                },
                {
                    "title": "BCDC",
                    "rel": "location",
                    "type": "application/vnd.abiquo.datacenter+json",
                    "href": "https://example.com:443/api/cloud/locations/4"
                },
                {
                    "title": "VMware vCenter",
                    "rel": "hypervisortype",
                    "type": "application/vnd.abiquo.hypervisortype+json",
                    "href": "https://example.com:443/api/config/hypervisortypes/VMX_04"
                },
                {
                    "title": "Abiquo monolithic 4.2",
                    "rel": "virtualmachine",
                    "type": "application/vnd.abiquo.virtualmachine+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/272"
                }
            ]
        },
        {
            "id": 265,
            "uuid": "14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "name": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "label": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "description": "",
            "cpu": 1,
            "coresPerSocket": 1,
            "ram": 48,
            "vdrpEnabled": true,
            "vdrpPort": 5913,
            "vdrpIP": "192.168.2.54",
            "idState": 4,
            "state": "ON",
            "idType": 0,
            "type": "NOT_MANAGED",
            "highDisponibility": 0,
            "password": "qa1gPTrL",
            "metadata": null,
            "monitored": false,
            "protected": false,
            "variables": {},
            "creationTimestamp": 1516271725000,
            "backuppolicies": [],
            "lastSynchronize": 1516271725000,
            "generateGuestInitialPassword": false,
            "links": [
                {
                    "title": "VMX_04",
                    "rel": "machine",
                    "type": "application/vnd.abiquo.machine+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2"
                },
                {
                    "title": "BCDC",
                    "rel": "location",
                    "type": "application/vnd.abiquo.datacenter+json",
                    "href": "https://example.com:443/api/cloud/locations/4"
                },
                {
                    "title": "VMware vCenter",
                    "rel": "hypervisortype",
                    "type": "application/vnd.abiquo.hypervisortype+json",
                    "href": "https://example.com:443/api/config/hypervisortypes/VMX_04"
                },
                {
                    "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
                    "rel": "virtualmachine",
                    "type": "application/vnd.abiquo.virtualmachine+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265"
                }
            ]
        },


.... Lots more VMs cut from here! ...
	]
}

...

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
{
    "volumes": {
        "links": [],
        "collection": []
    },
    "disks": {
        "links": [],
        "collection": [
            {
                "label": "",
                "sequence": 0,
                "sizeInMb": 64,
                "diskFormatType": "VMDK_FLAT",
                "path": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8/ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8756e9bd6-b079-430f-b9e7-c2e7e67de66e-flat.vmdk",
                "diskFileSize": 67108864,
                "diskControllerType": "IDE",
                "bus": 0,
                "unit": 0,
                "bootable": true,
                "uuid": "756e9bd6-b079-430f-b9e7-c2e7e67de66e",
                "links": []
            }
        ]
    },
    "nics": {
        "links": [],
        "collection": [
            {
                "mac": "00:50:56:08:D5:73",
                "sequence": 0,
                "tag": 7,
                "links": []
            }
        ]
    },
    "links": [
        {
            "title": "VMX_04",
            "rel": "machine",
            "type": "application/vnd.abiquo.machine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2"
        },
        {
            "title": "BCDC",
            "rel": "location",
            "type": "application/vnd.abiquo.datacenter+json",
            "href": "https://example.com:443/api/cloud/locations/4"
        },
        {
            "title": "VMware vCenter",
            "rel": "hypervisortype",
            "type": "application/vnd.abiquo.hypervisortype+json",
            "href": "https://example.com:443/api/config/hypervisortypes/VMX_04"
        },
        {
            "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "rel": "edit",
            "type": "application/vnd.abiquo.virtualmachine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265"
        }
    ],
    "id": 265,
    "name": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
    "description": "",
    "ram": 48,
    "cpu": 1,
    "vdrpPort": 5913,
    "vdrpIP": "192.168.2.54",
    "vdrpEnabled": true,
    "idState": 4,
    "state": "ON",
    "highDisponibility": 0,
    "idType": 0,
    "type": "NOT_MANAGED",
    "password": "qa1gPTrL",
    "uuid": "14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
    "metadata": null,
    "label": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
    "monitored": false,
    "monitoringLevel": "DEFAULT",
    "variables": {},
    "creationTimestamp": 1516271725000,
    "lastSynchronize": 1516271736000,
    "generateGuestInitialPassword": false,
    "protected": false,
    "backuppolicies": []
} 

...

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
Code Block

...


    "links": [
        {
            "rel": "first",
            "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips?limit=25&by=ip&asc=true"
        },
        {
            "rel": "last",
            "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips?startwith=0&limit=25&by=ip&asc=true"
        }
    ],
    "collection": [
        {
            "available": true,
            "quarantine": false,
            "links": [
                {
                    "title": "External_network",
                    "rel": "externalnetwork",
                    "type": "application/vnd.abiquo.vlan+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7"
                },
                {
                    "title": "ips",
                    "rel": "ips",
                    "type": "application/vnd.abiquo.externalips+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips"
                },
                {
                    "title": "192.168.7.2",
                    "rel": "self",
                    "type": "application/vnd.abiquo.externalip+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips/30"
                }
            ],
            "id": 30,
            "ip": "192.168.7.2",
            "networkName": "External_network",
            "ipv6": false
        },
        {
            "available": true,
            "quarantine": false,
            "links": [
                {
                    "title": "External_network",
                    "rel": "externalnetwork",
                    "type": "application/vnd.abiquo.vlan+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7"
                },
                {
                    "title": "ips",
                    "rel": "ips",
                    "type": "application/vnd.abiquo.externalips+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips"
                },
                {
                    "title": "192.168.7.3",
                    "rel": "self",
                    "type": "application/vnd.abiquo.externalip+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips/31"
                }
            ],
            "id": 31,
            "ip": "192.168.7.3",
            "networkName": "External_network",
            "ipv6": false
        }
    ],
    "totalSize": 2
}

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".

Code Block
        {
            "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "rel": "edit",
            "type": "application/vnd.abiquo.virtualmachine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265"
        }

The two new links to replace it

Code Block
        {
            "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "rel": "virtualmachine",
            "type": "application/vnd.abiquo.virtualmachine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265"
        },
        {
            "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "rel": "imported",
            "type": "application/vnd.abiquo.virtualmachine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265"
        }

...

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
Code Block
{
    "volumes": {
        "links": [],
        "collection": []
    },
    "disks": {
        "links": [],
        "collection": [
            {
                "label": "",
                "sequence": 0,
                "sizeInMb": 64,
                "diskFormatType": "VMDK_FLAT",
                "path": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8/ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8756e9bd6-b079-430f-b9e7-c2e7e67de66e-flat.vmdk",
                "diskFileSize": 67108864,
                "diskControllerType": "IDE",
                "bus": 0,
                "unit": 0,
                "bootable": true,
                "uuid": "756e9bd6-b079-430f-b9e7-c2e7e67de66e",
                "links": []
            }
        ]
    },
    "nics": {
        "links": [],
        "collection": [
            {
                "mac": "00:50:56:08:D5:73",
                "sequence": 0,
                "tag": 7,
			    "ip": "192.168.7.2",
                "links": [
                	        {
            					"title": "External_network",
            					"rel": "vlan",
            					"type": "application/vnd.abiquo.vlan+json",
            					"href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7"
        					}
                	]
            }
        ]
    },
    "links": [
        {
            "title": "VMX_04",
            "rel": "machine",
            "type": "application/vnd.abiquo.machine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2"
        },
        {
            "title": "BCDC",
            "rel": "location",
            "type": "application/vnd.abiquo.datacenter+json",
            "href": "https://example.com:443/api/cloud/locations/4"
        },
        {
            "title": "VMware vCenter",
            "rel": "hypervisortype",
            "type": "application/vnd.abiquo.hypervisortype+json",
            "href": "https://example.com:443/api/config/hypervisortypes/VMX_04"
        },
        {
            "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "rel": "virtualmachine",
            "type": "application/vnd.abiquo.virtualmachine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265"
        },
        {
            "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "rel": "imported",
            "type": "application/vnd.abiquo.virtualmachine+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265"
        }
    ],
    "id": 265,
    "name": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
    "description": "",
    "ram": 48,
    "cpu": 1,
    "vdrpPort": 5913,
    "vdrpIP": "192.168.2.54",
    "vdrpEnabled": true,
    "idState": 4,
    "state": "ON",
    "highDisponibility": 0,
    "idType": 0,
    "type": "NOT_MANAGED",
    "password": "qa1gPTrL",
    "uuid": "14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
    "metadata": null,
    "label": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
    "monitored": false,
    "monitoringLevel": "DEFAULT",
    "variables": {},
    "creationTimestamp": 1516271725000,
    "lastSynchronize": 1516271736000,
    "generateGuestInitialPassword": false,
    "protected": false,
    "backuppolicies": []
}

...