Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Author: Sergi Castro

You can capture a virtual machine using the API and once you get started, it's not such a daunting task as it might first seem!   And as always, if you get stuck, you can always open your browser console and take a look at how the Abiquo UI does it! 

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 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 work through this tutorial you can use a cloud admin account with basic authentication, but this is not recommended in a production environment, see Authentication

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.   

If you don't have the link to virtual appliances, first List virtual datacenters, and look for the "href" value of the virtualappliances link


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.

 Click here to expand...
{
    "links": [
        {
            "rel": "first",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances?limit=25&by=name&asc=true"
        },
        {
            "rel": "last",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances?startwith=0&limit=25&by=name&asc=true"
        }
    ],
    "collection": [
        {
            "id": 2,
            "error": 0,
            "highDisponibility": 0,
            "name": "vapp_vdc_tioco_02",
            "publicApp": 0,
            "state": "EMPTY",
            "notAllocatedVirtualMachines": 0,
            "onVirtualMachines": 0,
            "offVirtualMachines": 0,
            "pausedVirtualMachines": 0,
            "allocatedVirtualMachines": 0,
            "configuredVirtualMachines": 0,
            "unknownVirtualMachines": 0,
            "lockedVirtualMachines": 0,
            "links": [
                {
                    "title": "vapp_vdc_tioco_02",
                    "rel": "edit",
                    "type": "application/vnd.abiquo.virtualappliance+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2"
                },
                {
                    "title": "bcdc_tioco_02",
                    "rel": "virtualdatacenter",
                    "type": "application/vnd.abiquo.virtualdatacenter+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2"
                },
                {
                    "title": "Tioco",
                    "rel": "enterprise",
                    "type": "application/vnd.abiquo.enterprise+json",
                    "href": "https://example.com:443/api/admin/enterprises/2"
                },
                {
                    "title": "virtual machines",
                    "rel": "virtualmachines",
                    "type": "application/vnd.abiquo.virtualmachines+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines"
                },
                {
                    "title": "virtual appliances state",
                    "rel": "state",
                    "type": "application/vnd.abiquo.virtualappliancestate+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/state"
                },
                {
                    "title": "undeploy",
                    "rel": "undeploy",
                    "type": "application/vnd.abiquo.acceptedrequest+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/action/undeploy"
                },
                {
                    "title": "deploy",
                    "rel": "deploy",
                    "type": "application/vnd.abiquo.acceptedrequest+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/action/deploy"
                },
                {
                    "title": "price",
                    "rel": "price",
                    "type": "text/plain",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/action/price"
                },
                {
                    "title": "layers",
                    "rel": "layers",
                    "type": "application/vnd.abiquo.layers+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/layers"
                },
                {
                    "title": "alerts",
                    "rel": "alerts",
                    "type": "application/vnd.abiquo.alerts+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/alerts"
                },
                {
                    "title": "spec",
                    "rel": "spec",
                    "type": "application/vnd.abiquo.virtualappliancespec+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/action/spec"
                },
                {
                    "title": "tasks",
                    "rel": "tasks",
                    "type": "application/vnd.abiquo.tasks+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/tasks"
                },
                {
                    "title": "scalinggroups",
                    "rel": "scalinggroups",
                    "type": "application/vnd.abiquo.scalinggroups+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/scalinggroups"
                },
                {
                    "title": "metricsmetadata",
                    "rel": "metricsmetadata",
                    "type": "application/vnd.abiquo.metricsmetadata+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/metrics"
                },
                {
                    "title": "collectd",
                    "rel": "collectd",
                    "type": "application/json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/metrics/collectd"
                }
            ]
        }
    ],
    "totalSize": 1
}

To create the VM in the platform, we will send a POST request to this link. 

                {
                    "title": "virtual machines",
                    "rel": "virtualmachines",
                    "type": "application/vnd.abiquo.virtualmachines+json",
                    "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines"
                },

Now let's create the VM data object that we will send with the post request. 

Retrieve the VM with resources from the hypervisor

For this step, we will need to know how to locate and identify the VM in infrastructure. One easy way to do this is to open the UI console at the Network tab, and select the machine that the VM is running on. To obtain data about the infrastructure, the UI will be making GET requests to links like the following one. 

