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.
...
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
Now we 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 at to the Network tab and record actions
- Edit the VM , go and go to Network → Private → select network → drag and drop an IP address into the NICs panel, and Save the VM
- Examine the PUT request and look for the link to the NIC and expand it. It will probably be at the end of the links section.
...
Tip | ||
---|---|---|
| ||
If your VM is 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://mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22486/privatenetworks/53490/ips/16" 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.
...
We will use the part of the URL that refers to the IPs of the private network, which just means removing the identifier the IP link without the id of the IP from the IP linkas shown here.
Code Block |
---|
https://mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22486/privatenetworks/53490/ips |
You could perform a curl request from the command line, for example.
Code Block |
---|
curl --verbose 'https://mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22486/privatenetworks/53490/ips' \ -H 'Accept: application/vnd.abiquo.privateips+json; version=45.60' \ -u adminuser:xabiquopassword -k | jq . |
In our response body, there are 3 IP addresses: the gateway and two IP addresses we created specifically for this exercise.
Expand | ||
---|---|---|
|
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 request parameter "free=true", as follows.
Code Block | |||
---|---|---|---|
Code Block | |||
https://mjsabiquo
|
The available IP that we will use has the identifier "17".
And the link we need from this IP object is the link with a "rel" value of "self".
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
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.
|
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://mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22486/privatenetworks/53490/ips/17", "type": "application/vnd.abiquo.privateip+json?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": "nic0self", "titletype": "application/vnd.abiquo.privateip+json", }, |
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.
Expand | |
---|---|
Code Block | "href": "https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/privatenetworks/3490/ips/18027"{ "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/2",}, |
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 |
---|
{"type": "application/vnd.abiquo.enterprise+json", "rel"title": "enterprise privateip", "title rel": "Cloudland" nic0",} "type": "application/vnd.abiquo.privateip+json",{ "href": "https:// mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2 2486/virtualappliances privatenetworks/2 3490/virtualmachines ips/8 18027",
"type": "application/vnd.abiquo.virtualmachine+json",
"rel": "edit",
"title": "ABQ_06cfadf0-db57-48c5-8f4c-f9fe2ca76c46"
},
{
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/publiccloudregions/1/enterprises/2/virtualmachines/8/action/sendmail",
"type": "application/vnd.abiquo.mail+json",
"rel": "sendmail",
"title": "send mail"
},
{
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/2/users/1",
"type": "application/vnd.abiquo.user+json",
"rel": "user",
"title": "Cloud Administrator"
},
{
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2",
"type": "application/vnd.abiquo.virtualdatacenter+json",
"rel": "virtualdatacenter",
"title": "bcdc_vdc_cloudland_01"
}, }, |
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.
Expand | ||
---|---|---|
|
Send 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, you can save it to a file, for example, "VMnic.json", and then use the @ notation to reference the file in the cURL.
Code Block | |||||||
---|---|---|---|---|---|---|---|
Expand | |||||||
curl --verbose -X PUT '
|
The full text of the response object is shown in the expanding section below.
If the request is successful, 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.
This expanding section contains the full request with the VM object embedded in it.
|
Send 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, you can save it to a file, for example, "VMnic.json", and then use the @ notation to reference the file in the cURL.
Code Block |
---|
curl --verbose -X PUT 'https://nardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2486/virtualappliances/2990/virtualmachines/19454' \
-H 'Content-Type: application/vnd.abiquo.virtualmachine+json; version=5.0' \
-H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=5.0' \
-u user:password \
-d @VMnic.json -k |
The full text of the response object is shown in the expanding section below.
If the request is successful, 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.
The example request is given here.
Expand | ||
---|---|---|
|
...
Power actions on a VM
Before you begin this section, deploy a VM through the user interface. using the UI or the API.
Include Page | ||||
---|---|---|---|---|
|
...
Delete an entity
...
using the API
To delete an entity, simply perform a DELETE request to the API link. But remember 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 query, 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 the virtual datacenter.
Code Block |
---|
curl -X DELETE https://mjsabiquonardo40.bcn.abiquo.com:443/api/cloud/virtualdatacenters/22486/virtualappliances/22990/virtualmachines/819454 \ -H 'Accept: text/json,application/json;' \ -u user:password -k |
...
Related links
...