How to capture a remote virtual machine from a managed hypervisor

This tutorial describes how to capture a remote VM that is connected to a network not managed by Abiquo.

1. Prepare Abiquo to capture virtual machines

To prepare to capture a remote VM, first of all you need a physical machine from which you will capture the VM:

  1. Create the datacenter and rack, then add the physical machine

  2. Select Retrieve virtual machines.
    Screenshot: The platform marks the retrieved (or imported) VMs with the  symbol. 

     Imported VMs in the Virtual machines list for physical machine
    Imported VMs in the Virtual machines list for the physical machine

     

  3. Create the networks that the captured VM will be in. 
    For example, in the datacenter, create public or external networks with the same specifications as the VM networks.
    This means the same VLAN tag, network address, available IPs. 

     Create a network to match the VM network
    Create a network to match the VM network
  4. Create the IPs for your VMs in Abiquo 

  5. Create a virtual datacenter in the datacenter for your VM. 

  6. If you created a public network, you need to purchase public IPs for your virtual datacenter from the Network / Public tab.

  7. You will also need a virtual appliance. You can create it now or wait to do it as part of the capture process.

  8. Import the VMs from the physical machine. To do this, go to the datacenter, select the physical machine and click the Retrieve VMs from managed datastores button.

The platform will now display the VMs running on the hypervisor that are not managed by Abiquo. 

2. Capture the remote VM via GUI

Now you will capture the VM so that the platform can manage it.

  1. Select the VM you want to capture and click the Capture VM button.



  2. The GUI will then ask you for the virtual appliance to store the VM. Select your virtual appliance in the virtual datacenter with the network addresses purchased. If you didn't create a virtual appliance earlier, you can do so now by clicking the + add button.

  3. Check the General Information, on the Network tab, select the appropriate NICs and IP address, and check the Disks. 


    VM General information

    VM Network

  4. Accept the capture and the remote VM will be added to the virtual appliance and managed by Abiquo. 
    You can check the VM configuration on the details panel or when you edit the VM.
    The platform will now display the Release VM button instead of the Capture VM button. The Release VM button is a box with an arrow pointing outwards.

3. Capture a VM using the API

You can capture a VM using the API and once you get started, it's not such a daunting task as it might first seem!  A good working knowledge of the Abiquo API is required, but as always, if you get stuck, you can always open your browser console and take a look at how the Abiquo UI does it! 

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.

First be sure to do the preparatory steps and obtain the information about the VM and the environment that you will require to create the VM object.

Before you begin:

  • In Abiquo, determine the ID of:

    • The enterprise the VM will be captured for

    • The datacenter where it will be captured

    • The physical machine (hypervisor) where it will be captured from

  • In the hypervisor:

    • Check the VM name

    • Check the network details including the VLAN tag 

  • In the virtual machine

    • Check the IP addresses of the NICs

  • In Abiquo, create the following and make a note of the IDs:

    • The virtual datacenter that the VM will be captured into

    • The networks that the VM will belong to

    • The IP addresses for the VM in the networks

    • The virtual appliance that the VM will be captured into

To capture a VM using the API

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

    1. The POST to capture the VM is made to the virtual machines URL of the virtual appliance. 

      • It's not really necessary to get the whole virtual appliance, but by doing so, you can validate the link and check that you have the right virtual appliance!

  2. Retrieve the virtual machine with resources from the hypervisor in Abiquo

    1. You will modify this virtualmachineflat object to create the request payload for the POST request

  3. Retrieve network interfaces for configuration 

    1. You will need the network link and the IP address, to include them in the virtualmachineflat object

  4. Optionally retrieve a costcode object to add to the VM

  5. Modify the virtualmachineflat object

  6. Post the virtualmachineflat object to the virtual machines URL of the virtual appliance

3.1.
Retrieve virtual appliance

Using the virtual datacenter ID, retrieve all virtual appliances. See https://wiki.abiquo.com/api/latest/VirtualAppliancesResource.html#list-virtual-appliances

Then retrieve the virtual appliance that the VM will be captured into. 

curl --verbose -k -u admin:xabiquo -X GET "https://mjsabiquo.bcn.abiquo.com/api/cloud/virtualdatacenters/3/virtualappliances" -H "accept:application/vnd.abiquo.virtualappliances+json;version=4.7" | jq '.'

 

