Versions Compared

Key

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

Table of Contents

...

This tutorial continues on from Get 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.

...

Code Block
https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips

You could just open this link in your browser where you are using the UI, or perform a curl request from the command line, for example.

Code Block
curl --verbose 'https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips' \
     -H "'Accept: application/vnd.abiquo.privateips+json; version=4.4"6' \
	 -u user:passwordadmin:xabiquo -k | jq .

In our response body, there are 3 IP addresses: the gateway and two IP addresses we created specifically for this exercise.

Expand


Code Block
> GET /user@user:~ $ curl --verbose 'https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips' HTTP/1.1 > Authorization: Basic YWRtaW46eGFiaXF1bw== > User-Agent-H 'Accept: curlapplication/7vnd.35.0
> Host: mjsabiquo.bcn.abiquo.com
> Accept: application/vnd.abiquo.privateips+abiquo.privateips+json; version=4.4
> 
< HTTP/1.1 200 200
< Date: Thu, 06 Sep 2018 12:25:06 GMT6'  -u admin:xabiquo -k | jq .
* Connected to mjsabiquo.bcn.abiquo.com (10.60.13.180) port 443 (#0)
* Server Apacheauth isusing notBasic blacklistedwith < Server: Apache
< Set-Cookie: ABQSESSIONID=5089683228809279597; Max-Age=1800; Expires=Thu, 06-Sep-2018 12:55:07 GMT; Path=/; Secure; HttpOnly
< X-Abiquo-Token: b1bdc4461de17670c503e3330f6571fd51f3154c9e1a2ecd86f463ce3cc8acd2
< Content-Typeuser 'admin'
> GET /api/cloud/virtualdatacenters/2/privatenetworks/5/ips HTTP/1.1
> Authorization: Basic YWRtaW46eGFiaXF1bw==
> User-Agent: curl/7.35.0
> Host: mjsabiquo.bcn.abiquo.com
> Accept: application/vnd.abiquo.privateips+json; version=4.46
<> Transfer-Encoding:
chunked
< 
{ [data not shown]
100  3012    0  3012    0     0   8563      0 --:--:-- --:--:-- --:--:--  8581HTTP/1.1 200 200
< Date: Wed, 19 Jun 2019 13:11:53 GMT
* Server Apache is not blacklisted
< Server: Apache
< Set-Cookie: ABQSESSIONID=5059746984440775455; Max-Age=1800; Expires=Wed, 19-Jun-2019 13:41:53 GMT; Path=/; Secure; HttpOnly
< X-Abiquo-Token: 2772ef503a95419ab7066ee6771751e6546ca200feb764385226ae9047a8f03e
< Content-Type: application/vnd.abiquo.privateips+json; version=4.6
< Transfer-Encoding: chunked
< 
* Connection #0 to host mjsabiquo.bcn.abiquo.com left intact
{
  "collection": [
    {
      "links": [
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345",
          "type": "application/vnd.abiquo.vlan+json",
          "rel": "privatenetwork",
          "title": "default_private_network_cloudland_01"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips/14115",
          "type": "application/vnd.abiquo.privateip+json",
          "rel": "self",
          "title": "privateip"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262",
          "type": "application/vnd.abiquo.virtualdatacenter+json",
          "rel": "virtualdatacenter",
          "title": "kvmvdcbcdc_vdc_cloudland_01"
        }
      ],
      "availableid": true15,
      "ipv6ip": false"192.168.201.1",
      "networkNamemac": "default_private_network52:54:00:CD:25:F8",
      "name": "525400512A90525400CD25F8_host",
      "macnetworkName": "52:54:00:51:2A:90""private_network_cloudland_01",
      "ipv6": false,
      "ipquarantine": "192.168.0.1"false,
      "idavailable": 141true
    },
    {
      "links": [
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345",
          "type": "application/vnd.abiquo.vlan+json",
          "rel": "privatenetwork",
          "title": "default_private_network_cloudland_01"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips/14316",
          "type": "application/vnd.abiquo.privateip+json",
          "rel": "self",
          "title": "privateip"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262",
          "type": "application/vnd.abiquo.virtualdatacenter+json",
          "rel": "virtualdatacenter",
          "title": "kvmvdcbcdc_vdc_cloudland_01"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372",
          "type": "application/vnd.abiquo.virtualappliance+json",
          "rel": "virtualappliance",
          "title": "bcdc_vdc_cloudland_01_vapp_kvmvdc01"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1986",
          "type": "application/vnd.abiquo.virtualmachine+json",
          "rel": "virtualmachine",
          "title": "ABQ_66052b57331a9b47-f2b75cf6-4da94166-8f9ebb02-e4d9877b89c4021d5e8905df"
        }
      ],
      "available": true,
      "id": 14316,
      "ip": "192.168.0201.2",
      "mac": "52:54:00:4A5F:8A7D:C368",
      "name": "5254004A8AC35254005F7D68_host",
      "networkName": "default_private_network_cloudland_01",
      "ipv6": false,
      "usedBy": "ABQ_66052b57331a9b47-f2b75cf6-4da94166-8f9ebb02-e4d9877b89c4021d5e8905df",
      "availablequarantine": truefalse
    },
    {
      "links": [
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345",
          "type": "application/vnd.abiquo.vlan+json",
          "rel": "privatenetwork",
          "title": "default_private_network_cloudland_01"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips/21717",
          "type": "application/vnd.abiquo.privateip+json",
          "rel": "self",
          "title": "privateip"
        },
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262",
          "type": "application/vnd.abiquo.virtualdatacenter+json",
          "rel": "virtualdatacenter",
          "title": "kvmvdcbcdc_vdc_cloudland_01"
        }
      ],
      "availableid": true17,
      "ipv6ip": false"192.168.201.3",
      "networkNamemac": "default_private_network52:54:00:DC:31:12",
      "name": "525400D72B9E525400DC3112_host",
      "macnetworkName": "52:54:00:D7:2B:9E""private_network_cloudland_01",
      "ipv6": false,
      "ipquarantine": "192.168.0.3"false,
      "idavailable": 217true
    }
  ],
  "links": [
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips?limit=25&by=ip&asc=true",
      "rel": "first"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips?startwith=0&limit=25&by=ip&asc=true",
      "rel": "last"
    }
  ],
  "totalSize": 3
}

 


