Changing a devices tags from within a container on that device

Hey all,

I was wondering if there was a way to change devices tags from within the device.

The desired use-case would be to have more detailed status information available at a glance and able to be filtered apon and sorted like tags can be.

I would prefer if the python SDK was somehow exposed, but I would be happy with dbus commands to the supervisor.

Thanks,
-Thomas

We’ve got an old project on balena-io-playground which I’m going to be testing right now to check whether it’s still up-to-date. You can feel free to give it a try as well!

It relies on running curl against v3 of the API (we’re now on v4 as you can see in the docs but the endpoints are still up and working for v3), which relies on the BALENA_API_KEY variable being present inside the container. This in turn relies on setting the io.balena.features.balena-api label [1]

[1] https://www.balena.io/docs/reference/supervisor/docker-compose/#labels

This looks perfect. That variable is already exposed properly.

Will the endpoint for V3 be up for a good amount of time? And does your internal support system support tagging this form post for an update if at some point in the future they are going to get shut down?

I will test it out if it works for my use-case tomorrow, but it seems like it should work fine and do exactly what I want.

Thank you

-Thomas

Something else to note: server.js in that repo in fact uses the SDK as a node dependency, but that would require you to run node.

We generally intend to keep previous versions of the API up for quite a while. This is because we build our API on top of a pretty cool engine we wrote [1] which allows migrations to be defined between old data models and new ones. We can keep running the old API endpoints / methods / semantics while under the hood, everything gets converted forward to address the same schema which the latest version is running against.

Noticing how out of date this particular playground repo is, I’m actually going through and bringing it up-to-date right now, and should issue a PR shortly. Certain variables have changed their names, for example RESIN_ env vars are now BALENA_ (we changed our name last fall [2])

[1] https://github.com/balena-io/pinejs
[2] https://www.balena.io/blog/resin-io-changes-name-to-balena-releases-open-source-edition/

I was hoping to use the scripts in the folder as is and just call them from within python with the appropriate args. I shouldn’t need node for that I hope.

Thanks for bringing the repo up to date. I will check back when I see the pull request and test the integration then. I will post any feedback here.

-Thomas

(We do have both RESIN_ and BALENA_ env vars working, but I’ll be updating it nonetheless in that regard. The main thing is to use a modern base image, from the resin/ docker namespace to balenalib/which we use now[1]

[1] https://www.balena.io/blog/new-year-new-balena-base-images/

Oh yeah, you can use the shell scripts which request tag changes via the API through curl, I just mentioned nodeJS in passing as interesting. I think it’s probably more convenient (and efficient on disk space) in your case to use curl than including the python SDK in your runtime image, especially since you only need this one method.

Here’s the PR, you can check out that branch for ideas on your own implementation: https://github.com/balena-io-playground/device-tags/pull/4