How to capture a remote virtual machine from a managed hypervisor
This tutorial describes how to capture a remote VM hat is connected to a network not managed by Abiquo.
Prepare Abiquo to capture virtual machines
To capture a remote virtual machine first of all you need a physical machine from which you will capture the VM, so create the datacenter and rack, then add the physical machine.
Select Retrieve virtual machines. (Persistent VMs will not be retrieved because their system disks are located on external volumes. VMs that are already registered in Abiquo will not be retrieved).
Screenshot: A VM that has been imported is marked with the symbol.
Then you need to create the networks where the captured machine will be assigned. For example, you may need to create a public or external network in the datacenter with the same specification as the network that the NICs on the virtual machine are attached to (VLAN tag, network address, available IPs). And you should create the required IPs in Abiquo.
The last thing you need to do before capturing remote virtual machines is to create a virtual datacenter in this datacenter for your virtual machine. If you created a public network, you need to purchase public IPs for your virtual datacenter from the Network / Public tab. You can create a virtual appliance now or wait to do it as part of the capture process.
Now you will capture a remote virtual machine. First import machines from the physical machine. Go to the datacenter, select the machine and click on the "retrieve virtual machines" button.
Then you will see all the virtual machines on the hypervisor that are not managed by Abiquo.
Capture the remote virtual machine
Using the GUI
Select the virtual machine you want to capture and click the "capture virtual machine" button.
The GUI will then ask you for the virtual appliance to store the VM. Now select your virtual appliance created 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 + button.
Check the General Information, on the Network tab, select the appropriate NICs and IP address, and check Disks.
Accept the capture and the remote VM will be added to the virtual appliance and managed by Abiquo. This example showed the capture of a VM with two NICs and two hard disks and you can open the VM configuration to check them.
Using the API
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! 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
- Retrieve the virtual appliance the VM will be captured into
- The POST to capture the virtual machine 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!
- The POST to capture the virtual machine is made to the virtual machines URL of the virtual appliance.
- Retrieve the virtual machine with resources from the hypervisor in Abiquo
- You will modify this virtualmachineflat object to create the request payload for the POST request
- Retrieve network interfaces for configuration
- You will need the network link and the IP address, which will be included in the virtualmachineflat object
- Modify the virtualmachineflat object
- Post the virtualmachineflat object to the virtual machines URL of the virtual appliance
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 -u admin:xabiquo -X GET https://38testing.bcn.abiquo.com/api/cloud/virtualdatacenters/51/virtualappliances/292 -H accept:application/vnd.abiquo.virtualappliance+json;version=3.8
Retrieve virtual machine from the hypervisor
Retrieve all the virtual machines 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 -u admin:xabiquo -X GET https://38testing.bcn.abiquo.com/api/admin/datacenters/4/racks/4/machines/82/virtualmachines/2120?sync=true -H accept:application/vnd.abiquo.virtualmachinesflat+json;version=3.8
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.
curl --verbose -u admin:xabiquo -X GET https://38testing.bcn.abiquo.com:443/api/admin/enterprises/74/limits/40/externalnetworks/331/ips/4527
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.
curl --verbose -u admin:xabiquo -X GET https://38testing.bcn.abiquo.com/api/cloud/virtualdatacenters/95/publicips/purchased?has="10.10.10.2"
Then we checked the ID of the purchased IP and retrieved only this IP.
curl --verbose -u admin:xabiquo -X GET https://38testing.bcn.abiquo.com/api/cloud/virtualdatacenters/95/publicips/purchased/4502
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".
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.
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.
curl --verbose -u admin:xabiquo -X POST "https://38testing.bcn.abiquo.com/api/cloud/virtualdatacenters/95/virtualappliances/292/virtualmachines" \ -H "Content-Type:application/vnd.abiquo.virtualmachineflat+json;version=3.8" \ -H "Accept:application/vnd.abiquo.virtualmachineflat+json;version=3.8" \ -d @requestpayload.json
Success status code: 201
Request payload:
Request data:
Response payload: