Versions Compared

Key

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

...

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

...

titleGET all Virtual Machines in the Cloud

...

 Here we are filtering the VMs using the "has" parameter to select the one that has "ABQ_2fade" as part of the name, which is an easy way to find a VM that you have located in the UI.

Code Block
titleGET all virtual machines in the cloud, filtering by 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

...

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

...

The platform will store the VM startup script in the VM metadata under the "startup-script" key.

Abiquo supports cloud-config scripts with cloud-init templates in private cloud, and in public cloud. 

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

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

...

Code Block
#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 And after you escape the special characters it will look like this:

...

Code Block
{
    "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 And that's a wrapall(big grin)

Access metadata as part of the VM

Here we made a GET request to obtain the VM object and we removed the links to make it smallereasier to read. Here, the metadata object is part of the VM but the links list is not shown.

Code Block
        {
            "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": [],

  ....
        }

So Although you can read the metadata here, the most complete 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 when we retrieved the empty metadata object.

...