https://example.com/api/admin/datacenters/4/racks/4/machines/2/virtualmachines?cacheStamp=361_1516271112132

To retrieve all the VMs that are running on this machine but are not registered in Abiquo, use the query parameter "sync" with a value of true. 

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

 Click here to expand...
{
    "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! ...
	]
}

So our VM with the name starting with "ABQ_14c4aa8c" is number 265 in infrastructure, and its link is as follows.

                {
                    "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"
                }

Now retrieve the "virtualmachineflat" data object. This is a VM with all resources inline, including the network interface cards (NICs). Here we use the sync parameter with a value of true to obtain the latest information from the hypervisor. 

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.

 Click here to expand...
{
    "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": []
} 


Retrieve network details and IP addresses

In this tutorial we are going to work with an external network. This is the most flexible network type, because you can use public or private addresses and each external network is only available to the enterprise tenant that it belongs to. If you want to use a public network, you will need to purchase a public IP address for your virtual datacenter before you can add it to the VM.

External networks belong to a single enterprise, so you can open the browser console to the Networks tab and go to the Users view in the UI to find your enterprise ID number. When you select the enterprise, you should see a request to a link like the following one.

https://example.com/api/admin/enterprises/2/users?maxSize=5&maxSizeMini=1&currentPage=1&limit=25&startwith=0&totalSize=0&asc=true&connected=false&cacheStamp=755_1516274214060

Now use the enterprises link to get the enterprise data object.

curl -X GET https://example.com/api/admin/enterprises/2 \
     -H 'Accept:application/vnd.abiquo.enterprise+json; version=4.2' \
     -u user:password --verbose

From the enterprise, get the link to the enterprise limits.

        {
            "title": "limits",
            "rel": "limits",
            "type": "application/vnd.abiquo.limits+json",
            "href": "https://example.com:443/api/admin/enterprises/2/limits"
        },

Then perform a GET request to retrieve the limits. There is one limit for each datacenter or public cloud region that your enterrpise is allowed to use. This is because in the API, to allow an enterprise to use a datacenter, you create a datacenter limit for the enterprise.

