Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 27 Next »

Abiquo virtual machine metadata

Abiquo stores some information in VMs as metadata and allows users to store custom metadata too. To access metadata, use the link with the "rel" value of "metadata" in the VM.

The first step is to retrieve the existing metadata in the appropriate format. Abiquo recommends JSON format. Do not use a conversion tool to convert between JSON and XML format because this may produce an incompatible data transfer object.

Always use the existing metadata as the starting point for creating a new object to write. This is because writing metadata will overwrite ALL existing metadata


For the metadata attribute, Abiquo has the reserved keys that are described in the following table.

Metadata typeReserved KeysDescription
Chef
  • chef
  • Users enter Chef recipe attributes as JSON in the UI, in the VM dialog on the Chef / Attributes tab 
  • Abiquo stores the recipe attributes that you enter in JSON format as an escaped string under the chef key
Bootstrap script
  • startup-script
  • Cloud-config for use by cloud-init
  • Users enter Startup script in the UI, on the VM dialog on the Bootstrap script tab
Metrics
  • monitoring-metrics
  • Names of the metrics available for the VM – useful for accessing metrics via API
Custom 
  • Append custom metadata to the existing metadata
  • Do not use the Abiquo reserved metadata keys

VM metadata tutorial

This tutorial will show you have to retrieve and update metadata to add a startup script to your VM via API.

To work through this tutorial, you will need:

  • A VM that is not deployed (or powered off)
    • This tutorial shows a VM that is not deployed
  • An optional monitoring server
  • User with privileges to modify VMs and enable monitoring

To get started, use the query to retrieve all of your VMs from the cloud and select the desired VM.

GET all Virtual Machines in the Cloud
* No special privileges are required to get all the VMs that your user can access
* Here we are filtering the VMs using the "has" parameter to select the one that has "ABQ_2fade" in the name
curl -X GET https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualmachines?has=ABQ_2fade \
	-H "Accept: application/vnd.abiquo.virtualmachines+json; version=4.2" \ 
	-u user:password --verbose | pjson
 Click here to show or hide the API response example

Success status code: 200

Response:

