balena-io / balena-sdk-python

Balena SDK for Python
Apache License 2.0
67 stars 46 forks source link

Missing Functionality from balena.models.supervisor #337

Closed meawoppl closed 1 year ago

meawoppl commented 1 year ago

It used to be that you could initialize the Supervisor class with the environment variables BALENA_SUPERVISOR_ADDRESS and BALENA_SUPERVISOR_API_KEY on a balena device and use the class to admin the device itself from the device itself. As far as I can tell there isn't a clean/existing way to accomplish that presently.

Am I missing something? Many thanks.

otaviojacobi commented 1 year ago

Hello @meawoppl Indeed this got past me while migrating to the new format, the current behavior will try to hit the API which will then talk to the supervisor instead of directly forwarding to the local supervisor while running the SDK locally. I will raise internally on how this can be better hanlded and come back to you

otaviojacobi commented 1 year ago

Hello @meawoppl Could you explain what is your use case that requires using the SDK inside a device? If this is private information, could you send it to us in a private support ticket? We want to better understand the use cases here to be able to design this properly.

AmirAvonic commented 1 year ago

We actually have the same problem and the same use case. Our devices are mostly used offline when they are used by clients, and are only attached to the Balena Cloud when a new update is needed. In the meantime, we use the Balena Python SDK in order to perform supervisor commands directly on the device, such as sending a reboot command. Is this something that will be fixed in a future release possibly?

otaviojacobi commented 1 year ago

Hello @AmirAvonic Thanks for the clarification and explanation. This is a valid request. I will look into implementing it.

otaviojacobi commented 1 year ago

Hello @AmirAvonic and @meawoppl #346 has been merged, with that 14.1.0 was release and if you use SDK >= 14.1.0 the SDK running inside the device will reach the supervisor directly if you don't pass any UUID or if the UUID is equal to the same variable injected by the supervisor called BALENA_DEVICE_UUID. If the UUID is different (e.g. you are trying to do some operation from one device into another one) this will go via the API, but I believe this covers all your use cases, specially for working offline.

Please let me know if you can properly update and if you have any trouble. Note that if you are running open-balena this will require open-balena-api >= 14.1.0