So in this example, the enteprise is allowed to use a private cloud datacenter, called "BCDC" and a public cloud region, called "aws".

 Click here to expand...
{
    "links": [],
    "collection": [
        {
            "id": 5,
            "enabledHardwareProfiles": false,
            "links": [
                {
                    "title": "Tioco",
                    "rel": "enterprise",
                    "type": "application/vnd.abiquo.enterprise+json",
                    "href": "https://example.com:443/api/admin/enterprises/2"
                },
                {
                    "title": "edit datacenter limits 5",
                    "rel": "edit",
                    "type": "application/vnd.abiquo.limit+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5"
                },
                {
                    "title": "external networks",
                    "rel": "externalnetworks",
                    "type": "application/vnd.abiquo.vlans+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks"
                },
                {
                    "title": "virtualappliances",
                    "rel": "action",
                    "type": "application/vnd.abiquo.virtualappliances+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/action/virtualappliances"
                },
                {
                    "title": "BCDC",
                    "rel": "location",
                    "type": "application/vnd.abiquo.datacenter+json",
                    "href": "https://example.com:443/api/admin/datacenters/4"
                },
                {
                    "title": "Default Tier 1",
                    "rel": "tier",
                    "type": "application/vnd.abiquo.tier+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/storage/tiers/13"
                },
                {
                    "title": "Default Tier 2",
                    "rel": "tier",
                    "type": "application/vnd.abiquo.tier+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/storage/tiers/14"
                },
                {
                    "title": "Default Tier 3",
                    "rel": "tier",
                    "type": "application/vnd.abiquo.tier+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/storage/tiers/15"
                },
                {
                    "title": "Default Tier 4",
                    "rel": "tier",
                    "type": "application/vnd.abiquo.tier+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/storage/tiers/16"
                },
                {
                    "title": "Default Tier",
                    "rel": "datastoretier",
                    "type": "application/vnd.abiquo.datastoretier+json",
                    "href": "https://example.com:443/api/admin/datacenters/4/datastoretiers/4"
                }
            ],
            "diskSoftLimitInMb": 0,
            "diskHardLimitInMb": 0,
            "storageSoftInMb": 0,
            "storageHardInMb": 0,
            "vlansSoft": 0,
            "vlansHard": 0,
            "publicIpsSoft": 0,
            "publicIpsHard": 0,
            "repositorySoftInMb": 0,
            "repositoryHardInMb": 0,
            "ramSoft": 0,
            "ramHard": 0,
            "cpuSoft": 0,
            "cpuHard": 0
        },
        {
            "id": 6,
            "enabledHardwareProfiles": true,
            "links": [
                {
                    "title": "Tioco",
                    "rel": "enterprise",
                    "type": "application/vnd.abiquo.enterprise+json",
                    "href": "https://example.com:443/api/admin/enterprises/2"
                },
                {
                    "title": "edit datacenter limits 6",
                    "rel": "edit",
                    "type": "application/vnd.abiquo.limit+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/6"
                },
                {
                    "title": "external networks",
                    "rel": "externalnetworks",
                    "type": "application/vnd.abiquo.vlans+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/6/externalnetworks"
                },
                {
                    "title": "virtualappliances",
                    "rel": "action",
                    "type": "application/vnd.abiquo.virtualappliances+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/6/action/virtualappliances"
                },
                {
                    "title": "aws",
                    "rel": "location",
                    "type": "application/vnd.abiquo.publiccloudregion+json",
                    "href": "https://example.com:443/api/admin/publiccloudregions/5"
                },
                {
                    "title": "c1.medium",
                    "rel": "hardwareprofile",
                    "type": "application/vnd.abiquo.hardwareprofile+json",
                    "href": "https://example.com:443/api/admin/publiccloudregions/5/hardwareprofiles/12"
                },
.... Many hardware profiles cut from here ...
                {
                    "title": "t2.nano",
                    "rel": "hardwareprofile",
                    "type": "application/vnd.abiquo.hardwareprofile+json",
                    "href": "https://example.com:443/api/admin/publiccloudregions/5/hardwareprofiles/55"
                },
                {
                    "title": "t2.small",
                    "rel": "hardwareprofile",
                    "type": "application/vnd.abiquo.hardwareprofile+json",
                    "href": "https://example.com:443/api/admin/publiccloudregions/5/hardwareprofiles/9"
                }
            ],
            "diskSoftLimitInMb": 0,
            "diskHardLimitInMb": 0,
            "storageSoftInMb": 0,
            "storageHardInMb": 0,
            "vlansSoft": 0,
            "vlansHard": 0,
            "publicIpsSoft": 0,
            "publicIpsHard": 0,
            "repositorySoftInMb": 0,
            "repositoryHardInMb": 0,
            "ramSoft": 0,
            "ramHard": 0,
            "cpuSoft": 0,
            "cpuHard": 0
        }
    ]
}


Identify the limit for the datacenter you accessed in the previous steps, for example, here is the link identifying the datacenter within the limit. This limit has an ID with a value of "5".

                {
                    "title": "BCDC",
                    "rel": "location",
                    "type": "application/vnd.abiquo.datacenter+json",
                    "href": "https://example.com:443/api/admin/datacenters/4"
                },

For this limit, select the link to its external networks.

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

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

From the external networks object, find the link to IPs.

                {
                    "title": "ips",
                    "rel": "ips",
                    "type": "application/vnd.abiquo.externalips+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips"
                }, 