{
    "links": [
        {
            "rel": "first",
            "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualmachines?limit=25&has=ABQ_2fade&by=name&asc=true"
        },
        {
            "rel": "last",
            "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualmachines?startwith=0&limit=25&has=ABQ_2fade&by=name&asc=true"
        }
    ],
    "collection": [
        {
            "id": 24,
            "uuid": "2fade39a-fe59-44b4-be3f-b96b63b48153",
            "name": "ABQ_2fade39a-fe59-44b4-be3f-b96b63b48153",
            "label": "VM_metadata",
            "description": "A virtual machine",
            "cpu": 1,
            "ram": 48,
            "vdrpEnabled": true,
            "vdrpPort": 0,
            "idState": 1,
            "state": "NOT_ALLOCATED",
            "idType": 0,
            "type": "MANAGED",
            "highDisponibility": 0,
            "password": "uMvMpfyD",
            "metadata": null,
            "monitored": false,
            "protected": false,
            "variables": {},
            "creationTimestamp": 1520865331000,
            "backuppolicies": [],
            "generateGuestInitialPassword": false,
            "natrules": [],
            "links": [
                {
                    "title": "ABQ_2fade39a-fe59-44b4-be3f-b96b63b48153",
                    "rel": "edit",
                    "type": "application/vnd.abiquo.virtualmachine+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24"
                },
                {
                    "title": "Abiquo",
                    "rel": "enterprise",
                    "type": "application/vnd.abiquo.enterprise+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/1"
                },
                {
                    "title": "Cloud Administrator",
                    "rel": "user",
                    "type": "application/vnd.abiquo.user+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/1/users/1"
                },
                {
                    "title": "MJ_backup",
                    "rel": "virtualdatacenter",
                    "type": "application/vnd.abiquo.virtualdatacenter+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2"
                },
                {
                    "title": "vapp_backup",
                    "rel": "virtualappliance",
                    "type": "application/vnd.abiquo.virtualappliance+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2"
                },
                {
                    "title": "metadata",
                    "rel": "metadata",
                    "type": "application/vnd.abiquo.metadata+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/metadata"
                },
                {
                    "title": "vlan network configurations",
                    "rel": "configurations",
                    "type": "application/vnd.abiquo.virtualmachinenetworkconfigurations+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/network/configurations"
                },
                {
                    "title": "nics",
                    "rel": "nics",
                    "type": "application/vnd.abiquo.nics+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/network/nics"
                },
                {
                    "title": "disks",
                    "rel": "harddisks",
                    "type": "application/vnd.abiquo.harddisks+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/storage/disks"
                },
                {
                    "title": "NOT_ALLOCATED",
                    "rel": "state",
                    "type": "application/vnd.abiquo.virtualmachinestate+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/state"
                },
                {
                    "title": "virtual machine undeploy",
                    "rel": "undeploy",
                    "type": "application/vnd.abiquo.acceptedrequest+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/action/undeploy"
                },
                {
                    "title": "virtual machine deploy",
                    "rel": "deploy",
                    "type": "application/vnd.abiquo.acceptedrequest+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/action/deploy"
                },
                {
                    "title": "virtual machine reset",
                    "rel": "reset",
                    "type": "application/vnd.abiquo.acceptedrequest+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/action/reset"
                },
                {
                    "title": "virtual machine snapshot",
                    "rel": "instance",
                    "type": "application/vnd.abiquo.acceptedrequest+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/action/instance"
                },
                {
                    "title": "remote access",
                    "rel": "rdpaccess",
                    "type": "application/vnd.abiquo.virtualmachineconsole+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/config/rdpaccess"
                },
                {
                    "title": "tasks",
                    "rel": "tasks",
                    "type": "application/vnd.abiquo.tasks+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/tasks"
                },
                {
                    "title": "firewalls",
                    "rel": "firewalls",
                    "type": "application/vnd.abiquo.links+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/firewalls"
                },
                {
                    "title": "load balancers",
                    "rel": "loadbalancers",
                    "type": "application/vnd.abiquo.loadbalancers+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/loadbalancers"
                },
                {
                    "title": "request on demand backup",
                    "rel": "requestbackup",
                    "type": "application/vnd.abiquo.ondemandbackup+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/backup/action/request"
                },
                {
                    "title": "request a restore of a backup",
                    "rel": "requestrestore",
                    "type": "application/vnd.abiquo.restore+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/backup/action/restore"
                },
                {
                    "title": "volumes",
                    "rel": "volumes",
                    "type": "application/vnd.abiquo.volumes+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/storage/volumes"
                },
                {
                    "diskControllerType": "IDE",
                    "diskLabel": "Hard disk 1",
                    "length": "64",
                    "title": "d5c3c598-5086-497f-8ed1-58d9d4138902",
                    "rel": "disk0",
                    "type": "application/vnd.abiquo.harddisk+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/disks/25"
                },
                {
                    "title": "Default Tier",
                    "rel": "datastoretier0",
                    "type": "application/vnd.abiquo.datastoretier+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/locations/1/datastoretiers/1"
                },
                {
                    "title": "protect",
                    "rel": "protect",
                    "type": "text/plain",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/action/protect"
                },
                {
                    "title": "unprotect",
                    "rel": "unprotect",
                    "type": "text/plain",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/action/unprotect"
                },
                {
                    "title": "metricsmetadata",
                    "rel": "metricsmetadata",
                    "type": "application/vnd.abiquo.metricsmetadata+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/metrics"
                },
                {
                    "title": "enablemonitoring",
                    "rel": "enablemonitoring",
                    "type": "",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/enablemonitoring"
                },
                {
                    "title": "collectd",
                    "rel": "collectd",
                    "type": "application/json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/metrics/collectd"
                },
                {
                    "title": "alarms",
                    "rel": "alarms",
                    "type": "application/vnd.abiquo.alarms+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/alarms"
                },
                {
                    "title": "actionplans",
                    "rel": "actionplans",
                    "type": "application/vnd.abiquo.virtualmachineactionplans+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/actionplans"
                },
                {
                    "title": "actionplansflat",
                    "rel": "actionplansflat",
                    "type": "application/vnd.abiquo.virtualmachineactionplansflat+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/actionplans"
                },
                {
                    "title": "clone",
                    "rel": "clone",
                    "type": "application/vnd.abiquo.virtualmachinecloneoptions+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/action/clone"
                },
                {
                    "title": "KVM",
                    "rel": "hypervisortype",
                    "type": "application/vnd.abiquo.hypervisortype+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/hypervisortypes/KVM"
                },
                {
                    "title": "yVM",
                    "rel": "virtualmachinetemplate",
                    "type": "application/vnd.abiquo.virtualmachinetemplate+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/3"
                },
                {
                    "title": "Others",
                    "rel": "category",
                    "type": "application/vnd.abiquo.category+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/categories/1"
                }
            ]
        }
    ],
    "totalSize": 1,
    "duplicatedvms": []
} 

From the VM data object, the link to the VM metadata is the one with the "rel" value of metadata.

                {
                    "title": "metadata",
                    "rel": "metadata",
                    "type": "application/vnd.abiquo.metadata+json",
                    "href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/metadata"
                },


Retrieve existing VM metadata

Use the VM metadata link from the step above to retrieve any existing metadata.

curl -X GET http://localhost:9000/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/metadata \
     -H 'Accept:application/vnd.abiquo.metadata+json; version=4.2' \
     -u user:password --verbose

When there is no metadata, the query returns a 200 status code, and the data object has an empty links list and a null metadata attribute.

{
    "links": [],
    "metadata": null
}


Enable monitoring, select metrics and retrieve metadata again

First, in the UI, just enable "Fetch metrics" and don't select any metrics to retrieve. Then retrieve metadata again using the same GET request as in the previous step.

The metadata object will now have an empty monitoring-metrics list.

{
    "links": [],
    "metadata": {
        "monitoring-metrics": []
    }
}

Now select one or more metrics to retrieve. Here we selected two of the built-in metrics from a KVM hypervisor and performed the GET request again. 

{
    "links": [],
    "metadata": {
        "monitoring-metrics": [
            {
                "name": "cpu_time"
            },
            {
                "name": "used_mem"
            }
        ]
    }
} 

Prepare a VM startup script

The VM startup script is stored in the VM metadata under the startup-script key.

Abiquo supports cloud-setup scripts with cloud-init templates and in public cloud. 

To add the startup script to the JSON object, you will need to escape any special characters, such as quotation marks, in the script.

So for example, we have the following script for use with a cloud-init template on a Linux system.

(minus) Disclaimer: this is a sample script for illustrative purposes only. Please see cloud-init documentation to find out how this script works.

#cloud-config
hostname: "userdatahostname"
users:
  - name: "myuser"
  	# mkpasswd --method=SHA-512 --rounds=4096 mypass
    passwd: "$6$rounds=4096$aD0didNw/$Pau0z3YK2Ss5MWYoxScEedfMa.1N5qRqK0xYrgs79qdjHdoFUIRmVXpeEewDduSbImu7sqIjSRm40xO6PpJhk/" 
    groups:
      - "sudo"
ssh_authorized_keys:
  - "ssh-rsa USER_ID_RSA.PUB"

After you escape the special characters it will look like this:

#cloud-config\r\nhostname: \"userdatahostname\"\r\nusers:\r\n  - name: \"myuser\"\r\n  \t# mkpasswd --method=SHA-512 --rounds=4096 mypass\r\n    passwd: \"$6$rounds=4096$aD0didNw\/$Pau0z3YK2Ss5MWYoxScEedfMa.1N5qRqK0xYrgs79qdjHdoFUIRmVXpeEewDduSbImu7sqIjSRm40xO6PpJhk\/\" \r\n    groups:\r\n      - \"sudo\"\r\nssh_authorized_keys:\r\n  - \"ssh-rsa USER_ID_RSA.PUB\"

Tip: you can use a JSON string escape/unescape tool to create this format.

Add the startup script to the metadata object with the "startup-script" key. Don't forget to add a comma after the previous object.  After you add the startup script, the metadata object should look something like this:

{
    "links": [],
    "metadata": {
        "monitoring-metrics": [
            {
                "name": "cpu_time"
            },
            {
                "name": "used_mem"
            }
        ],
        "startup-script": 
"#cloud-config\r\nhostname: \"userdatahostname\"\r\nusers:\r\n  - name: \"myuser\"\r\n  \t# mkpasswd --method=SHA-512 --rounds=4096 mypass\r\n    passwd: \"$6$rounds=4096$aD0didNw\/$Pau0z3YK2Ss5MWYoxScEedfMa.1N5qRqK0xYrgs79qdjHdoFUIRmVXpeEewDduSbImu7sqIjSRm40xO6PpJhk\/\" \r\n    groups:\r\n      - \"sudo\"\r\nssh_authorized_keys:\r\n  - \"ssh-rsa USER_ID_RSA.PUB\"" 
    }
} 

Update VM metadata

To update the VM metadata, perform a PUT request to the metadata link.

curl -X PUT http://localhost:9000/api/cloud/virtualdatacenters/2/virtualappliances/2/virtualmachines/24/metadata \
     -H 'Accept:application/vnd.abiquo.metadata+json; version=4.2' \
     -H 'Content-Type:application/vnd.abiquo.metadata+json; version=4.2' \
     -d @requestpayload.json \
     -u user:password --verbose

In this case, the requestpayload.json file should contain the JSON object from the previous step.

Metadata requestpayload.json object
{
    "links": [],
    "metadata": {
        "monitoring-metrics": [
            {
                "name": "cpu_time"
            },
            {
                "name": "used_mem"
            }
        ],
        "startup-script": 
"#cloud-config\r\nhostname: \"userdatahostname\"\r\nusers:\r\n  - name: \"myuser\"\r\n  \t# mkpasswd --method=SHA-512 --rounds=4096 mypass\r\n    passwd: \"$6$rounds=4096$aD0didNw\/$Pau0z3YK2Ss5MWYoxScEedfMa.1N5qRqK0xYrgs79qdjHdoFUIRmVXpeEewDduSbImu7sqIjSRm40xO6PpJhk\/\" \r\n    groups:\r\n      - \"sudo\"\r\nssh_authorized_keys:\r\n  - \"ssh-rsa USER_ID_RSA.PUB\"" 
    }
} 

If the request is successful, it will return a status code of 200 and the updated metadata object.

{
    "links": [],
    "metadata": {
        "monitoring-metrics": [
            {
                "name": "cpu_time"
            },
            {
                "name": "used_mem"
            }
        ],
        "startup-script": "#cloud-config\r\nhostname: \"userdatahostname\"\r\nusers:\r\n  - name: \"myuser\"\r\n  \t# mkpasswd --method=SHA-512 --rounds=4096 mypass\r\n    passwd: \"$6$rounds=4096$aD0didNw/$Pau0z3YK2Ss5MWYoxScEedfMa.1N5qRqK0xYrgs79qdjHdoFUIRmVXpeEewDduSbImu7sqIjSRm40xO6PpJhk/\" \r\n    groups:\r\n      - \"sudo\"\r\nssh_authorized_keys:\r\n  - \"ssh-rsa USER_ID_RSA.PUB\""
    }
}

So that's a wrap! (big grin)

Get metadata as part of the VM

Here we made a GET request to obtain the VM object and removed the links to make it smaller. The metadata object is part of the VM.

        {
            "id": 24,
            "uuid": "2fade39a-fe59-44b4-be3f-b96b63b48153",
            "name": "ABQ_2fade39a-fe59-44b4-be3f-b96b63b48153",
            "label": "VM_metadata",
            "description": "A virtual machine",
            "cpu": 1,
            "ram": 48,
            "vdrpEnabled": true,
            "vdrpPort": 0,
            "idState": 1,
            "state": "NOT_ALLOCATED",
            "idType": 0,
            "type": "MANAGED",
            "highDisponibility": 0,
            "password": "uMvMpfyD",
            "metadata": {
                "monitoring-metrics": [
                    {
                        "name": "cpu_time"
                    },
                    {
                        "name": "used_mem"
                    }
                ],
                "startup-script": "#cloud-config\r\nhostname: \"userdatahostname\"\r\nusers:\r\n  - name: \"myuser\"\r\n  \t# mkpasswd --method=SHA-512 --rounds=4096 mypass\r\n    passwd: \"$6$rounds=4096$aD0didNw/$Pau0z3YK2Ss5MWYoxScEedfMa.1N5qRqK0xYrgs79qdjHdoFUIRmVXpeEewDduSbImu7sqIjSRm40xO6PpJhk/\" \r\n    groups:\r\n      - \"sudo\"\r\nssh_authorized_keys:\r\n  - \"ssh-rsa USER_ID_RSA.PUB\""
            },
            "monitored": true,
            "protected": false,
            "variables": {},
            "creationTimestamp": 1520865331000,
            "backuppolicies": [],
            "generateGuestInitialPassword": false,
            "natrules": [],

  ....
        }

However, the appropriate and most convenient way to work with VM metadata is using the metadata link!

Delete metadata

If you ever need to delete the VM metadata, just send a DELETE request to the metadata link. But remember that this request will delete ALL metadata, leaving just the empty links list and the null metadata key, as shown in the first example about where we retrieved empty metadata.

API references about working with VM metadata:

  • No labels