...
To obtain an authorization token, send a GET
request to the API login resource.
Use basic authentication and get the token from the X-Abiquo-Token
header.
Code Block |
---|
curl --verbose -X GET "https://abiquo.example.com:443/api/login" -u adminuser:password -k |
...
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 this example we have shortened the token. In the workflow below, we represent the token with {api_token}
.
...
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.
Replace the base_api_url
with the URL of your Abiquo API server, for example, https://abiquo.example.com/api
, and replace {api_token}
with the token from the X-Abiquo-Token
response header.
Here we use JQ to filter the API response to only display the enteprise enterprise names and IDs.
Code Block |
---|
curl -X GET '{base_api_url}/admin/enterprises?has=Abiquo' \ -H 'Accept: application/vnd.abiquo.enterprises+json;version=6.1' -k \ -H 'Authorization: Token {api_token}' \ | jq '.collection[]| {name: .name, id: .id}' |
...
If you are not already working with the selected enterprise, switch enterprise in the UI (by clicking the Switch enterprise button) or by switching enterprises via the API.
...
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.
Code Block |
---|
{ "title": "repositories", "rel": "datacenterrepositories", "type": "application/vnd.abiquo.datacenterrepositories+json", "href": "{base_api_url}/admin/enterprises/1/datacenterrepositories" } |
...
Code Block |
---|
curl -s -X GET '{base_api_url}/admin/enterprises/1/datacenterrepositories' \ -H 'Accept: application/vnd.abiquo.datacenterrepositories+json;version=6.1' -k \ -H 'Authorization: Token {api_token}' \ | jq '.collection[].links[]| select(.rel=="datacenter", .rel=="edit")' |
The JQ filter above will print the datacenter
and edit
links for each of the datacenter repositories.
...
Select the appropriate repo and then use the edit
link to get the datacenter repository and select 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.
...
Get the template that you wish to use. The template will contain a link to the template template’s disks.
Code Block |
---|
curl -s -X GET '{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72' \ -H 'Accept: application/vnd.abiquo.virtualmachinetemplate+json;version=6.1' -k \ -H 'Authorization: Token {api_token}' \ | jq '.links[] | select (.rel=="disks")' |
From the JQ filter in the above example, we got the following disk
link.
Code Block |
---|
{ "title": "disks", "rel": "disks", "type": "application/vnd.abiquo.disks+json", "href": "{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72/disks" } |
...
For the repository, you will need the diskUrl
and currentPath
of this disk. In the Abiquo API, these are the href
URL from the disk edit disk edit link
and the path
of thedisk
.
The above query and JQ filter returned the following.
Code Block |
---|
{ "title": "disk", "rel": "edit", "type": "application/vnd.abiquo.disk+json", "href": "{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72/disks/74" } { "sequence": 0, "path": "1/bundle/e05785d2-b49a-4034-9bb9-3440e1693589-4ba3b6e1-6f06-47d9-8703-9e9/4ba3b6e1-6f06-47d9-8703-9e9eae1c2a9b-snapshot-yVM2b8c91aa4-14b1-44a6-b27b-aa12c7ca3433-flat.vmdk" } |
You will need the “href” href
and the “path” path
for the replacement object!
...
From the above response, we need
the
href
URL from the disk disk in theedit link
the
path
of thedisk
From the example above, for the first disk with a sequence
a number
of "0
", we have the following.
Code Block |
---|
"href": "{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72/disks/74" "path": "1/bundle/e05785d2-b49a-4034-9bb9-3440e1693589-4ba3b6e1-6f06-47d9-8703-9e9/4ba3b6e1-6f06-47d9-8703-9e9eae1c2a9b-snapshot-yVM2b8c91aa4-14b1-44a6-b27b-aa12c7ca3433-flat.vmdk" |
...
From the above response, you will need to set the following
diskUrl
= thehref
URL from the disk edit linkcurrentPath
=path
To get the VM template URL, just remove the “disksdisks/
XX” XX
from the end of the diskUrl
!
Here is an example object.
Code Block | ||
---|---|---|
| ||
{ "virtualMachineTemplateUrl":"{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72", "diskUrl":"{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72/disks/74", "currentPath":"1/bundle/e05785d2-b49a-4034-9bb9-3440e1693589-4ba3b6e1-6f06-47d9-8703-9e9/4ba3b6e1-6f06-47d9-8703-9e9eae1c2a9b-snapshot-yVM2b8c91aa4-14b1-44a6-b27b-aa12c7ca3433-flat.vmdk", "diskController": "lsilogic", "diskControllerType": "SCSI", "diskFileFormat":"VMDK_STREAM_OPTIMIZED", "diskFilePath": "", "label": "Hard disk 1", "requiredHDInMB":120, "sequence":0 } |
Note |
---|
For the " See Determine the size of a VM disk file Abiquo does not validate the value that you enter and if you enter an incorrect value, the platform will try to deploy the disk with its true capacity. The deploy may fail and the platform will not be able to properly check that the disk will fit on the hypervisor datastore. Important note: You cannot resize (expand) a boot disk before you deploy a VM. After you expand any disk, remember to update the configuration of the disk in the VM operating system. |
...
Note |
---|
The default value for the If your template uses a different controller type and value, such as " You should note that the AM API does not support all of the values that are supported by the Abiquo API. |
...
Warning |
---|
If your file name or folder name contains spaces, do the steps below in “Steps for folder names with spaces” and “Steps for file names with spaces” to obtain the folder path, file name and URL |
...
For template folder, from our example with the following “href” href
and “path” path
:
Code Block |
---|
"href": "{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72/disks/74" "path": "1/bundle/e05785d2-b49a-4034-9bb9-3440e1693589-4ba3b6e1-6f06-47d9-8703-9e9/4ba3b6e1-6f06-47d9-8703-9e9eae1c2a9b-snapshot-yVM2b8c91aa4-14b1-44a6-b27b-aa12c7ca3433-flat.vmdk" |
...
So the full URL to post to will be template path containing the prefix “ /am/erpos/{enterpriseId}/templates
and the folder path
Code Block |
---|
/am/erepos/1/templates/1/bundle/e05785d2-b49a-4034-9bb9-3440e1693589-4ba3b6e1-6f06-47d9-8703-9e9 |
Tip |
---|
The template path does not contain the ID of the datacenter repository. It contains the folder name from |
Info |
---|
If the original disk file is not available, you can create a placeholder file in the folder using the touch command, in the format touch |
...
The template folder is the folder path
on the NFS Repository, without the file name.
So for a folder name with spaces, for example, “abc def” abc def
.
We would have the following “href” href
and “path” path
:
Code Block |
---|
"href": "{base_api_url}/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/72/disks/74" "path": "1/bundle/abc%20def/olddisk-flat.vmdk" |
...
We recommend that you use double quotation marks around all the parameters, including the file parameters for diskInfo
and diskFile
.
Code Block |
---|
curl -v -k -X POST '{base_url_NO_API}/am/erepos/1/templates/1/bundle/e05785d2-b49a-4034-9bb9-3440e1693589-4ba3b6e1-6f06-47d9-8703-9e9' \ -H 'Authorization: Token {api_token}' \ -F "diskInfo=@diskReplace.json" -F "diskFile=@newdisk.vmdk" |
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 calleddiskReplace.json
. This is the real data object from our example.
...
Use double quotation marks around all the parameters, including the file parameters for diskInfo
and diskFile
, especially if the disk file name contains spaces!
...
You can check the disk file in Abiquo UI, which will display the path
and file size
.
...
You can also go to the datacenter repository on the NFS share (in the /opt/vm_repository
folder) and check the new disk file on the file system using the details in the Location
link in the above response.
...
Note that if the disk file had spaces, it would display with “+
” marks signs in the file name, for example:
...
Which for our disk, shows the newdisk.vmdk
file has been loaded into Abiquo.
...