Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents

Introduction

This tutorial continues on from Get Started started with the Abiquo API!

Modify an entity through 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 through the UI

Now 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.

  1. Open the browser console at the Network tab and record actions
  2. Edit the VM, go to Network → Private → select network → drag and drop an IP, and Save the VM
  3. 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.

Image Removed

Tip
titleDeployed VMs

If your VM is 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.

In this tutorial, you will use the Abiquo API to do the following.

  1. Configure a VM by adding an IP address (NIC)

  2. 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:

  1. Not deployed

  2. 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.

  1. Use a GET request to retrieve the entity's data object

  2. Modify the data object

  3. 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.

  1. Open the browser console to the Network tab and record actions

  2. Edit the VM and go to Network → Private

  3. Select the network and drag an IP address into the NICs panel, and Save the VM

  4. Find the PUT request and copy it, or get the nic 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":"nic0nic1",
         "type":"application/vnd.abiquo.privateip+json",
         "href":"https://mjsabiquoabiquo.bcnlab.abiquoexample.com:443/api/cloud/virtualdatacenters/212/privatenetworks/59/ips/1611"
      }, 

We will use this type of NIC link in the next step.

...


...


Get an IP address to add to the VM

...

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.

...

To find a free IP address:

  1. From the link to the NIC in the previous step, get only the networks IPs link

    Code Block
    https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/

...

  1. 9/ips

...

  1. Use a

...

  1. GET request

...

  1. to obtain the first 3 IP addresses in this network, and add the query parameter limit with a value of 3  

    Code Block
    curl --verbose 'https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/

...

  1. 9/ips?limit=3' \
         -H 'Accept: application/vnd.abiquo.privateips+json; version=

...

  1. 6.

...

  1. 1' \
    	 -u 

...

  1. user:

...

  1. password -k | jq .

...

  1.  

    (tick) To retrieve IPs that are available for use only, use the query parameter free with a value of true

  2. The response has 3 IP addresses: the gateway and the IP addresses we created specifically for this exercise.

...

  1. Code Block

...

  1. ~ 

...

  1. % curl --verbose -k 'https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/

...

  1. 9/ips?limit=3' \
         -H 'Accept: application/vnd.abiquo.privateips+json; version=

...

  1. 6.

...

  1. 1' \
         -u 

...

  1. user:

...

  1. password 

...

  1. | jq .
    

...

  1.  

...

  1.  

...

  1.  

...

  1.  

...

  1.  

...

  1. 
    

...

  1. > 

...

  1. GET /api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/

...

  1. 9/ips?limit=3 HTTP/1.1
    > Host: abiquo.lab.example.com
    > Authorization: Basic 

...

  1. XXXXXX
    > User-Agent: curl/7.

...

  1. 88.

...

  1. 1
    >

...

  1.  

...

  1. Accept: application/vnd.abiquo.privateips+json; version=

...

  1. 6.

...

  1. 1
    > 
    < HTTP/1.1 200 200
    < Date: Wed, 

...

  1. 07 Jun 

...

  1. 2023 13:

...

  1. 54:

...

  1. 46 GMT

...

  1. 
    

...

  1. < Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
    < Set-Cookie: ABQSESSIONID=

...

  1. 5848743475559326145; Max-Age=1800; Expires=Wed, 

...

  1. 07-Jun-

...

  1. 2023 

...

  1. 14:

...

  1. 24:

...

  1. 46 GMT; Path=/; Secure; HttpOnly; SameSite=strict
    < X-Abiquo-

...

  1. TracerContext: 

...

  1. c2b1df27-14c5-4e28-917d-f793d7dc3a71
    < 

...

  1. X-Abiquo-

...

  1. Token: 

...

  1. XXXXXX
    < 

...

  1. Cache-

...

  1. Control: 

...

  1. 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://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/

...

  1. 9/ips?limit=3&by=ip&asc=true"
        },
        {
     

...

  1.  

...

  1.     

...

  1. "rel": "

...

  1. next",
          

...

  1. "href": "https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/

...

  1. 9/ips?startwith=3&limit=3&by=ip&asc=true"
        },
        {
          "

...

  1. rel": "

...

  1. last",

...

  1. 
          "

...

  1. href": "

...

  1. https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips?startwith=1&limit=3&by=ip&asc=true"
        }
      ],
      "

...

  1. collection": 

