API tips and tricks

This document gives some basic tips about working with the Abiquo API

Can I set the ID of a VM when I create it?

When you create an entity, the ID is created automatically by Abiquo. Therefore, you should always remove the "id" attribute from an example template before creating an entity. This also applies to other attributes that are automatically assigned in Abiquo. In general, the attributes you can set in the UI can also be set in the API and differences may be noted in the User Guide or Developer's Guide.

What can I do with this version?

The links that can be found in each entity provide a general guide to the API calls that you can make in relation to that entity. 

A list of all the resources and methods with media types is provided by the Wink admin console. It can be found by sending a GET request using the options ?doc=registry, for example.

https://<apiIPaddress>/api/console?doc=registry

Retrieve VMs

There are many paths you can use to retrieve VMs with the Abiquo API, for example:

User

Link

API docs

Notes

User

Link

API docs

Notes

All users

api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines

VirtualMachinesResource.html

All VMs in a virtual appliance

All users

api/cloud/virtualmachines

AllVirtualMachinesResource.html

All VMs belonging to a user on the cloud path

All users
cloud administrators

api/admin/virtualmachines

VirtualMachinesAdminResource.html

All VMs belonging to a user on the infrastructure path
The UI uses this link for infrastructure Alarms

Cloud administrators

api/admin/datacenters/1/racks/1/machines/1/virtualmachines

VirtualMachinesInfrastructureResource.html

All VMs deployed on physical machine

Find the default network connection and default gateway of a VM

To find the default network connection and the default gateway of a VM:

  1. Retrieve the VM

  2. Looking at the VM links, you will see:

    1. a link to /network/configurations, which is the group of all the networks that the VM is attached to

      • Note that each of these network configurations has a number

    2. a link (if present) to /network/configuration/X, which is the default network configuration of the VM

      • The VM's default gateway is the gateway of this network

Add a network interface card to a VM

To add a NIC to a VM:

  1. Retrieve the VM

  2. Retrieve an available IP address from a network

  3. Copy the "self" link of the IP address and edit it to contain "nic" and the appropriate sequence number, for example, nic0 for the first NIC, nic1 for the second, and so on.

  4. Update the VM with a put request

See How to add a NIC to a VM via API

Add a secondary hard disk to a VM

When you create a secondary hard disk in the Abiquo UI, it is automatically attached to the VM. This is not the case in the Abiquo API, where hard disks are created for virtual datacenters and attached to VMs.

To add a secondary hard disk on the hypervisor datastore to a VM in the Abiquo API:

  1. Create the secondary hard disk

  2. Attach it to the VM

See How to add a hard disk to a VM via API

Create an enterprise

To create an Enterprise:

  1. Create an enterprise

  2. Create an enterprise-datacenter limit

It is essential to create the limit to allow the tenant's users to access a datacenter. Otherwise you will not be able to use the enterprise. This is the same as in the UI, where you  must assign an allowed datacenter to an enterprise before you can use it.

See Create tenants via API

Modify VM template categories

If you have the "Administer all enterprises" privilege, you can use the API to change a category from  local  to  global  if there is no global category with the same name. You cannot move a local category from one enterprise to another or change a category from global to local.

Add a startup script to a VM via API

To add a startup script to a VM via API, find the VM link to metadata, and send a GET request to retrieve existing metadata. Then add the "startup-script" key with the script, and send a PUT request to the metadata link. 

See Manage virtual machine metadata via API

Search for users across all enterprises

To search for users across all enterprises:

  • use the "_" underscore character as the enterprise ID in the URL

  • use the "has" query parameter to filter the results by a text string

For example, https://nardo40.bcn.abiquo.com:443/api/admin/enterprises/_/users?has=entadmin

Synchronize VDCs in multiple enterprises

In integrations, to update the platform's data about VDCs in an enterprise without logging in to or switching to each enterprise, you can send an enterprise link in a links object as the body of a POST request to synchronize the remote virtual datacenters in a location. This means that Abiquo will use the linked enterprise instead of the user's enterprise to synchronize the VDCs with public cloud.

{ "links": [ { "rel": "enterprise", "href": "https://nardo40ptv.lab.abiquo.com:443/api/admin/enterprises/418" } ] }

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