In the above example, the IP that is being used on a VM has a link to that the VM. 

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

...

The available IP that we will use has the identifier "21717".

And the link we need from this IP object is the link with a "rel" value of "self".

Code Block
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips/21717",
          "type": "application/vnd.abiquo.privateip+json",
          "rel": "self",
          "title": "privateip"
        },

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
        {
          "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworks/345/ips/21717",
          "type": "application/vnd.abiquo.privateip+json",
          "rel": "nic0",
          "title": "privateip"
        },

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
 {
  "links": [
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloudadmin/virtualdatacenters/26/virtualappliances/37/virtualmachines/199enterprises/2",
      "type": "application/vnd.abiquo.virtualmachineenterprise+json",
      "rel": "editenterprise",
      "title": "ABQ_f26a16fb-d732-4d73-9bb6-0dbc34cd3a31Cloudland"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/4/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8",
      "type": "application/vnd.abiquo.enterprisevirtualmachine+json",
      "rel": "enterpriseedit",
      "title": "Accounting departmentABQ_06cfadf0-db57-48c5-8f4c-f9fe2ca76c46"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/publiccloudregions/1/enterprises/4/users/12/virtualmachines/8/action/sendmail",
      "type": "application/vnd.abiquo.usermail+json",
      "rel": "usersendmail",
      "title": "Cloudsend Administratormail"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26admin/enterprises/2/users/1",
      "type": "application/vnd.abiquo.virtualdatacenteruser+json",
      "rel": "virtualdatacenteruser",
      "title": "kvmvdcCloud Administrator"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/372",
      "type": "application/vnd.abiquo.virtualappliancevirtualdatacenter+json",
      "rel": "virtualappliancevirtualdatacenter",
      "title": "vapp_kvmvdcbcdc_vdc_cloudland_01"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/37/virtualmachines/199/metadata2",
      "type": "application/vnd.abiquo.metadatavirtualappliance+json",
      "rel": "metadatavirtualappliance",
      "title": "metadatabcdc_vdc_cloudland_01_vapp_01"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/network/configurationsmetadata",
      "type": "application/vnd.abiquo.virtualmachinenetworkconfigurationsmetadata+json",
      "rel": "configurationsmetadata",
      "title": "vlan network configurationsmetadata"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/network/nicsconfigurations",
      "type": "application/vnd.abiquo.nicsvirtualmachinenetworkconfigurations+json",
      "rel": "nicsconfigurations",
      "title": "nicsvlan network configurations"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/storagenetwork/disksnics",
      "type": "application/vnd.abiquo.harddisksnics+json",
      "rel": "harddisksnics",
      "title": "disksnics"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/8/199storage/statedisks",
      "type": "application/vnd.abiquo.virtualmachinestateharddisks+json",
      "rel": "stateharddisks",
      "title": "NOT_ALLOCATEDdisks"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/action/undeploystate",
      "type": "application/vnd.abiquo.acceptedrequestvirtualmachinestate+json",
      "rel": "undeploystate",
      "title": "virtual machine undeployNOT_ALLOCATED"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/action/deployundeploy",
      "type": "application/vnd.abiquo.acceptedrequest+json",
      "rel": "deployundeploy",
      "title": "virtual machine deployundeploy"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/action/resetdeploy",
      "type": "application/vnd.abiquo.acceptedrequest+json",
      "rel": "resetdeploy",
      "title": "virtual machine resetdeploy"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/action/instancereset",
      "type": "application/vnd.abiquo.acceptedrequest+json",
      "rel": "instancereset",
      "title": "virtual machine snapshotreset"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/configaction/rdpaccessinstance",
      "type": "application/vnd.abiquo.virtualmachineconsoleacceptedrequest+json",
      "rel": "rdpaccessinstance",
      "title": "remotevirtual machine accesssnapshot"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/config/tasksrdpaccess",
      "type": "application/vnd.abiquo.tasksvirtualmachineconsole+json",
      "rel": "tasksrdpaccess",
      "title": "tasksremote access"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/firewallstasks",
      "type": "application/vnd.abiquo.linkstasks+json",
      "rel": "firewallstasks",
      "title": "firewallstasks"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/loadbalancersfirewalls",
      "type": "application/vnd.abiquo.loadbalancerslinks+json",
      "rel": "loadbalancersfirewalls",
      "title": "load balancersfirewalls"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/199/backup/action/request8/loadbalancers",
      "type": "application/vnd.abiquo.ondemandbackuploadbalancers+json",
      "rel": "requestbackuploadbalancers",
      "title": "requestload balancers"
on demand backup"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/backup/action/restorerequest",
      "type": "application/vnd.abiquo.restoreondemandbackup+json",
      "rel": "requestrestorerequestbackup",
      "title": "request aon restoredemand of a backup"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/8/199backup/action/vappmoverestore",
      "type": "application/vnd.abiquo.linksrestore+json",
      "rel": "vappmoverequestrestore",
      "title": "moverequest a VMrestore toof a virtual appliancebackup"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/storageaction/volumesvappmove",
      "type": "application/vnd.abiquo.volumeslinks+json",
      "rel": "volumesvappmove",
      "title": "volumesmove VM to a virtual appliance"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/disks/216/2/virtualappliances/2/virtualmachines/8/action/move",
      "type": "application/vnd.abiquo.harddiskmovevm+json",
      "rel": "disk0move",
      "title": "35a20d65-ff7f-4f65-8207-45751fa4e400",
      "length": "64",
      "diskLabel": "Hard disk 1",
 move VM to another virtual datacenter"
    "diskControllerType": "IDE"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/locations/10/datastoretiers/3/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/storage/volumes",
      "type": "application/vnd.abiquo.datastoretiervolumes+json",
      "rel": "datastoretier0volumes",
      "title": "Default Tiervolumes"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/37/virtualmachines/199/action/protectdisks/31",
      "type": "text/plainapplication/vnd.abiquo.harddisk+json",
      "rel": "protectdisk0",
      "title": "protect"
    }9c83fcc3-e9cb-44bf-88d0-f8a98248fa69",
    {       "hreflength": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/unprotect64",
      "typediskLabel": "text/plain",Hard disk      "rel": "unprotect"1",
      "titlediskControllerType": "unprotectIDE"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenterslocations/261/virtualappliances/37/virtualmachines/199/metricsdatastoretiers/1",
      "type": "application/vnd.abiquo.metricsmetadatadatastoretier+json",
      "rel": "metricsmetadatadatastoretier0",
      "title": "metricsmetadataDefault Tier"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/enablemonitoringaction/protect",
      "type": "text/plain",
      "rel": "enablemonitoringprotect",
      "title": "enablemonitoringprotect"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/metricsaction/collectdunprotect",
      "type": "applicationtext/jsonplain",
      "rel": "collectdunprotect",
      "title": "collectdunprotect"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/alarmsmetrics",
      "type": "application/vnd.abiquo.alarmsmetricsmetadata+json",
      "rel": "alarmssearchmetricsmetadata",
      "title": "alarmssearchmetricsmetadata"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1998/action/cloneenablemonitoring",
      "type": "application/vnd.abiquo.virtualmachinecloneoptions+json",
      "rel": "cloneenablemonitoring",
      "title": "cloneenablemonitoring"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/hypervisortypes/KVMcloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/metrics/collectd",
      "type": "application/vnd.abiquo.hypervisortype+json",
      "rel": "hypervisortypecollectd",
      "title": "KVMcollectd"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admincloud/enterprisesvirtualdatacenters/42/datacenterrepositoriesvirtualappliances/102/virtualmachinetemplatesvirtualmachines/2438/alarms",
      "type": "application/vnd.abiquo.virtualmachinetemplatealarms+json",
      "rel": "virtualmachinetemplatealarmssearch",
      "title": "yVMalarmssearch"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/categories/1/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8/action/clone",
      "type": "application/vnd.abiquo.categoryvirtualmachinecloneoptions+json",
      "rel": "categoryclone",
      "title": "Othersclone"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloudconfig/virtualdatacenters/26/privatenetworks/34/ips/217hypervisortypes/KVM",
      "type": "application/vnd.abiquo.privateiphypervisortype+json",
      "rel": "nic0hypervisortype",
      "title": "privateipKVM"
    },
  ],  {
      "iconUrlhref": "https://uploadmjsabiquo.bcn.wikimedia.org/wikipedia/commons/a/af/Tux.pngabiquo.com:443/api/admin/enterprises/2/datacenterrepositories/1/virtualmachinetemplates/86",
  "natrules": [],   "generateGuestInitialPasswordtype": false,   "backuppolicies": []"application/vnd.abiquo.virtualmachinetemplate+json",
  "creationTimestamp": 1536229326000,   "variablesrel": {}"virtualmachinetemplate",
  "protected": false,   "vdrpEnabledtitle": true,"yvm2"
   "ram": 48},
  "cpu": 1, {
 "description": "A virtual machine",   "labelhref": "yVM_New",https://mjsabiquo.bcn.abiquo.com:443/api/config/categories/1",
      "nametype": "ABQ_f26a16fb-d732-4d73-9bb6-0dbc34cd3a31application/vnd.abiquo.category+json",
      "uuidrel": "f26a16fb-d732-4d73-9bb6-0dbc34cd3a31category",
  "id": 199,   "vdrpPorttitle": "Others"
0,   "idState": 1},
  "state": "NOT_ALLOCATED",  {
  "idType": 0,   "typehref": "MANAGEDhttps://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/privatenetworks/5/ips/17",
  "highDisponibility": 0,   "passwordtype": "F8CYQsk4application/vnd.abiquo.privateip+json",
      "monitoredrel": false
}

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://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199" \
	 -H "Content-Type: application/vnd.abiquo.virtualmachine+json; version=4.4" \
     -H "Accept: application/vnd.abiquo.acceptedrequest+json; version=4.4" \
	 -u user:password \
 	 -d @VMnic.json

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.