...

  1. [
        {
       

...

  1.    "id": 8,
        

...

  1.   "ip": "192.168.0.1",
          

...

  1. "

...

  1. mac": "

...

  1. 00:50:56:2F:D8:F3",
          

...

  1. "

...

  1. name": "

...

  1. 0050562FD8F3_captured",

...

  1. 
          

...

  1. "

...

  1. networkName": "

...

  1. default_private_network",
          

...

  1. "ipv6": 

...

  1. false,
          "quarantine": false,
    

...

  1.       "available": 

...

  1. true,
          "

...

  1. links":

...

  1.  [
            {
      

...

  1.  

...

  1.        "

...

  1. title": "

...

  1. default_private_network",
              "

...

  1. rel": "

...

  1. privatenetwork",
              "

...

  1. type": "

...

  1. application/vnd.abiquo.vlan+json",
          

...

  1.  

...

  1.    "href": "https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9"
      

...

  1.  

...

  1.      },
     

...

  1.  

...

  1.      

...

  1.  {
       

...

  1.        "

...

  1. title": "privateip",
      

...

  1.         

...

  1. "rel": "self",
              "

...

  1. type": "application/vnd.abiquo.privateip+json",
              "href": "https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/9/

...

  1. ips/8"
            },
           

...

  1.  {
              "

...

  1. title": "

...

  1. vdcbcdc",
              "

...

  1. rel": "

...

  1. virtualdatacenter",
            

...

  1.   "type": "application/vnd.abiquo.virtualdatacenter+json",
         

...

  1.      

...

  1. "href": "https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12"
            

...

  1. }
          ]
       

...

  1.  },
        {
          "

...

  1. id": 

...

  1. 11,
          

...

  1. "ip": "192.168.0.2",
          "mac": 

...

  1. "00:50:56:1A:2E:18",
          

...

  1. "

...

  1. name": "

...

  1. 0050561A2E18_captured",
          

...

  1. "

...

  1. networkName": "

...

  1. default_private_network",
          

...

  1. "

...

  1. ipv6": 

...

  1. false,
          "

...

  1. usedBy": "

...

  1. 1979e77f-32b1-430d-9b92-9f6347dbd416",
          

...

  1. "quarantine": false,
          "available": 

...

  1. true,
          "links": [
           

...

  1.  {
              "

...

  1. title": "

...

  1. default_private_network",
              "rel": "

...

  1. privatenetwork",
              "

...

  1. type": "

...

  1. application/vnd.abiquo.vlan+json",
              "href": "https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/

...

  1. privatenetworks/9"
            },
            {
     

...

  1.          "title": "

...

  1. privateip",
              "rel": "

...

  1. self",
              "

...

  1. type": "

...

  1. application/vnd.abiquo.privateip+json",
            

...

  1.   "href": "https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips/11"
         

...

  1.    },
       

...

  1.  

...

  1.     {
      

...

  1.  

...

  1.        "

...

  1. title": "

...

  1. vdcbcdc",
              "

...

  1. rel": "

...

  1. virtualdatacenter",
              "

...

  1. type": "

...

  1. application/vnd.abiquo.virtualdatacenter+json",
              "

...

  1. href": "

...

  1. https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12"
            },
            {
      

...

  1.  

...

  1.        "

...

  1. title": "

...

  1. vapbcdc",
          

...

  1.  

...

  1.    

...

  1. "rel": "virtualappliance",
       

...

  1.        "

...

  1. type": 

...

  1. "application/vnd.abiquo.virtualappliance+json",
              "href": "https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/

...

  1. virtualappliances/

...

  1. 4"

...

  1. 
            },
     

...

  1.        {
         

...

  1.      "title": "vmapihowto",
              "

...

  1. rel": "

...

  1. virtualmachine",
            

...

  1.   

...

  1. "type": "application/vnd.abiquo.virtualmachine+json",
              "href": "https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/

...

  1. virtualappliances/

...

  1. 4/

...

  1. virtualmachines/

...

  1. 304"

...

  1. 
            }
     

...

  1.      ]
        },
      

...

  1.  

...

  1.  {
          "

...

  1. id": 

...

  1. 12,
          

...

  1. "ip": "192.168.0.3",
          

...

  1. "mac": "00:50:56:18:63:13",
          

...

  1. "

...

  1. name": "

...

  1. 005056186313_host",
          "

...

  1. networkName": "

...

  1. default_private_network",
          "ipv6": false,
          "

...

  1. quarantine": 

...

  1. false,
          "available": true,
          "

...

  1. links": 

...

  1. [
            

...

  1. {
       

...

  1.        "

...

  1. title": 

...

  1. "default_private_network",
              "

...

  1. rel": "

...

  1. privatenetwork",
              "

...

  1. type": "

...

  1. application/vnd.abiquo.vlan+json",
              "

...

  1. href": "

...

  1. https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9"
           

...

  1.  },
          

...

  1.  

...

  1.  

...

  1. {
       

...

  1.        "

...

  1. title": 

...

  1. "privateip",
        

...

  1.    

...

  1.    "

...

  1. rel":

...

  1.  "self",
              

...

  1. "type": "application/vnd.abiquo.privateip+json",
              "href": "https://

...

  1. abiquo.

...

  1. lab.

...

  1. example.com:443/api/cloud/virtualdatacenters/

...

  1. 12/privatenetworks/

...

  1. 9/ips

...

  1. /12"
          

...

  1.  

...

  1.  },
       

...

  1.      {
              "

...

  1. title": 

...

  1. "vdcbcdc",
              "rel": "virtualdatacenter",
              "

...

  1. type": "

...

  1. application/vnd.abiquo.virtualdatacenter+json",
        

...

  1.    

...

  1.    "

...

  1. href": 

...

  1. "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. 

Hint: to only retrieve IPs that are available for use, you can use the request parameter "free=true", as follows.

Code Block
https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/privatenetworks/34/ips?free=true

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"

The available IP address of 192.168.0.3 is the one we will use, and it has an ID of 12.

From the IP address object in the above step, get the link with a rel attribute that has a value of self.

Code Block
        {
          "hreftitle": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/privatenetworks/5/ips/17privateip",
          "typerel": "application/vnd.abiquo.privateip+jsonself",
          "reltype": "selfapplication/vnd.abiquo.privateip+json",
          "titlehref": "privateip"
        },

...

https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/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 on the machine, we will add "nic0" nic1 as shown here.

Code Block
        {
          "hreftitle": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/privatenetworks/5/ips/17",privateip",
          "rel": "nic1",
          "type": "application/vnd.abiquo.privateip+json",
          "relhref": "nic0",
          "title": "privateip"https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips/12"
        },

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.

...

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.

(tick) 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/
admin/enterprises/2",
cloud/virtualmachines?vmname=2' \
     
"type"
-H 'Accept: 
"
application/vnd.abiquo.
enterprise
virtualmachines+json
",
; version=6.1' \
    
"rel": "enterprise", "title": "Cloudland" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8", "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" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2", "type": "application/vnd.abiquo.virtualappliance+json", "rel": "virtualappliance", "title": "bcdc_vdc_cloudland_01_vapp_01" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/metadata", "type": "application/vnd.abiquo.metadata+json", "rel": "metadata", "title": "metadata" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/network/configurations", "type": "application/vnd.abiquo.virtualmachinenetworkconfigurations+json", "rel": "configurations", "title": "vlan network configurations" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/network/nics", "type": "application/vnd.abiquo.nics+json", "rel": "nics", "title": "nics" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/storage/disks", "type": "application/vnd.abiquo.harddisks+json", "rel": "harddisks", "title": "disks" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/state", "type": "application/vnd.abiquo.virtualmachinestate+json", "rel": "state", "title": "NOT_ALLOCATED" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/undeploy", "type": "application/vnd.abiquo.acceptedrequest+json", "rel": "undeploy", "title": "virtual machine undeploy" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/deploy", "type": "application/vnd.abiquo.acceptedrequest+json", "rel": "deploy", "title": "virtual machine deploy" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/reset", "type": "application/vnd.abiquo.acceptedrequest+json", "rel": "reset", "title": "virtual machine reset" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/instance", "type": "application/vnd.abiquo.acceptedrequest+json", "rel": "instance", "title": "virtual machine snapshot" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/config/rdpaccess", "type": "application/vnd.abiquo.virtualmachineconsole+json", "rel": "rdpaccess", "title": "remote access" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/tasks", "type": "application/vnd.abiquo.tasks+json", "rel": "tasks", "title": "tasks" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/firewalls", "type": "application/vnd.abiquo.links+json", "rel": "firewalls", "title": "firewalls" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/loadbalancers", "type": "application/vnd.abiquo.loadbalancers+json", "rel": "loadbalancers", "title": "load balancers" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/backup/action/request", "type": "application/vnd.abiquo.ondemandbackup+json", "rel": "requestbackup", "title": "request on demand backup" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/backup/action/restore", "type": "application/vnd.abiquo.restore+json", "rel": "requestrestore", "title": "request a restore of a backup" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/vappmove", "type": "application/vnd.abiquo.links+json", "rel": "vappmove", "title": "move VM to a virtual appliance" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/move", "type": "application/vnd.abiquo.movevm+json", "rel": "move", "title": "move VM to another virtual datacenter" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/storage/volumes", "type": "application/vnd.abiquo.volumes+json", "rel": "volumes", "title": "volumes" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/disks/31", "type": "application/vnd.abiquo.harddisk+json", "rel": "disk0", "title": "9c83fcc3-e9cb-44bf-88d0-f8a98248fa69", "length": "64", "diskLabel": "Hard disk 1", "diskControllerType": "IDE" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/locations/1/datastoretiers/1", "type": "application/vnd.abiquo.datastoretier+json", "rel": "datastoretier0", "title": "Default Tier" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/protect", "type": "text/plain", "rel": "protect", "title": "protect" }, { "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/unprotect
 -u 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.

(warning) 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,
      "uuid": "eb613c22-ffa1-4498-827a-ccaf37385c2e",
      "
type
fqdn": "
text/plain
box.localdomain",
      "
rel
description": "
unprotect
A virtual machine",
      "
title
coresPerSocket": 1,
      "
unprotect
idState": 1,
   
},
   "idType": 0,
{
      
"
href
type": "
https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/metrics
MANAGED",
      "
type
highDisponibility": 0,
    
"application/vnd.abiquo.metricsmetadata+json"
  "monitored": false,
      "
rel
monitoringLevel": "
metricsmetadata
DEFAULT",
      "
title
protected":
"metricsmetadata"
 false,
      "variables": {},
     
{
 "backuppolicies": [],
      "
href
lastSynchronize": 
"https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/enablemonitoring"
1686046081000,
      "
type
generateGuestInitialPassword": false,
      "natrules": [],
      "
rel
vdrpEnabled": 
"enablemonitoring"
true,
      "vdrpPort": 0,
      "
title
password": "
enablemonitoring
6t51rgZ9",
    
},
  
{
"deallocated": false,
      "
href
name": 
"https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/metrics/collectd"
"vmapihowto2",
      "ram": 48,
      "
type
cpu": 
"application/json"
1,
      "
rel
state": "
collectd
NOT_ALLOCATED",
      "
title
creationTimestamp": 1686042455000,
      "
collectd
birthTimestamp": 1686045726000,
  
},
    "links": [
    
{
    {
  
"href":
 
"https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/alarms",
       "
type
title": "
application/vnd.abiquo.alarms+json
Abiquo",
          "rel": "
alarmssearch
enterprise",
          "
title
type": "
alarmssearch" }
application/vnd.abiquo.enterprise+json",
    
{
      
"href": "https://
mjsabiquo
abiquo.
bcn
lab.
abiquo
example.com:443/api/
cloud
admin/
virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/clone",
enterprises/1"
        },
        {
          "
type
title": "
application/vnd.abiquo.virtualmachinecloneoptions+json
vmapihowto2",
          "rel": "
clone
edit",
          "
title
type": "
clone" }
application/vnd.abiquo.virtualmachine+json",
    
{
      
"href": "https://
mjsabiquo
abiquo.
bcn
lab.
abiquo
example.com:443/api
/config/hypervisortypes/KVM",
/cloud/virtualdatacenters/12/virtualappliances/4/virtualmachines/305"
       
"type": "application/vnd.abiquo.hypervisortype+json",
 },
  
"rel":
 
"hypervisortype",
     ...
 
"title":
 
"KVM"
     
},
     
{
    {
  
"href":
 
"https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/2/datacenterrepositories/1/virtualmachinetemplates/86",
       "
type
title": "
application/vnd.abiquo.virtualmachinetemplate+json
VMware vCenter Cluster",
          "rel": "
virtualmachinetemplate
hypervisortype",
          "
title
type": "
yvm2" },
application/vnd.abiquo.hypervisortype+json",
   
{
       "href": "https://
mjsabiquo
abiquo.
bcn
lab.
abiquo
example.com:443/api/config/
categories
hypervisortypes/
1",
VCENTER_CLUSTER"
        },
        {
          "
type
title": "
application/vnd.abiquo.category+json
yVM",
          "rel": "
category
virtualmachinetemplate",
          "
title
type": "
Others" }
application/vnd.abiquo.virtualmachinetemplate+json",
    
{
      
"href": "https://
mjsabiquo
abiquo.
bcn
lab.
abiquo
example.com:443/api/
cloud
admin/
virtualdatacenters
enterprises/
2
1/
privatenetworks
datacenterrepositories/
5
2/
ips
virtualmachinetemplates/
17"
145"
        },
        {
  
"type":
 
"application/vnd.abiquo.privateip+json",
       "
rel
title": "
nic0
Others",
          "
title
rel": "
privateip
category",
    
}
   
],
   "
natrules
type": 
[]
"application/vnd.abiquo.category+json",
  
"generateGuestInitialPassword":
 
false,
   
"backuppolicies":
 
[],
   "
creationTimestamp
href": 
1560939950000,
"https://abiquo.lab.example.com:443/api/config/categories/1"
   
"variables":
 
{},
   
"protected":
 
false
},
   
"monitored":
 
false,
   
"ram": 48,
 {
  
"coresPerSocket":
 
1,
   
"cpu":
 
1,
   "
description
title": "
A
privateip",
  
virtual
 
machine",
   
"label":
 
"yVM_New",
   "
name
rel": "
ABQ_06cfadf0-db57-48c5-8f4c-f9fe2ca76c46
nic1",
  
"uuid
        "type": "
06cfadf0-db57-48c5-8f4c-f9fe2ca76c46",
application/vnd.abiquo.privateip+json",
          "
id
href": 
8, "vdrpEnabled": true, "vdrpPort": 0, "idState": 1, "state": "NOT_ALLOCATED", "idType": 0, "type": "MANAGED", "highDisponibility": 0, "password": "VUFvbvoa" }

...

"https://abiquo.lab.example.com:443/api/cloud/virtualdatacenters/12/privatenetworks/9/ips/12"
        } 
      ],
      "usageStatistics": []
    }      

...


Update the VM to add the NIC

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://mjsabiquoabiquo.bcnlab.abiquoexample.com:443/api/cloud/virtualdatacenters/212/virtualappliances/24/virtualmachines/8305' \
  	 -H 'Content-Type: application/vnd.abiquo.virtualmachine+json; version=46.61' \
     -H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=46.61' \
	   -u adminuser:xabiquopassword \
  	 -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 successfulthe platform 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.

Image Removed

This expanding section contains the full request with the VM object embedded in it.

...

 for an undeployed VM.

An example of the request is given here.

Code Block
 √ api_tutorials % curl --verbose -X PUT 'https://
mjsabiquo
abiquo.
bcn
lab.
abiquo
example.com:443/api/cloud/virtualdatacenters/
2
12/virtualappliances/
2
4/virtualmachines/
8
305' \
   -H 'Content-Type: application/vnd.abiquo.virtualmachine+json; version=
4
6.
6
1' \
   
-H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=
4
6.
6
1' \
   -u 
admin:xabiquo
user:password \
   -d 
@VMnic
@vmapihowto2.json -k
* Connected to mjsabiquo.bcn.abiquo.com (10.60.13.180) port 443

(#0)
 
*
 
Server
 
auth
 
using

Basic with user 'admin'
> PUT /api/cloud/virtualdatacenters/
2
12/virtualappliances/
2
4/virtualmachines/
8
305 HTTP/1.1
> Host: abiquo.lab.example.com
> Authorization: Basic 
YWRtaW46eGFiaXF1bw==
XXXXXXX
> User-Agent: curl/7.
35
88.
0
1
> 
Host
Content-Type: 
mjsabiquo
application/vnd.
bcn.abiquo.com
abiquo.virtualmachine+json; version=6.1
> 
Content-Type
Accept: application/vnd.abiquo.
virtualmachine
acceptedrequest+json; version=6.1
> Content-Length: 12498
> 
< HTTP/1.1 204 204
< Date: Wed, 07 Jun 2023 15:06:58 GMT
< Server: Apache/2.4.6 
> Accept: application/vnd.abiquo.acceptedrequest+json; version=4.6 > Content-Length: 9805 > Expect: 100-continue > < HTTP/1.1 100 Continue < HTTP/1.1 204 204 < Date: Wed, 19 Jun 2019 13:30:55 GMT < Server: Apache < Set-Cookie: ABQSESSIONID=4974951206556392645; Max-Age=1800; Expires=Wed, 19-Jun-2019 14:00:55 GMT; Path=/; Secure; HttpOnly < X-Abiquo-Token: 2772ef503a95419ab7066ee6771751e622f4fd0743fe006121a77f6b3213506b <

...

Before you begin this section, deploy a VM through the user interface. 

...

Delete an entity through the API

...

(CentOS) OpenSSL/1.0.2k-fips
< Set-Cookie: ABQSESSIONID=7288756894413749700; Max-Age=1800; Expires=Wed, 07-Jun-2023 15:36:58 GMT; Path=/; Secure; HttpOnly; SameSite=strict
< X-Abiquo-TracerContext: e54d1e2f-6b6a-4338-ba9e-4c770f4e9813
< 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
< 

...

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.

(tick) 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 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://mjsabiquoabiquo.bcnlab.abiquoexample.com:443/api/cloud/virtualdatacenters/212/virtualappliances/24/virtualmachines/8305 \
     	-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: