News

Back
2019
September
24
2019

Keeping Track with Tags

One server seldom comes alone: another server is quickly added for the test environment, an additional volume holds archived data, and Floating IPs enable high availability. When the naming scheme hits its limits, the new tags feature helps to ensure that you always know what belongs together.

How tags help you stay on top of things

Tags make it clear at a glance what a particular resource is all about or where it belongs. Such "labels" with key/value pairs can be attached to most of your resources: servers and server groups; volumes; Floating IPs; and Objects Users. This allows you, for example, to differentiate between "prod" and "development" environments, to associate resources with the respective end customer, or to record a comment.

When querying resources, you can filter them directly by tag to display only the relevant objects. Filtering can be done by a specific tag content (e.g. "tag:Env=Prod" for all production servers) or by the presence of a given tag regardless of its content (e.g. "tag:Customer" for all servers assigned to any end customer).

How tags are created and retrieved

Tags are currently implemented for our API. The already existing endpoints of the supported resources now recognize an element "tags", which accepts a JSON object with freely definable key/value pairs. These are automatically included in the output of a GET request, as in the simplified example below:

[
  {
    "href": "https://api.cloudscale.ch/v1/servers/c10...",
    "name": "WebWorker1",
    "created_at": "2019-09-18T17:48:21.547057Z",
    "status": "running",
    "flavor": {
      "slug": "flex-32",
      "name": "Flex-32",
      "vcpu_count": 8,
      "memory_gb": 32
    },
    "server_groups": [],
    "anti_affinity_with": [],
    "tags": {
      "Env": "Prod",
      "Customer": "Cloud Corp.",
      "Lifecycle": "Installing",
      "Comment": "Don't forget the monitoring! (Remove comment when done.)"
    }
  }
]

Tags are set and changed using a PATCH request to the URL of the resource in question:

$ curl -H "$AUTH_HEADER" -H "Content-Type: application/json" -X PATCH --data '{ "tags": { "Env": "Prod", "Customer": "Cloud Corp.", "Lifecycle": "Live" }}' https://api.cloudscale.ch/v1/servers/c10...

If only resources with a certain tag are to be retrieved, the desired criterion is simply appended as a URL parameter:

$ curl -H "$AUTH_HEADER" https://api.cloudscale.ch/v1/servers?tag:Env=Prod

It goes without saying that further information and examples can also be found in our API documentation. In addition, our Ansible Cloud Module supports tags for the most important resources starting with the upcoming Ansible version 2.9.


With tags, we are responding to a request made by several power users among our customers. We are glad that all our users can benefit from this helpful feature, which allows you to navigate even large deployments with ease.

Keeping everything in order with tags,
Your cloudscale.ch team

Back to overview