Abiquo virtual machine metadata
...
Writing metadata will overwrite ALL existing metadata, so the first step is to to obtain a base object to modify, retrieve the existing metadata in the appropriate format. Abiquo recommends JSON format. Then add new metadata keys and values as required.
Note: Do not use a conversion tool to convert between JSON and XML format because this may produce an incompatible data transfer object.
Excerpt |
---|
For the metadata attribute |
...
or object, Abiquo has the reserved keys that are described in the following table. |
...
keys | Description |
---|
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 | | Cloud-config for use by cloud-init Users enter Startup script in the UI, on the VM dialog on the Bootstrap script tab
| Metrics | | | Custom |
|
...
VM metadata tutorial
This tutorial will show you have how 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 a VM that is powered off)
- An optional monitoring server
User with privileges to
modify VMs and enable monitoringwork with VMs and Manage virtual machine backup configuration (VAPP_MANAGE_BACKUP) because backups previously used metadata
Optional: a monitoring server and a user with the privileges to Manage virtual machine metrics (USERS_ENABLE_DISABLE_VM_METRICS)
Get the VM and the metadata link
To get started, use the a query to retrieve all of your VMs from the cloud and select the desired VM.
Code Block |
---|
title | 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 |
...
title | Click here to show or hide the API response example |
---|
Success status code: 200
Response:
...
Here we are filtering the VMs using the "vmlabel" parameter to select the one that has a text string (in this case "metadata") as part of the name, which is an easy way to find a VM that you have located in the UI.
GET all virtual machines in the cloud, filtering by name
Code Block |
---|
curl -X GET https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualmachines?vmlabel=metadata \
-H "Accept: application/vnd.abiquo.virtualmachines+json; version=4.7" \
-u user:password --verbose | pjson |
Expand |
---|
title | Click here to show or hide the API response example |
---|
|
Success status code: 200 Response: Code Block |
---|
{
"totalSize": 1,
"links": [
{
"rel": "first",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualmachines?vmlabel=metadata&limit=25&by=name&asc=true"
},
{
"rel": "last",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualmachines?vmlabel=metadata&startwith=0&limit=25&by=name&asc=true"
}
],
"collection": [
{
"id": 3,
"uuid": "d0876a63-4238-4182-9d10-5f4f363101b9",
"description": "root : abiquo",
"coresPerSocket": 1,
"idState": 1,
"idType": 0,
"type": "MANAGED",
"highDisponibility": 0,
"monitored": false,
"protected": false,
"variables": {},
"backuppolicies": [],
"generateGuestInitialPassword": false,
"natrules": [],
"vdrpEnabled": true,
"vdrpPort": 0,
"password": "MLiRXdmv",
"deallocated": false,
"name": "ABQ_d0876a63-4238-4182-9d10-5f4f363101b9",
"label": "metadatavm",
"ram": 64,
"cpu": 1,
"state": "NOT_ALLOCATED",
"creationTimestamp": 1583494480000,
"iconUrl": "http://rs.bcn.abiquo.com:9000/public/icons/tinycore.png",
"links": [
{
|
|
...
...
...
...
...
...
...
...
...
...
application/vnd.abiquo.enterprise+json",
"href": "https://mjsabiquo.bcn.abiquo. |
|
...
com:443/api/admin/enterprises/1"
|
|
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
"type": "application/vnd.abiquo.virtualmachine+json",
|
|
...
...
...
...
...
...
"https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/3"
|
|
...
...
...
...
...
...
...
...
...
...
...
...
...
application/vnd.abiquo.mail+json",
|
|
...
...
...
...
https://mjsabiquo.bcn.abiquo.com:443/api/admin/publiccloudregions/1/enterprises/1/virtualmachines/3/action/sendmail"
|
|
...
...
...
...
...
...
...
...
...
...
...
...
"application/vnd.abiquo.user+json",
|
|
...
...
...
"https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/1/users/1"
|
|
...
...
bcdc_vdc_01_01_01",
"rel": " |
|
...
virtualdatacenter",
"type": "application/vnd.abiquo. |
|
...
virtualdatacenter+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
bcdc_vapp_aa_aa_aa",
"rel": " |
|
...
virtualappliance",
"type": "application/vnd.abiquo. |
|
...
virtualappliance+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/ |
|
...
...
virtualappliances/1"
},
{
"title": " |
|
...
...
metadata",
"type": "application/vnd.abiquo. |
|
...
metadata+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/ |
|
...
...
...
virtualappliances/1/virtualmachines/3/metadata"
},
{
"title": " |
|
...
vlan network configurations",
"rel": " |
|
...
configurations",
"type": "application/vnd.abiquo. |
|
...
virtualmachinenetworkconfigurations+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters |
|
...
/1/virtualappliances/1/virtualmachines/3/network/configurations"
},
{
"title": " |
|
...
...
nics",
"type": "application/vnd.abiquo. |
|
...
nics+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
/1/virtualmachines/3/network/nics"
},
{
"title": " |
|
...
...
harddisks",
"type": "application/vnd.abiquo. |
|
...
harddisks+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
...
state",
"type": "application/vnd.abiquo. |
|
...
virtualmachinestate+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
virtual machine undeploy",
"rel": " |
|
...
undeploy",
"type": "application/vnd.abiquo. |
|
...
acceptedrequest+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
undeploy"
},
{
"title": " |
|
...
virtual machine deploy",
"rel": " |
|
...
deploy",
"type": "application/vnd.abiquo. |
|
...
acceptedrequest+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
...
virtual machine reset",
"rel": " |
|
...
reset",
"type": "application/vnd.abiquo. |
|
...
acceptedrequest+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
reset"
},
{
"title": "virtual machine |
|
...
...
instance",
"type": "application/vnd.abiquo.acceptedrequest+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
instance"
},
{
"title": " |
|
...
...
...
rdpaccess",
"type": "application/vnd.abiquo. |
|
...
virtualmachineconsole+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
rdpaccess"
},
{
"title": " |
|
...
...
tasks",
"type": "application/vnd.abiquo. |
|
...
tasks+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
...
firewalls",
"type": "application/vnd.abiquo. |
|
...
links+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
firewalls"
},
{
"title": " |
|
...
...
...
loadbalancers",
"type": "application/vnd.abiquo. |
|
...
loadbalancers+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
loadbalancers"
},
{
"title": " |
|
...
request on demand backup",
"rel": " |
|
...
requestbackup",
"type": "application/vnd.abiquo. |
|
...
ondemandbackup+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
1/virtualmachines/3/backup/ |
|
...
...
...
request a restore of a backup",
"rel": " |
|
...
requestrestore",
"type": "application/vnd.abiquo. |
|
...
restore+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
3/backup/action/restore"
},
{
"title": " |
|
...
move VM to a virtual appliance",
"rel": " |
|
...
vappmove",
"type": "application/vnd.abiquo. |
|
...
links+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
vappmove"
},
{
"title": " |
|
...
move VM to another virtual datacenter",
"rel": " |
|
...
move",
"type": "application/vnd.abiquo. |
|
...
movevm+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
...
...
volumes",
"type": "application/vnd.abiquo. |
|
...
volumes+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
...
...
...
...
...
...
...
...
...
"title": "f9693188-5e49-430c-bb38-fc70916dcfb4",
|
|
...
...
...
application/vnd.abiquo.harddisk+json",
" |
|
...
...
"https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/1/disks/5"
},
|
|
...
...
...
datastoretier0",
"type": "application/vnd.abiquo. |
|
...
datastoretier+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/ |
|
...
...
...
...
...
...
...
...
...
...
...
...
"length": "100",
"title": " |
|
...
d5acae19-9202-4bec-a600-4ee66ef4d26b",
"rel": " |
|
...
...
application/vnd.abiquo.harddisk+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
datastoretier1",
"type": " |
|
...
application/vnd.abiquo.datastoretier+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/ |
|
...
...
...
datastoretiers/1"
},
{
"title": " |
|
...
...
...
text/plain",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
...
unprotect",
"type": "text/plain",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
unprotect"
},
{
"title": " |
|
...
metricsmetadata",
"rel": " |
|
...
metricsmetadata",
"type": "application/vnd.abiquo.metricsmetadata+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
...
enablemonitoring",
"rel": " |
|
...
enablemonitoring",
"type": " |
|
...
",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
enablemonitoring"
},
{
"title": " |
|
...
...
collectd",
"type": "application/ |
|
...
json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
collectd"
},
{
"title": " |
|
...
...
alarmssearch",
"type": "application/vnd.abiquo. |
|
...
alarms+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
...
alarms"
},
{
"title": "clone",
"rel": "clone",
"type": "application/vnd.abiquo.virtualmachinecloneoptions+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/ |
|
...
...
...
3/action/clone"
},
{
"title": "KVM",
"rel": "hypervisortype",
"type": "application/vnd.abiquo.hypervisortype+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/hypervisortypes/KVM"
},
{
"title": " |
|
...
core_duplicate",
"rel": "virtualmachinetemplate",
"type": "application/vnd.abiquo.virtualmachinetemplate+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/ |
|
...
22"
},
{
"title": "Others",
"rel": "category",
"type": "application/vnd.abiquo.category+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/config/categories/1"
}
],
|
|
...
...
...
...
From the VM data object, the link to the VM metadata is the one with the "rel" value of metadata.
Code Block |
---|
{
"title": "metadata",
"rel": "metadata",
"type": "application/vnd.abiquo.metadata+json",
"href": "https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/21/virtualappliances/21/virtualmachines/243/metadata"
}, |
There is also a metadata attribute in the VM with a null value, but the correct way to access metadata is using the metadata link.
...
Use the VM metadata link from the step above to retrieve any existing metadata.
Code Block |
---|
curl -X GET httphttps://localhost:9000mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/21/virtualappliances/21/virtualmachines/243/metadata \
-H 'Accept:application/vnd.abiquo.metadata+json; version=4.27' \
-u user:password --verbose |
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.
Code Block |
---|
{
"links": [],
"metadata": null
} |
...
Optionally enable monitoring, select metrics, and retrieve metadata again
FirstTo move ahead quickly, 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.
Code Block |
---|
{
"links":
[], "metadata": {
"monitoring-metrics": []
},
"links": []
} |
Now select one or more metrics to retrieve. Here In the UI we selected two of the built-in metrics from a KVM hypervisor and performed the GET request again.
Code Block |
---|
{
"links": [],
"metadata": {
"monitoring-metrics": [
{
"name": "cpuused_timemem"
},
{
"name": "usedcpu_memtime"
}
]
},
"links": []
} |
Prepare a metadata object with a VM startup script
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.
Disclaimer: this is a sample script for illustrative purposes only. Please see cloud-init documentation to find out how this script works.
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 |
---|
#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\" |
...
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 For our example, after adding the startup script, the metadata object should look something object looked 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\""
},
"links": []
} |
Update VM metadata
To update the VM metadata, perform a PUT request to the metadata link.
Code Block |
---|
curl -X PUT http://localhost:9000https://mjsabiquo.bcn.abiquo.com:443/api/cloud/virtualdatacenters/21/virtualappliances/21/virtualmachines/243/metadata \
-H 'Accept:application/vnd.abiquo.metadata+json; version=4.27' \
-H 'Content-Type:application/vnd.abiquo.metadata+json; version=4.27' \
-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
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\""
}
} |
If the request is successful, it will return a status code of 200 and the updated metadata object.
Code Block |
---|
{
"links": [],
"metadata": {
"monitoring-metrics": [
{
"name": "cpu_time"
": {
"monitoring-metrics": [
}, {
"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\""name": "cpu_time"
} } |
So that's a wrap!
Access 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. Here, the metadata object is part of the VM but the links list is not shown.
Code Block |
---|
}
{ ],
"idstartup-script": 24,"#cloud-config\r\nusers:\r\n - name: \"myuser\"\r\n \t# mkpasswd --method=SHA-512 --rounds=4096 mypass\r\n "uuid" passwd: "2fade39a-fe59-44b4-be3f-b96b63b48153",\"$6$rounds=4096$aD0didNw/$Pau0z3YK2Ss5MWYoxScEedfMa.1N5qRqK0xYrgs79qdjHdoFUIRmVXpeEewDduSbImu7sqIjSRm40xO6PpJhk/\" \r\n groups:\r\n - \"sudo\"\r\nssh_authorized_keys:\r\n - "name": "ABQ_2fade39a-fe59-44b4-be3f-b96b63b48153",\"ssh-rsa USER_ID_RSA.PUB\""
},
"labellinks": "VM_metadata",
[]
} |
And that's all!
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 easier to read. Here, the metadata object is part of the VM but the links list is not shown.
Code Block |
---|
"description": "A virtual machine",{
"cpuid": 13,
"ramuuid": 48"d0876a63-4238-4182-9d10-5f4f363101b9",
"vdrpEnableddescription": true,"root "vdrpPort": 0: abiquo",
"idStatecoresPerSocket": 1,
"stateidState": "NOT_ALLOCATED"1,
"idType": 0,
"type": "MANAGED",
"highDisponibility": 0,
"password": "uMvMpfyD",
"metadata": {
"monitoring-metrics": [
{
"name": "cpuused_timemem"
},
{
"name": "usedcpu_memtime"
}
],
"startup-script": "#cloud-config\r\nhostname: \"userdatahostname\"config\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": [],
....
}
|
...
Although you can read the metadata here, the most correct and convenient way to work with VM metadata is using the metadata link !as described in the previous steps.
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.
Related links
Some API references about working with VM metadata: