API tips and tricks
- 1 Can I set the ID of a VM when I create it?
- 2 What can I do with this version?
- 3 Retrieve VMs
- 4 Find the default network connection and default gateway of a VM
- 5 Add a network interface card to a VM
- 6 Add a secondary hard disk to a VM
- 7 Create an enterprise
- 8 Modify VM template categories
- 9 Add a startup script to a VM via API
- 10 Search for users across all enterprises
- 11 Synchronize VDCs in multiple enterprises
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 |
---|---|---|---|
All users | api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines | All VMs in a virtual appliance | |
All users | api/cloud/virtualmachines | All VMs belonging to a user on the cloud path | |
All users | api/admin/virtualmachines | All VMs belonging to a user on the infrastructure path | |
Cloud administrators | api/admin/datacenters/1/racks/1/machines/1/virtualmachines | 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:
Retrieve the VM
Looking at the VM links, you will see:
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
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:
Retrieve the VM
Retrieve an available IP address from a network
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.
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:
Create the secondary hard disk
Attach it to the VM
See How to add a hard disk to a VM via API
Create an enterprise
To create an Enterprise:
Create an enterprise
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.
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