> GET /api/cloud/virtualdatacenters/3/virtualappliances HTTP/1.1 > Host: mjsabiquo.bcn.abiquo.com > Authorization: Basic YWRtaW46eGFiaXF1bw== > User-Agent: curl/7.54.0 > accept:application/vnd.abiquo.virtualappliances+json;version=4.7 > < HTTP/1.1 200 200 < Date: Mon, 18 Nov 2019 16:38:38 GMT < Server: Apache < Set-Cookie: ABQSESSIONID=6906893432497011639; Max-Age=1800; Expires=Mon, 18-Nov-2019 17:08:39 GMT; Path=/; Secure; HttpOnly < X-Abiquo-TracerContext: f4c925e1-4bc7-4470-91bf-03ee604e568e < X-Abiquo-Token: 9a5a5c937821bb44506d654af977b90ad97d4968e49bea58d699034a8a783416 < Content-Type: application/vnd.abiquo.virtualappliances+json; version=4.7 < Transfer-Encoding: chunked < { "totalSize": 1, "links": [ { "rel": "first", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances?limit=25&by=name&asc=true" }, { "rel": "last", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances?startwith=0&limit=25&by=name&asc=true" } ], "collection": [ { "id": 3, "error": 0, "highDisponibility": 0, "name": "vmware_vapp_01", "publicApp": 0, "state": "EMPTY", "restricted": false, "description": "Vapp", "notAllocatedVirtualMachines": 0, "onVirtualMachines": 0, "offVirtualMachines": 0, "pausedVirtualMachines": 0, "allocatedVirtualMachines": 0, "configuredVirtualMachines": 0, "unknownVirtualMachines": 0, "lockedVirtualMachines": 0, "links": [ { "title": "vmware_vapp_01", "rel": "edit", "type": "application/vnd.abiquo.virtualappliance+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3" }, { "title": "vmware_vdc_01", "rel": "virtualdatacenter", "type": "application/vnd.abiquo.virtualdatacenter+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3" }, { "title": "Abiquo", "rel": "enterprise", "type": "application/vnd.abiquo.enterprise+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/1" }, { "title": "virtual machines", "rel": "virtualmachines", "type": "application/vnd.abiquo.virtualmachines+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/virtualmachines" }, { "title": "virtual appliances state", "rel": "state", "type": "application/vnd.abiquo.virtualappliancestate+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/state" }, { "title": "undeploy", "rel": "undeploy", "type": "application/vnd.abiquo.acceptedrequest+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/action/undeploy" }, { "title": "deploy", "rel": "deploy", "type": "application/vnd.abiquo.acceptedrequest+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/action/deploy" }, { "title": "price", "rel": "price", "type": "text/plain", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/action/price" }, { "title": "layers", "rel": "layers", "type": "application/vnd.abiquo.layers+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/layers" }, { "title": "spec", "rel": "spec", "type": "application/vnd.abiquo.virtualappliancespec+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/action/spec" }, { "title": "tasks", "rel": "tasks", "type": "application/vnd.abiquo.tasks+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/tasks" }, { "title": "scalinggroups", "rel": "scalinggroups", "type": "application/vnd.abiquo.scalinggroups+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/scalinggroups" }, { "title": "metricsmetadata", "rel": "metricsmetadata", "type": "application/vnd.abiquo.metricsmetadata+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/metrics" }, { "title": "collectd", "rel": "collectd", "type": "application/json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/metrics/collectd" }, { "title": "alarmssearch", "rel": "alarmssearch", "type": "application/vnd.abiquo.alarms+json", "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/3/virtualappliances/3/alarms" } ] } ] }

3.2. Retrieve virtual machine from the hypervisor

Retrieve all the VMs from the hypervisor, using sync=true. Identify the required VM. Obtain a flat representation of the VM that includes the disks and network interface details (MAC address and sequence number).

curl --verbose -k -u admin:xabiquo -X GET "https://mjsabiquo.bcn.abiquo.com/api/admin/datacenters/2/racks/2/machines/3/virtualmachines/174?sync=true" -H "accept:application/vnd.abiquo.virtualmachineflat+json;version=4.7" | jq '.'

 

3.3. Retrieve network details and IP addresses

Retrieve IPs from the external network that are available in the datacenter and then retrieve the appropriate IP for the VM.

 

 

Retrieve IPs from the public network that have been purchased and are available to the virtual datacenter. Select and retrieve the appropriate public IP. To start with, first we used the "has" parameter to identify the required IP address.

Then we checked the ID of the purchased IP and retrieved only this IP.

 

3.4. Create virtualmachineflat data transfer object

Change the virtual machine links as follows.

Replace the "rel" link with a value of edit with two links with "rel" values of "virtualmachine" and "imported".

The original "rel" edit link.

The new links to replace it

In the nics section, add links to the vlans (with "rel" value of "vlan" and the "ip" attribute set to the IP address). 

Finally you should have a data object like the one contained in the following expanding section.

3.5. Optionally retrieve a cost code to add to the VM

You can optionally add a cost code to the VM as part of the capture process. You can use the "has" parameter to search for the cost code name, then retrieve the required cost code by ID.

Create a cost code link by changing "rel" link with a value of "edit" to "codecode". Here is an example link.

Add your link to the links section of the VM object. 

When you capture the VM, the platform adds the cost code to the temporary template that it creates, which has a link in the VM object returned by the capture. And when you create an instance to save the VM template to the Apps library, this template will have the cost code that you added to the VM. 

The platform will account the VM by its template cost code.

3.6. Capture the virtual machine

To capture the machine, send the virtualmachineflat data transfer object as part of a post request to the virtual machines URL of the virtual appliance that will hold the captured virtual machine.

Success status code: 201

Request payload:

Request data:

Response payload:

 

Copyright © 2006-2024, Abiquo Holdings SL. All rights reserved