Image Removed

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

Expand
Code Block
curl --verbose -X PUT "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199" \
	 -H "Content-Type: application/vnd.abiquo.virtualmachine+json; version=4.4" \
     -H "Accept: application/vnd.abiquo.acceptedrequest+json; version=4.4" \
	 -u user:password \
 	 -d '{
  "links": [
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199",
      "type": "application/vnd.abiquo.virtualmachine+json",
      "rel": "edit",
      "title": "ABQ_f26a16fb-d732-4d73-9bb6-0dbc34cd3a31"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/4",
      "type": "application/vnd.abiquo.enterprise+json",
      "rel": "enterprise",
      "title": "Accounting department"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/4/users/1",
      "type": "application/vnd.abiquo.user+json",
      "rel": "user",
      "title": "Cloud Administrator"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26",
      "type": "application/vnd.abiquo.virtualdatacenter+json",
      "rel": "virtualdatacenter",
      "title": "kvmvdc"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37",
      "type": "application/vnd.abiquo.virtualappliance+json",
      "rel": "virtualappliance",
      "title": "vapp_kvmvdc"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/metadata",
      "type": "application/vnd.abiquo.metadata+json",
      "rel": "metadata",
      "title": "metadata"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/network/configurations",
      "type": "application/vnd.abiquo.virtualmachinenetworkconfigurations+json",
      "rel": "configurations",
      "title": "vlan network configurations"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/network/nics",
      "type": "application/vnd.abiquo.nics+json",
      "rel": "nics",
      "title": "nics"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/storage/disks",
      "type": "application/vnd.abiquo.harddisks+json",
      "rel": "harddisks",
      "title": "disks"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/state",
      "type": "application/vnd.abiquo.virtualmachinestate+json",
      "rel": "state",
      "title": "NOT_ALLOCATED"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/undeploy",
      "type": "application/vnd.abiquo.acceptedrequest+json",
      "rel": "undeploy",
      "title": "virtual machine undeploy"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/deploy",
      "type": "application/vnd.abiquo.acceptedrequest+json",
      "rel": "deploy",
      "title": "virtual machine deploy"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/reset",
      "type": "application/vnd.abiquo.acceptedrequest+json",
      "rel": "reset",
      "title": "virtual machine reset"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/instance",
      "type": "application/vnd.abiquo.acceptedrequest+json",
      "rel": "instance",
      "title": "virtual machine snapshot"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/config/rdpaccess",
      "type": "application/vnd.abiquo.virtualmachineconsole+json",
      "rel": "rdpaccess",
      "title": "remote access"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/tasks",
      "type": "application/vnd.abiquo.tasks+json",
      "rel": "tasks",
      "title": "tasks"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/firewalls",
      "type": "application/vnd.abiquo.links+json",
      "rel": "firewalls",
      "title": "firewalls"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/loadbalancers",
      "type": "application/vnd.abiquo.loadbalancers+json",
      "rel": "loadbalancers",
      "title": "load balancers"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/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/26/virtualappliances/37/virtualmachines/199/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/26/virtualappliances/37/virtualmachines/199/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/26/virtualappliances/37/virtualmachines/199/storage/volumes",
      "type": "application/vnd.abiquo.volumes+json",
      "rel": "volumes",
      "title": "volumes"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/disks/216",
      "type": "application/vnd.abiquo.harddisk+json",
      "rel": "disk0",
      "title": "35a20d65-ff7f-4f65-8207-45751fa4e400",
      "length": "64",
      "diskLabel": "Hard disk 1",
      "diskControllerType": "IDE"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/locations/10/datastoretiers/3",
      "type": "application/vnd.abiquo.datastoretier+json",
      "rel": "datastoretier0",
      "title": "Default Tier"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/protect",
      "type": "text/plain",
      "rel": "protect",
      "title": "protect"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/unprotect",
      "type": "text/plain",
      "rel": "unprotect",
      "title": "unprotect"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/metrics",
      "type": "application/vnd.abiquo.metricsmetadata+json",
      "rel": "metricsmetadata",
      "title": "metricsmetadata"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/enablemonitoring",
      "type": "",
      "rel": "enablemonitoring",
      "title": "enablemonitoring"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/metrics/collectd",
      "type": "application/json",
      "rel": "collectd",
      "title": "collectd"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/alarms",
      "type": "application/vnd.abiquo.alarms+json",
      "rel": "alarmssearch",
      "title": "alarmssearch"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/26/virtualappliances/37/virtualmachines/199/action/clone",
      "type": "application/vnd.abiquo.virtualmachinecloneoptions+json",
      "rel": "clone",
      "title": "clone"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/hypervisortypes/KVM",
      "type": "application/vnd.abiquo.hypervisortype+json",
      "rel": "hypervisortype",
      "title": "KVM"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/4/datacenterrepositories/10/virtualmachinetemplates/243",
      "type": "application/vnd.abiquo.virtualmachinetemplate+json",
      "rel": "virtualmachinetemplate",
      "title": "yVM"
    },
    {
      "href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/categories/1",
      "type": "application/vnd.abiquo.category+json",
      "rel": "category",
      "title": "Others"
    },
    {
      "href": ""nic0",
      "title": "privateip"
    }
  ],
  "natrules": [],
  "generateGuestInitialPassword": false,
  "backuppolicies": [],
  "creationTimestamp": 1560939950000,
  "variables": {},
  "protected": false,
  "monitored": false,
  "ram": 48,
  "coresPerSocket": 1,
  "cpu": 1,
  "description": "A virtual machine",
  "label": "yVM_New",
  "name": "ABQ_06cfadf0-db57-48c5-8f4c-f9fe2ca76c46",
  "uuid": "06cfadf0-db57-48c5-8f4c-f9fe2ca76c46",
  "id": 8,
  "vdrpEnabled": true,
  "vdrpPort": 0,
  "idState": 1,
  "state": "NOT_ALLOCATED",
  "idType": 0,
  "type": "MANAGED",
  "highDisponibility": 0,
  "password": "VUFvbvoa"
}


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://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/8' \
	 -H 'Content-Type: application/vnd.abiquo.virtualmachine+json; version=4.6' \
     -H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=4.6' \
	 -u admin:xabiquo \
 	 -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.

