Upload and replace template disks via API

 

1. Introduction 

This document describes how to upload and replace existing template disks using the Appliance manager API.

Use case

Use this process to replace a template disk directly in the repository file system and ensure that Abiquo has the correct template details for the new disk.

  • This request requires direct access to the Appliance Manager API

  • The Appliance Manager API does not validate the request, so be sure to provide the correct path to your disk file or you could overwrite some other part of your file system!!

Here is an example use case

  1. Upload or download a template

  2. Use it to create a VM 

  3. Update the template.  Abiquo supports changes to:

    1. file content

    2. size

    3. format

    4. capacity

    5. controller

    Update the disk using the Appliance manager API.

  4. When the user next deploys the VM, the platform will copy the updated disk


 

Basic steps

  1. Get the template details from the Abiquo API

  2. Create the replacement data object

  3. Replace the file using the Appliance manager API

 


2. Send a GET request to the API login resource to obtain an authorization token

If you wish to use token authentication, which is more secure and required for 2FA, do these steps.

Use basic authentication and get the token from the X-Abiquo-Token header.

curl --verbose -X GET "https://abiquo.example.com:443/api/login"-u adminuser:password -k | jq .

Or if you are using 2FA, you can get the 2FA verification code in the usual way (by email or from Google Authenticator).

Log in again and send the 2FA verification code.

curl --verbose -X GET "https://abiquo.example.com:443/api/login" "-H "X-Abiquo-OTP: your2FAcode" | jq .

Now you can get the token from the X-Abiquo-Token header of the response.

In your API requests, use the token in a header with the following format. In these examples we have shortened the token to make the requests easier to read.

-H 'Authorization: Token a2e19816735381c1d074441cbd002aa01f9ed7dc4cd9f4e0683c3c88...'

For more details, see Authentication.

You can also get the token from the UI! Go to the browser Developer console on the Network tab and in the request responses look for the X-Abiquo-Token header.




3. Get the template details

Get the enterprise, for example, by using the "has" parameter to filter by a text string in the enterprise names from the list enterprises request.

https://wiki.abiquo.com/api/latest/EnterprisesResource.html#list-enterprises

If you are not already working with this enterprise, switch enterprise by updating the user from any enterprise (underscore character) to the new enterprise.

https://wiki.abiquo.com/api/latest/UsersResource.html#update-a-user-of-an-enterprise

Get the link to the enterprise's datacenter repository for the appropriate datacenter. The link to the datacenter repositories can be found in the Enterprise entity.

From this link you can get the datacenter repositories.

https://wiki.abiquo.com/api/latest/DatacenterRepositoriesResource.html#list-datacenter-repositories

Select the appropriate repo and then get the link to the virtual machine templates.

Get the templates, and find the appropriate template. You can use the "has" parameter to search for the template by name.

https://wiki.abiquo.com/api/latest/VirtualMachineTemplatesResource.html#list-virtual-machine-templates-in-a-datacenter-repository

The template will contain a link to the template disks.

Get the template disks, and find the disk you wish to replace.

Get the  diskUrl  and  currentPath  of the disk.

Response payload:






4. Create the replacement object

From the above response, we need

  • the href URL from the disk edit link

  • the path of the disk

From the example above, for the first disk with sequence a number of "0", we have the following.



diskReplace.json

From the above response, the URL from the disk edit link is used as the diskUrl and the path is used as the currentPath in the JSON request payload to modify the template object. 

Here is an example object.










5. Replace the file

Replace the file using the Appliance manager API.

The URL to post to contains the enterprise ID and the template folder in the following format.

The template folder is the folder path on the NFS Repository, without the file name. For our example:

The folder path is as follows:





Use this information to build the request to replace the disk.



cURL

Replace newdisk.vmdk  with the name of your disk file on the local file system.

Save the disk replacement object you created previously to a file called diskReplace.json

Example request:

Success status code: 201 Created






6. Check the disk file

You can check the new disk file on the file system using the details in the Location link in the above response.

And in this case, we retrieved the template disks and checked the details of the disk file in the API.



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