Table of Contents |
---|
Introduction
This tutorial continues on from Get Started with the Abiquo API!
This tutorial requires two VMs that are undeployed without any network interfaces.
To continue working with the same VM that you deployed in the last tutorial, you will need to undeploy the VM and delete its NIC, which you can easily do with the Abiquo UI. Or you can create a new VM for this tutorial.
Modify an entity using the API
Because the VM entity is a special case, we are going to look at two types of modifications: configuring a VM and changing the state of a VM.
But for most entities you can simply retrieve a data object with a GET request, modify the data object, and then perform a PUT request.
Warning |
---|
Links do more than just take you to related objects–they also define the configuration of a VM. When you edit the data object, take care not to accidentally remove any links because you could accidentally remove a disk or a NIC or perform some other unintended action! |
To add a NIC to the VM, we are going to first perform the steps using the UI, in order to obtain information about the data object.
Configure the VM to add a NIC using the UI
We will add a network interface card (NIC) with an IP address in a private network to the first VM we created. In this case, we will assume that the VM is not deployed.
- Open the browser console to the Network tab and record actions
- Edit the VM and go to Network → Private → select network → drag an IP address into the NICs panel, and Save
- Examine the PUT request and look for the link to the NIC in the expanded VM response. It will probably be at the end of the links section.
Tip | ||
---|---|---|
| ||
If your VM has been deployed, then it will already have a NIC. To work with a deployed VM, you may need to create another private network, because by default, you may not be able to add two NICs in the same private network. To change the configuration of a deployed VM, if the VM doesn't have network hot-reconfigure, then you will need to shut it down first. |
At the top of the Request Payload section, click "view source". Copy the source, format it, and select the link to the NIC and copy it. After formatting, it will look something like this.
Code Block |
---|
{
"title":"privateip",
"rel":"nic0",
"type":"application/vnd.abiquo.privateip+json",
"href":"https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips/18020"
} |
We will use this type of NIC link in the next step.
Add a NIC to the VM using the API
Now we are going to add a NIC to the second VM. To do this, we need to identify the second private IP that we created for this tutorial.
So we perform a GET request to retrieve all the IP addresses on the same network used above.
We will use the part of the URL that refers to the IPs of the private network, which just the IP link without the id of the IP as shown here.
Code Block |
---|
https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips |
You could perform a curl request from the command line, for example.
Code Block |
---|
curl --verbose 'https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips' \
-H 'Accept: application/vnd.abiquo.privateips+json; version=5.0' \
-u user:password -k | jq . |
In our response body, there are 3 IP addresses: the gateway and two IP addresses we created specifically for this exercise.
...
Code Block |
---|
user@user $ curl --verbose 'https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips' \
-H 'Accept: application/vnd.abiquo.privateips+json; version=5.0' \
-u user:password -k | jq .
* Connected to nardo40.bcn.abiquo.com (10.60.11.9) port 443 (#0)
* Server auth using Basic with user 'user'
> GET /api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips HTTP/1.1
> Host: nardo40.bcn.abiquo.com
> Authorization: Basic blahblahblah
> User-Agent: curl/7.64.1
> Accept: application/vnd.abiquo.privateips+json; version=5.0
>
< HTTP/1.1 200 200
< Date: Wed, 29 Jul 2020 15:11:46 GMT
< Server: Apache
< Set-Cookie: ABQSESSIONID=2853985954862764381; Max-Age=1800; Expires=Wed, 29-Jul-2020 15:41:47 GMT; Path=/; Secure; HttpOnly; SameSite=strict
< X-Abiquo-TracerContext: 211b2da1-897b-4cf3-a8c2-828a400ff388
< X-Abiquo-Token: a2e19816735381c1d074441cbd002aa01fff4b1659f8c90ac4235e1318874499cf18ee6a802e0b9484df51ffa5c9fcb9ff18fc48dd1a90c7dafdb2e557d0293e
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< Strict-Transport-Security: max-age=31536000 ; includeSubDomains
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: DENY
< X-Content-Type-Options: nosniff
< Content-Type: application/vnd.abiquo.privateips+json; version=5.0
< Transfer-Encoding: chunked
<
{
"totalSize": 3,
"links": [
{
"rel": "first",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips?limit=25&by=ip&asc=true"
},
{
"rel": "last",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips?startwith=0&limit=25&by=ip&asc=true"
}
],
"collection": [
{
"id": 18014,
"ip": "192.168.0.1",
"mac": "00:50:56:1D:5E:DE",
"name": "0050561D5EDE_host",
"networkName": "default_private_network",
"ipv6": false,
"quarantine": false,
"available": true,
"links": [
{
"title": "default_private_network",
"rel": "privatenetwork",
"type": "application/vnd.abiquo.vlan+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490"
},
{
"title": "privateip",
"rel": "self",
"type": "application/vnd.abiquo.privateip+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips/18014"
},
{
"title": "vdc_api_tutorial",
"rel": "virtualdatacenter",
"type": "application/vnd.abiquo.virtualdatacenter+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486"
}
]
},
{
"id": 18020,
"ip": "192.168.0.2",
"mac": "00:50:56:19:71:96",
"name": "005056197196_host",
"networkName": "default_private_network",
"ipv6": false,
"usedBy": "ABQ_e73648be-81bc-49ba-b78f-041072bc74c8",
"quarantine": false,
"available": true,
"links": [
{
"title": "default_private_network",
"rel": "privatenetwork",
"type": "application/vnd.abiquo.vlan+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490"
},
{
"title": "privateip",
"rel": "self",
"type": "application/vnd.abiquo.privateip+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips/18020"
},
{
"title": "vdc_api_tutorial",
"rel": "virtualdatacenter",
"type": "application/vnd.abiquo.virtualdatacenter+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486"
},
{
"title": "vap_api_tutorial",
"rel": "virtualappliance",
"type": "application/vnd.abiquo.virtualappliance+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990"
},
{
"title": "ABQ_e73648be-81bc-49ba-b78f-041072bc74c8",
"rel": "virtualmachine",
"type": "application/vnd.abiquo.virtualmachine+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19453"
}
]
},
{
"id": 18027,
"ip": "192.168.0.3",
"mac": "00:50:56:31:8A:DD",
"name": "005056318ADD_host",
"networkName": "default_private_network",
"ipv6": false,
"quarantine": false,
"available": true,
"links": [
{
"title": "default_private_network",
"rel": "privatenetwork",
"type": "application/vnd.abiquo.vlan+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490"
},
{
"title": "privateip",
"rel": "self",
"type": "application/vnd.abiquo.privateip+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips/18027"
},
{
"title": "vdc_api_tutorial",
"rel": "virtualdatacenter",
"type": "application/vnd.abiquo.virtualdatacenter+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486"
}
]
}
]
} |
In the above example, the IP that is being used on a VM has a link to the VM.
Hint: to only retrieve IPs that are available for use, you can use the query parameter "free=true", as follows.
Code Block |
---|
https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips?free=true |
The available IP that we will use has the identifier "18027".
And the link we need from this IP object is the link with a "rel" value of "self".
Code Block |
---|
{
"title": "privateip",
"rel": "self",
"type": "application/vnd.abiquo.privateip+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips/18027"
}, |
To add it to the VM, we just need to change "self" to "nicX", where "X" represents the number of the new NIC in the VM. So if there are no NICs on the machine, we will add "nic0" as shown here.
Code Block |
---|
{
"title": "privateip",
"rel": "nic0",
"type": "application/vnd.abiquo.privateip+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips/18027"
}, |
Remember that when you add this NIC to the end of the links section, you must add a comma first, after the previous item. And as this will be the last link, remember to remove the comma after it.
So here is an example of the request body that would be used to update our second VM, with the nic0 link at the end of the links section.
...
Table of Contents |
---|
Introduction
This tutorial continues on from Get started with the Abiquo API.
In this tutorial, you will use the Abiquo API to do the following.
Configure a VM by adding an IP address (NIC)
Delete a VM
There is also a link to another section that describes how to power cycle a VM.
...
Requirements
This tutorial requires two VMs that are:
Not deployed
Have no IP addresses (NICs)
You will also need 2 free IP addresses in private networks in the virtual datacenter with the VMs.
To use VMs from the previous tutorial, in the UI undeploy it and delete its IP address.
Tip |
---|
Working with Deployed VMs A deployed VM must always have a NIC. If you want to add another NIC, you may need to create another network to avoid trying to add two IP addresses in the same network. To change the configuration of a deployed VM, if the VM doesn't have network hot-reconfigure, then you will need to shut it down first. |
...
Get and modify an entity using the API
In general, to modify an entity using the Abiquo API, do these steps.
Use a
GET
request to retrieve the entity's data objectModify the data object
Use a
PUT
request to update the entity
Note |
---|
Within a data object, links can define an entity's configuration. When you edit the VM data object, be careful not to accidentally delete links because you could change the configuration, such as by deleting a disk from your VM! |
...
Configure a VM to add a NIC using the UI
First perform the action using the Abiquo UI, to view the API request that the UI makes.
To the first VM, which is not deployed, add a network interface card (NIC) with an IP address in a private network.
Open the browser console to the Network tab and record actions
Edit the VM and go to Network → Private
Select the network and drag an IP address into the NICs panel, and Save the VM
Find the
PUT
request and copy it, or get thenic
link and VM data object
...
Obtain the link to the NIC
In the VM object, find the link to the NIC (with a rel
attribute with a value of nic1
near the end of the VM links section.
Code Block |
---|
{ "title":"privateip", "rel": " enterprisenic1", "type": "application/vnd.abiquo. enterprise+json",
"href": "https://nardo40.bcn.abiquo.com:443/api/admin/enterprises/336"
},
{
"title": "ABQ_2fb11009-8157-4d61-915d-40fa45f440ac",privateip+json", "rel href":"edit", "https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips/11""type": "application/vnd.abiquo.virtualmachine+json", "href": "https://nardo40.bcn.abiquo }, |
...
Get an IP address to add to the VM
To find a free IP address:
From the link to the NIC in the previous step, get only the networks IPs link
Code Block https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips
Use a GET request to obtain the first 3 IP addresses in this network, and add the query parameter
limit
with a value of3
Code Block curl --verbose 'https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters
...
/
...
12/
...
privatenetworks/
...
9/ips?limit=3' \
...
-H 'Accept:
...
application/vnd.abiquo.privateips+json; version=6.1' \ -u user:password -k | jq .
To retrieve IPs that are available for use only, use the query parameter
free
with a value oftrue
The response has 3 IP addresses: the gateway and the IP addresses we created specifically for this exercise.
Code Block √ ~ % curl --verbose -k 'https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/
...
privatenetworks/9/ips?limit=3' \ -H 'Accept: application/vnd.abiquo.privateips+json; version=6.1' \
...
-u user:password |
...
jq .
...
> GET /api/cloud/virtualdatacenters/12/privatenetworks/9/ips?limit=3 HTTP/1.1 > Host: abiquo.lab.example.com > Authorization: Basic XXXXXX > User-Agent: curl/7.88.1 > Accept: application/vnd.abiquo.
...
privateips+json; version=6.1 > < HTTP/1.1 200 200 < Date: Wed, 07 Jun 2023 13:54:46 GMT < Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips < Set-Cookie: ABQSESSIONID=5848743475559326145; Max-Age=1800; Expires=Wed, 07-Jun-2023 14:24:46 GMT; Path=/; Secure; HttpOnly; SameSite=strict < X-Abiquo-TracerContext: c2b1df27-14c5-4e28-917d-f793d7dc3a71 < X-Abiquo-Token: XXXXXX < Cache-Control: no-cache, no-store, max-age=0, must-revalidate < Pragma: no-cache < Expires: 0 < Strict-Transport-Security: max-age=31536000 ; includeSubDomains < X-XSS-Protection: 1; mode=block < X-Frame-Options: DENY < X-Content-Type-Options: nosniff < Content-Type: application/vnd.abiquo.privateips+json; version=6.1 < Transfer-Encoding: chunked < { "totalSize": 4, "
...
links":
...
[
...
{
...
"
...
rel": "
...
first", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters
...
/12/privatenetworks/9/ips?limit=3&by=ip&asc=true" }, { "rel": "
...
next", "href": "
...
https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips?startwith=3&limit=3&by=ip&asc=true" },
...
{ "
...
rel": "
...
last", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/12/
...
privatenetworks/
...
9/ips?startwith=1&limit=3&by=ip&asc=true" } ], "collection": [ { "id": 8,
...
"ip": "192.168.0.1", "
...
mac": "
...
00:50:56:2F:D8:F3", "
...
name": "
...
0050562FD8F3_captured", "
...
networkName": "
...
default_private_network", "
...
ipv6": false,
...
"quarantine": false,
...
"available": true, "links": [ { "title": "
...
default_private_network", "rel": "
...
privatenetwork", "type": "application/vnd.abiquo.
...
vlan+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12/
...
privatenetworks/9" }, { "title": "
...
privateip", "rel": "
...
self", "type": "application/vnd.abiquo.
...
privateip+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12/
...
privatenetworks/
...
9/
...
ips/8" }, { "title": "
...
vdcbcdc", "rel": "
...
virtualdatacenter", "type": "application/vnd.abiquo.
...
virtualdatacenter+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12" } ] }, { "
...
id":
...
11, "
...
ip": "
...
192.168.0.2", "
...
mac": "
...
00:50:56:1A:2E:18", "
...
name": "
...
0050561A2E18_captured",
...
...
"networkName": "default_private_network",
...
"
...
ipv6":
...
false, "
...
usedBy": "
...
1979e77f-32b1-430d-9b92-9f6347dbd416", "
...
quarantine":
...
false, "
...
available": true, "links": [
...
{ "title":
...
"default_private_network", "rel": "
...
privatenetwork", "type": "application/vnd.abiquo.
...
vlan+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12/
...
privatenetworks/9" }, { "title": "privateip"
...
,
...
...
"rel": "
...
self", "type": "application/vnd.abiquo.
...
privateip+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12/
...
privatenetworks/
...
9/
...
ips/11" }, { "title": "vdcbcdc"
...
,
...
...
"rel": "
...
virtualdatacenter", "type": "application/vnd.abiquo.
...
virtualdatacenter+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12" }, {
...
"title": "
...
vapbcdc", "rel": "
...
virtualappliance", "type": "application/vnd.abiquo.
...
virtualappliance+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12/virtualappliances/
...
4" }, { "title": "
...
vmapihowto", "rel": "
...
virtualmachine", "type": "application/vnd.abiquo.
...
virtualmachine+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12/virtualappliances/
...
4/virtualmachines/
...
304" }
...
]
...
},
...
{ "
...
id":
...
12, "
...
ip": "
...
192.168.0.3", "
...
mac": "
...
00:50:56:18:63:13",
...
...
"name": "005056186313_host", "
...
networkName": "
...
default_private_network", "
...
ipv6":
...
false, "
...
quarantine":
...
false, "
...
available":
...
true, "links": [
...
{
...
"title": "default_private_network", "rel": "
...
privatenetwork", "type": "application/vnd.abiquo.
...
vlan+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12/
...
privatenetworks/9" }, { "title": "
...
privateip",
...
...
...
...
...
...
"rel": "
...
self", "type": "application/vnd.abiquo.
...
privateip+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud
...
/virtualdatacenters/12/privatenetworks/9/ips/12" }, { "title": "vdcbcdc"
...
,
...
...
...
...
...
...
"rel": "
...
virtualdatacenter", "type": "application/vnd.abiquo.
...
virtualdatacenter+json", "href": "https://
...
abiquo.
...
lab.
...
example.com:443/api/cloud/virtualdatacenters/
...
12"
...
...
}
...
] }
...
] }
In the above example, the NIC for the IP address of 192.168.0.2
is the one that we just added to the VM called vmapihowto
and it has a link to the VM.
The available IP address of 192.168.0.3
is the one we will use, and it has an ID of 12
.
Create a NIC link
From the IP address object in the above step, get the link with a rel
attribute that has a value of self
.
Code Block |
---|
{ "title": "volumes privateip", "rel": "volumes self", "type": "application/vnd.abiquo.volumes privateip+json", "href": "https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/cloud/virtualdatacenters/2486 12/virtualappliances privatenetworks/2990 9/virtualmachines/19454/storage/volumes" ips/12" }, |
To prepare it for the VM, change the rel
attribute from a value of self
to nicX
, where X
represents the number of the new NIC in the VM. So if there are no NICs, add nic1
as shown here.
Code Block |
---|
{{"diskAllocation": "THIN", " diskControllerTypetitle": "IDE privateip", "diskLabel rel": "Hard nic1",disk 1", " lengthtype": "64 application/vnd.abiquo.privateip+json", "title href": "4ffdcc26-6b30-47db-99b7-20bccbe285ea", "rel": "disk0", https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips/12""type": "application/vnd.abiquo.harddisk+json", "href": "https://nardo40.bcn.abiquo }, |
...
Add the NIC link to the VM object
Get the VM object that you created using the API in the first part of this tutorial.
To get the VM entity again, you can send a GET
request to the cloud/virtualmachines
link.
In this case, we are using a vmname
query parameter to filter on the number 2
in the VM name to only retrieve the VM from the first part of the tutorial.
Code Block |
---|
√ ~ % curl --verbose 'https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/2486/disks/18018" }, { "title": "datastoretierESXI6.0_2.29", virtualmachines?vmname=2' \"rel": "datastoretier0", -H 'Accept: application/vnd.abiquo.virtualmachines+json; version=6.1' \ -u"type": "application/vnd.abiquo.datastoretier+json", "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/locations/1/datastoretiers/58" }, { user:password -k | jq . |
This request returns a collection of VMs, so you will need to select the individual VM from the collection.
In the VM object, go the end of the links
section and add the NIC link from the previous step.
If this is the last link, remember to add a comma before it, and remove any comma after it.
This is an example of a modified VM object, with the nic1
link at the end of a shortened links
section. We shortened the links
section to make the example more readable
Code Block |
---|
{ "id": 305, "title uuid": "protect eb613c22-ffa1-4498-827a-ccaf37385c2e", "rel fqdn": "protect box.localdomain", "type description": "text/plain A virtual machine", "href coresPerSocket":"https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/action/protect" 1, "idState":} 1,{ "idType": 0, "title type": "unprotect MANAGED", "rel highDisponibility": 0, "unprotect monitored": false, "type monitoringLevel": "text/plain DEFAULT", "href protected":"https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/action/unprotect" false,}, "variables": {}, "title backuppolicies":"metricsmetadata" [], "rel lastSynchronize":"metricsmetadata" 1686046081000, "type generateGuestInitialPassword":"application/vnd.abiquo.metricsmetadata+json" false, "href natrules":"https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/metrics" [],}, {"vdrpEnabled": true, "title vdrpPort":"enablemonitoring" 0, "rel password": "enablemonitoring 6t51rgZ9", "type deallocated":"" false, "href name": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/enablemonitoring" vmapihowto2",}, {"ram": 48, "title cpu":"collectd" 1, "rel state": "collectd NOT_ALLOCATED", "type creationTimestamp":"application/json" 1686042455000, "href": birthTimestamp"https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/metrics/collectd" : 1686045726000, "links": [}, { "title": "alarmssearch Abiquo", "rel": "alarmssearch enterprise", "type": "application/vnd.abiquo.alarms enterprise+json", "href": "https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/cloud admin/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454/alarms" enterprises/1" }, { "title": "clone vmapihowto2", "rel": "clone edit", "type": "application/vnd.abiquo.virtualmachinecloneoptions virtualmachine+json", "href": "https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/cloud/virtualdatacenters/2486 12/virtualappliances/2990 4/virtualmachines/19454/action/clone" 305" }, ... { "title": "VMware vCenter Cluster", "rel": "hypervisortype", "type": "application/vnd.abiquo.hypervisortype+json", "href": "https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/config/hypervisortypes/VCENTER_CLUSTER" " },}, {{ "title": "yVM _Abiquo_enterprise", "rel": "virtualmachinetemplate", "type": "application/vnd.abiquo.virtualmachinetemplate+json", "href": "https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/admin/enterprises/336 1/datacenterrepositories/1 2/virtualmachinetemplates/2 145" }, { "title": "Others", "rel": "category", "type": "application/vnd.abiquo.category+json", "href": "https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/config/categories/1" }, { "title": "privateip", "rel": "nic0 nic1", "type": "application/vnd.abiquo.privateip+json", "href": "https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/cloud/virtualdatacenters/2486 12/privatenetworks/3490 9/ips/18027 12" } ], "usageStatistics": [] } |
...
Update the VM to add the NIC
Send Create a PUT
request to update the whole VM, including all the links. As the VM object is quite large, instead of adding it to the -d option between single quotation marks
To easily manage the large data object, you can save it to a JSON file, for example, "VMnic.json", and then use the @ the @
notation to reference the file in the cURL PUT
request.
In our example, we called the file vmapihowto2.json
.
Code Block |
---|
curl --verbose -X PUT 'https://nardo40abiquo.bcnlab.abiquoexample.com:443/api/cloud/virtualdatacenters/248612/virtualappliances/29904/virtualmachines/19454305' \ -H 'Content-Type: application/vnd.abiquo.virtualmachine+json; version=56.01' \ -H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=56.01' \ -u user:password \ -d @VMnic@vmapihowto2.json -k |
The full text of the response object is shown in the expanding section belowSend the PUT
request.
If the request is successfulplatform updates the VM successfully, the response status and message will be "204 No content
".
In the UI, when you select the VM, and open the control panel in the Network tab, the NIC should display. Note that this example shows a different VM to the one used in the request examples!
The example for an undeployed VM.
An example of the request is given here.
...
Code Block |
---|
user@user $√ api_tutorials % curl --verbose -X PUT 'https://nardo40 abiquo.bcn lab.abiquo example.com:443/api/cloud/virtualdatacenters/2486 12/virtualappliances/2990 4/virtualmachines/19454 305' \ -H 'Content-Type: application/vnd.abiquo.virtualmachine+json; version=5 6.0 1' \ -H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=5 6.0 1' \ -u user:password \ -d@VMnic @vmapihowto2.json -k* Connected to nardo40.bcn.abiquo.com (10.60.11.9) port 443 (#0) * Server auth
using Basic with user 'user'
> PUT /api/cloud/virtualdatacenters/ 248612/virtualappliances/2990 4/virtualmachines/19454 305 HTTP/1.1 > Host:nardo40 abiquo.bcn lab.abiquo example.com > Authorization: BasicXYZABC123456XYZABC123456 XXXXXXX > User-Agent: curl/7.64 88.1 > Content-Type: application/vnd.abiquo.virtualmachine+json; version=5 6.0 1 > Accept: application/vnd.abiquo.acceptedrequest+json; version=5 6.0 1 > Content-Length:10505 > Expect: 100-continue > < HTTP/1.1 100 Continue * We are completely uploaded and fine 12498 > < HTTP/1.1 204 204 < Date: Wed,29 07Jul Jun2020 2023 15:45 06:22 58 GMT < Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips < Set-Cookie: ABQSESSIONID=1638929587679935046 7288756894413749700; Max-Age=1800; Expires=Wed,29 07-Jul Jun-2020 202316 15:15 36:22 58 GMT; Path=/; Secure; HttpOnly; SameSite=strict < X-Abiquo-TracerContext:5cf12345 e54d1e2f-72bf 6b6a-449d 4338-8dee ba9e-b9e2cefb5026 4c770f4e9813 < X-Abiquo-Token:a2e19816735381c1d074441cbd002aa05c1d486bb93581cab46a78a3a2ec7e739506cc8a51c09fddd8eb25620540bfd1a82f31c2d9402c7e1079bfbd2d88f3c2 XXXXXX < Cache-Control: no-cache, no-store, max-age=0, must-revalidate < Pragma: no-cache < Expires: 0 < Strict-Transport-Security: max-age=31536000 ; includeSubDomains < X-XSS-Protection: 1; mode=block < X-Frame-Options: DENY < X-Content-Type-Options: nosniff < |
Power actions on a VM
Before you begin this section, deploy a VM using the UI or the API.
...
...
Check your VM in the UI
In the UI, when you select the VM, and open the VM details panel to the NICs tab, the NIC should display.
...
Change the power states of a VM
To prepare a VM to change power states, deploy a VM using the UI or the API.
To deploy the VM you were using in the previous step, send a POST
request to the deploy
link.
Then see Administer and troubleshoot VMs in the "Manage VM power states using the API" section
...
Delete a VM using the API
To delete an a VM (or another entity), simply perform a DELETE request to the API link. But remember
Note that there may be restrictions on what you can delete. For example, you cannot delete a virtual datacenter that contains virtual appliances.
If we delete the VM using the following queryas shown here, it will be removed from the platform (and if it exists on the hypervisor, it will be destroyed). The NIC we added will be detached and released back into And the IP address will return to the virtual datacenter.
Code Block |
---|
curl -X DELETE https://nardo40abiquo.bcnlab.abiquoexample.com:443/api/cloud/virtualdatacenters/248612/virtualappliances/29904/virtualmachines/19454305 \ -H 'Accept: text/json,application/json;' \ -u user:password -k |
...
Conclusion
Congratulations, you have now completed the Abiquo API tutorials. You can now continue to experiment using the API together with the UI. And you can find more examples in the API Howtos section.
And of course don't forget to check out the Java and Python libraries. Enjoy!
Related links