Image Added

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

Expand


Code Block
user@user:~/Documents/tutorials $ curl --verbose -X PUT 'https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/privatenetworksvirtualappliances/342/ips/217",virtualmachines/8'       "type"-H 'Content-Type: "application/vnd.abiquo.privateipvirtualmachine+json",
      "rel": "nic0",
      "title": "privateip"
    }
  ],
  "iconUrl": "https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png",
  "natrules": [],
  "generateGuestInitialPassword": false,
  "backuppolicies": [],
  "creationTimestamp": 1536229326000,
  "variables": {},
  "protected": false,
  "vdrpEnabled": true,
  "ram": 48,
  "cpu": 1,
  "description": "A virtual machine",
  "label": "yVM_New",
  "name": "ABQ_f26a16fb-d732-4d73-9bb6-0dbc34cd3a31",
  "uuid": "f26a16fb-d732-4d73-9bb6-0dbc34cd3a31",
  "id": 199,
  "vdrpPort": 0,
  "idState": 1,
  "state": "NOT_ALLOCATED",
  "idType": 0,
  "type": "MANAGED",
  "highDisponibility": 0,
  "password": "F8CYQsk4",
  "monitored": false
}'; version=4.6'      -H 'Accept: application/vnd.abiquo.acceptedrequest+json; version=4.6'  -u admin:xabiquo   -d @VMnic.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/virtualappliances/2/virtualmachines/8 HTTP/1.1
> Authorization: Basic YWRtaW46eGFiaXF1bw==
> User-Agent: curl/7.35.0
> Host: mjsabiquo.bcn.abiquo.com
> Content-Type: application/vnd.abiquo.virtualmachine+json; version=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
< 



Power actions on a VM

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

Include Page
VM power actions using the API
VM power actions using the API

Delete an entity through 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://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/262/virtualappliances/372/virtualmachines/1988 \
     -H 'Accept: text/json,application/json;' \ 
	 -u user:password

...