And perform a GET request to retrieve the IPs.

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
 Click here to expand...
{
    "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.

Create the virtualmachineflat data object

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

 Click here to expand...

The original link with a "rel" value of "edit".

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

        {
            "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"
        }

In the NICs section of the VM, add links to the VLAN. For example, for the external IP address, obtain the link with a "rel" value of "externalnetwork".

                {
                    "title": "External_network",
                    "rel": "externalnetwork",
                    "type": "application/vnd.abiquo.vlan+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7"
                },

And change the value of the "rel" attribute to "vlan"

                {
                    "title": "External_network",
                    "rel": "vlan",
                    "type": "application/vnd.abiquo.vlan+json",
                    "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7"
                },

And note the IP address you would like to add

            "ip": "192.168.7.2",

Edit the VM NIC(s) and add the link(s) to the "nics" - "collection" - "links" section for each NIC and the IP to the main section of each NIC after the tag value (don't forget the comma).

Finally your data object should be similar to the one in the following example.

 Click here to expand...
 {
    "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": []
}


Capture the virtual machine

To capture the VM machine, send a POST request to the virtualmachines URL of the virtual appliance that will hold the captured VM. Use the virtualmachineflat data transfer object that you created in the previous step as the data object.

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.

 Click here to expand...
{
    "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": []
}

If the request is successful, a 201 code should be returned, as well as the virtualmachineflat data object that was created.

 Click here to expand...
{
    "volumes": {
        "links": [],
        "collection": []
    },
    "disks": {
        "links": [],
        "collection": [
            {
                "id": 35,
                "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": [
                    {
                        "title": "bcdc_tioco_02",
                        "rel": "virtualdatacenter",
                        "type": "application/vnd.abiquo.virtualdatacenter+json",
                        "href": "https://example.com:443/api/cloud/virtualdatacenters/2"
                    },
                    {
                        "diskControllerType": "IDE",
                        "diskLabel": "",
                        "rel": "disk0",
                        "type": "application/vnd.abiquo.harddisk+json",
                        "href": "https://example.com:443/api/cloud/virtualdatacenters/2/disks/35"
                    },
                    {
                        "title": "disk",
                        "rel": "disk",
                        "type": "application/vnd.abiquo.disk+json",
                        "href": "https://example.com:443/api/admin/enterprises/2/datacenterrepositories/4/virtualmachinetemplates/110/disks/146"
                    },
                    {
                        "title": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
                        "rel": "virtualmachine",
                        "type": "application/vnd.abiquo.virtualmachine+json",
                        "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265"
                    },
                    {
                        "title": "Default Tier",
                        "rel": "datastoretier",
                        "type": "application/vnd.abiquo.datastoretier+json",
                        "href": "https://example.com:443/api/cloud/locations/4/datastoretiers/4"
                    }
                ]
            }
        ]
    },
    "nics": {
        "links": [],
        "collection": [
            {
                "id": 30,
                "ip": "192.168.7.2",
                "mac": "00:50:56:08:D5:73",
                "sequence": 0,
                "tag": 7,
                "links": [
                    {
                        "title": "00:50:56:08:D5:73",
                        "rel": "self",
                        "type": "application/vnd.abiquo.nic+json",
                        "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/network/nics/30"
                    },
                    {
                        "title": "192.168.7.2",
                        "rel": "edit",
                        "type": "application/vnd.abiquo.externalip+json",
                        "href": "https://example.com:443/api/admin/enterprises/2/limits/5/externalnetworks/7/ips/30"
                    },
                    {
                        "title": "External_network",
                        "rel": "externalnetwork",
                        "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": "ABQ_14c4aa8c-5ee4-49f5-b9e7-596e332d90a8",
            "rel": "edit",
            "type": "application/vnd.abiquo.virtualmachine+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265"
        },
        {
            "title": "send mail",
            "rel": "sendmail",
            "type": "application/vnd.abiquo.mail+json",
            "href": "https://example.com:443/api/admin/datacenters/4/racks/4/machines/2/virtualmachines/265/action/sendmail"
        },
        {
            "title": "Tioco",
            "rel": "enterprise",
            "type": "application/vnd.abiquo.enterprise+json",
            "href": "https://example.com:443/api/admin/enterprises/2"
        },
        {
            "title": "Cloud Administrator",
            "rel": "user",
            "type": "application/vnd.abiquo.user+json",
            "href": "https://example.com:443/api/admin/enterprises/2/users/1"
        },
        {
            "title": "bcdc_tioco_02",
            "rel": "virtualdatacenter",
            "type": "application/vnd.abiquo.virtualdatacenter+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2"
        },
        {
            "title": "vapp_vdc_tioco_02",
            "rel": "virtualappliance",
            "type": "application/vnd.abiquo.virtualappliance+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2"
        },
        {
            "title": "metadata",
            "rel": "metadata",
            "type": "application/vnd.abiquo.metadata+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/metadata"
        },
        {
            "title": "vlan network configurations",
            "rel": "configurations",
            "type": "application/vnd.abiquo.virtualmachinenetworkconfigurations+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/network/configurations"
        },
        {
            "title": "nics",
            "rel": "nics",
            "type": "application/vnd.abiquo.nics+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/network/nics"
        },
        {
            "title": "disks",
            "rel": "harddisks",
            "type": "application/vnd.abiquo.harddisks+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/storage/disks"
        },
        {
            "title": "ON",
            "rel": "state",
            "type": "application/vnd.abiquo.virtualmachinestate+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/state"
        },
        {
            "title": "virtual machine undeploy",
            "rel": "undeploy",
            "type": "application/vnd.abiquo.acceptedrequest+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/undeploy"
        },
        {
            "title": "virtual machine deploy",
            "rel": "deploy",
            "type": "application/vnd.abiquo.acceptedrequest+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/deploy"
        },
        {
            "title": "virtual machine reset",
            "rel": "reset",
            "type": "application/vnd.abiquo.acceptedrequest+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/reset"
        },
        {
            "title": "virtual machine snapshot",
            "rel": "instance",
            "type": "application/vnd.abiquo.acceptedrequest+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/instance"
        },
        {
            "title": "remote access",
            "rel": "rdpaccess",
            "type": "application/vnd.abiquo.virtualmachineconsole+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/config/rdpaccess"
        },
        {
            "title": "tasks",
            "rel": "tasks",
            "type": "application/vnd.abiquo.tasks+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/tasks"
        },
        {
            "title": "firewalls",
            "rel": "firewalls",
            "type": "application/vnd.abiquo.links+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/firewalls"
        },
        {
            "title": "load balancers",
            "rel": "loadbalancers",
            "type": "application/vnd.abiquo.loadbalancers+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/loadbalancers"
        },
        {
            "title": "request on demand backup",
            "rel": "requestbackup",
            "type": "application/vnd.abiquo.ondemandbackup+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/backup/action/request"
        },
        {
            "title": "request a restore of a backup",
            "rel": "requestrestore",
            "type": "application/vnd.abiquo.restore+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/backup/action/restore"
        },
        {
            "title": "relocate candidates",
            "rel": "relocatecandidates",
            "type": "application/vnd.abiquo.links+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/relocatecandidates"
        },
        {
            "title": "relocate",
            "rel": "relocate",
            "type": "application/vnd.abiquo.acceptedrequest+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/relocate"
        },
        {
            "title": "volumes",
            "rel": "volumes",
            "type": "application/vnd.abiquo.volumes+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/storage/volumes"
        },
        {
            "title": "protect",
            "rel": "protect",
            "type": "text/plain",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/protect"
        },
        {
            "title": "unprotect",
            "rel": "unprotect",
            "type": "text/plain",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/unprotect"
        },
        {
            "title": "metricsmetadata",
            "rel": "metricsmetadata",
            "type": "application/vnd.abiquo.metricsmetadata+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/metrics"
        },
        {
            "title": "enablemonitoring",
            "rel": "enablemonitoring",
            "type": "",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/enablemonitoring"
        },
        {
            "title": "collectd",
            "rel": "collectd",
            "type": "application/json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/metrics/collectd"
        },
        {
            "title": "alarms",
            "rel": "alarms",
            "type": "application/vnd.abiquo.alarms+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/alarms"
        },
        {
            "title": "actionplans",
            "rel": "actionplans",
            "type": "application/vnd.abiquo.virtualmachineactionplans+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/actionplans"
        },
        {
            "title": "actionplansflat",
            "rel": "actionplansflat",
            "type": "application/vnd.abiquo.virtualmachineactionplansflat+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/actionplans"
        },
        {
            "title": "clone",
            "rel": "clone",
            "type": "application/vnd.abiquo.virtualmachinecloneoptions+json",
            "href": "https://example.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/265/action/clone"
        },
        {
            "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_image",
            "rel": "virtualmachinetemplate",
            "type": "application/vnd.abiquo.virtualmachinetemplate+json",
            "href": "https://example.com:443/api/admin/enterprises/2/datacenterrepositories/4/virtualmachinetemplates/110"
        },
        {
            "title": "Others",
            "rel": "category",
            "type": "application/vnd.abiquo.category+json",
            "href": "https://example.com:443/api/config/categories/1"
        }
    ],
    "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": "CAPTURED",
    "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": []
}

Now Abiquo should display your VM as a managed VM and you should be able to find it in the virtual datacenter.

  • No labels