balena-io / balena-sdk-python Goto Github PK
View Code? Open in Web Editor NEWBalena SDK for Python
License: Apache License 2.0
Balena SDK for Python
License: Apache License 2.0
I'm new to using the resin-sdk-python. I'm using python 2.7.11 and when I try to import the resin sdk, I get a syntax error:
Traceback (most recent call last): File "<input>", line 1, in <module> File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/resin/__init__.py", line 9, in <module> from .base_request import BaseRequest File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 9, in <module> from .settings import Settings File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/resin/settings.py", line 56 print(Message.INVALID_SETTINGS.format(path=config_file_path), file=sys.stderr)
but if I change the file to:
sys.stderr.write(Message.INVALID_SETTINGS.format(path=config_file_path))
then I don't get an invalid syntax.
Am I using the sdk wrong? or am I using it wrong?
Settings
instances among models and classes are not consistent which means current settings is not global.
We need to reimplement settings to make it global
Hi @nghiant2710,
The new API implementation works confusing because of the login state. If already logged in on the SDK version 1.x the old API address is retained even when updated to the latest 2.0 version. Only after a logout or removal of the resin.cfg file. But, if I try to reproduce it, I do get:
Settings file not found or not in proper format. Rewriting default settings to: /Users/username/.resin/resin.cfg
2nd point. The device.set_to_build
command doesn't work. It returns:
>>> resin.models.device.set_to_build("ef448bdb8ac0000bb9013d98c6491587","339379")
Traceback (most recent call last):
File "<input>", line 1, in <module>
resin.models.device.set_to_build("ef448bdb8ac0000bb9013d98c6491587","339379")
File "/usr/local/lib/python2.7/site-packages/resin/models/device.py", line 721, in set_to_build
endpoint=self.settings.get('pine_endpoint')
File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 171, in request
raise exceptions.RequestError(response._content)
RequestError
3th and last point ๐
. Some return values have different labelling with API v3.
Like:
build
โก๏ธ should_be_running__build
commit
โก๏ธ is_on__commit
I understand I am quite early using these commands. However, it would be nice to have some documentation on which values changed in API v3.
Thanks! ๐ฌ
It currently returns a string but should return a dict instead.
We need to pass an additional request parameter for OS version to the API - version
.
In resin/models/device_os.py
from sets import Set
, Set
is never used. Plus it is deprecated since version 2.6
I currently cannot set a device to a specific release with the Python SDK. I tried using both the release hash and the release ID.
Release Hash: RequestError: b'"Release is not valid for this device"'
Release ID: ReleaseNotFound: <RELEASE_ID>
I am able to set the release using the shell scripts here, using the same UUID I attempted with the Python SDK.
I'm not sure what changed recently because I was able to use the Python SDK to do this same operation earlier this week.
Documentation link: https://github.com/resin-io/resin-sdk-python/blob/master/DOCUMENTATION.md#supervisor
Code that makes them both mandatory: https://github.com/resin-io/resin-sdk-python/blob/master/resin/models/supervisor.py#L39-L44
The SDK is currently using the ewa
API version, we should update it to the latest version
Hi I am having some issues trying to build the package, specifically in the cffi dependence.
Error:
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-haFsHd/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.5m -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.5/c/_cffi_backend.o
c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-_j379qbe/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-cqnd3icb-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_j379qbe/cffi/
Docker file.
`# Base image
FROM resin/armv7hf-debian:stretch
RUN apt-cache policy
RUN apt-get update && apt-get install -yq
curl
gcc
git
iputils-ping
libboost-all-dev
libcurl4-openssl-dev
libssl-dev \
python3
python3-dev
python3-pip
python3-setuptools
modemmanager
valgrind &&
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install -U --no-binary :all:
git+https://github.com/resin-io/resin-sdk-python.git
WORKDIR /usr/src/app
COPY . ./
COPY env_vars.yaml /data/env_vars.yaml
ENV DBUS_SYSTEM_BUS_ADDRESS unix:path=/host/run/dbus/system_bus_socket
CMD ["bash", "start.sh"]`
Error messages such as this should go to it's proper place so it can be separated from standard output.
Support changing device name as in the node SDK, i.e.:
resin.models.device.rename(process.env.RESIN_DEVICE_UUID, 'some-new-name');
While on Python 2 it works fine, the SDK seems to have a missing dependency on Python 3.
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import resin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/greg/resin/prog/bluemix-resin-python/venv3/lib/python3.5/site-packages/resin/__init__.py", line 9, in <module>
from .base_request import BaseRequest
File "/home/greg/resin/prog/bluemix-resin-python/venv3/lib/python3.5/site-packages/resin/base_request.py", line 7, in <module>
from urlparse import urljoin
ImportError: No module named 'urlparse'
There doesn't seem to be a way to access the SDK's defined exceptions from a dependant
When running an application using this SDK, the error Settings file not found or not in proper format. Rewriting default settings to: /root/.resin/resin.cfg
is present on every device reboot, where hostOS is rebooted as well. Generally it is harmless, however it appears to take 15s to process this error, which slows down the boot process.
Application in question is the following: https://github.com/IRNAS/PiRA-zero-firmware
We use the Pyhton SDK to issue shutdown and reboot commands to the host os.
On https://docs.resin.io/tools/python-sdk/ there's no documentation about what, if any, init-args the Resin()
constructor takes.
Steps to reproduce:
resin_client = Resin()
resin_client.auth.is_logged_in()
It raises a Unauthorized
error, I believe it should return False
in this case
There does not seem to be a parameter for single/quad core switch as per the web interface when downloading device OS image. Any ideas how this could be achieved with current SDK?
See https://app.frontapp.com/open/cnv_gtna5t
File "resin_cli.py", line 130, in main
res = resin.models.device.set_to_build(arguments["--device_uuid"],build_id)
File "/usr/local/lib/python3.6/site-packages/resin/models/device.py", line 721, in set_to_build
endpoint=self.settings.get('pine_endpoint')
File "/usr/local/lib/python3.6/site-packages/resin/base_request.py", line 171, in request
raise exceptions.RequestError(response._content)
resin.exceptions.RequestError: b'Internal Server Error'
Hello I posted on the gitter chat about an issue where setting a single environment variable causes all environment variables in the project to be changed, making my devices basically unusable.
Example code:
`
resin = Resin()
key = open("/blah/blah/blah/resin_key",'r')
token = key.readline().rstrip()
print(token)
resin.auth.login_with_token(token)
print("Is Login Successful?: " + str(resin.auth.is_logged_in()) )
import pprint
pp = pprint.PrettyPrinter(indent=4)
env = resin.models.environment_variables.device.get_all('{uuid}')
pp.pprint(env)
resin.models.environment_variables.device.update({var_id},"This should only change one")
`
This is also from Gitter:
Shaun Mulligan
@shaunmulligan
14:02
Okay @sako0938 , I have reproduced this, its a bug in our translation layer. The node.js SDK isn't affected by it because it has been updated to use the latest API version, but the python sdk hasn't been updated yet, so it uses older endpoints that have translation logic behind them to make sure the data maps onto the new model changes we deployed.
I will get the guys to fix this asap
is there any good and general way to avoid this version conflict ?
energywebfoundation/ew-link-origin#6 (comment)
at the moment, when not giving any versions, that list of dependencies can just not be installed.
Problematic are web3 4.3.0
and resin-sdk 4.7.0
.
Thanks.
https://docs.resin.io/tools/python-sdk/ says "please don't hesitate to open an issue in GitHub".
It would be really useful if that linked to https://github.com/resin-io/resin-sdk-python/issues :-)
Change RESIN_API_KEY
name since it's reserved and can't be set in the Resin Dashboard
I used the Pythonic resin-sdk before from the command line.
Now I'm trying to move some of my code into a WSGI application, but I get:
OSError: [Errno 13] Permission denied: '/usr/share/httpd/.balena'
Is there a way to not use such a directory? Maybe using the RESIN_API_KEY?
It's possible that reading ~/.resin/resin.cfg
will fail and the reading code is not robust. It currently checks for the existence of the data directory and .cfg file before attempting to read settings, but it's possible that the file exists but hasn't been saved correctly. Here's a traceback that reads the file but it's not in proper format:
a = resin.Auth()
File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/auth.py", line 14, in __init__
self.base_request = BaseRequest()
File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/base_request.py", line 23, in __init__
self.settings = Settings()
File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/settings.py", line 41, in __init__
self.__read_settings()
File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/settings.py", line 64, in __read_settings
options = config_reader.options(self.CONFIG_SECTION)
File "/usr/lib/python2.7/ConfigParser.py", line 279, in options
raise NoSectionError(section)
NoSectionError: No section: 'Settings'
Unless we save user data in resin.cfg, I think it makes sense to try/catch reading the settings, and fallback to just writing the file, like so:
def __init__(self):
try:
self.__read_settings()
except Exception as e:
print('Settings file not found or not in proper format', e)
self.__write_settings()
Is planned to have device_environment_variable resource in models? like in the js sdk?
Hello. I am having problems with the Python-SDK. Let me first explain what am I doing right now. I am creating a backup file every day of all variables and tags for device. I am currently working on a backup processor script which is taking the values and restoring the devices variables and tags. I found an interesting thing while testing the script. When I deleted a tag and after that I tried to set it back on - it is returning "OK" as it exists and it was updated but it doesn't exist and it isn't populated at all. I think, you are caching things up on your end and you are returning this for a faster response. The devices are raspberry pi 3, if that matter.
Is there any way to check the free disk space of the devices from the sdk?
Some Supervisor API endpoints (e.g. /v1/apps
) are only provided by the latest supervisor versions, so the SDK should check the device.supervisor_version
field and display a descriptive error message if the SDK users invokes an unsupported method.
Also check discussion here: balena-io/balena-sdk#206
See balena-io/balena-sdk#143 for more explanation.
This auth.is_logged_in()
function is returning auth token not a boolean value as describing.
resin.models.device.get_name("#####")
Traceback (most recent call last):
File "", line 1, in
File "/home/skorn/Babylon-Web/django/env/lib/python3.6/site-packages/resin/models/device.py", line 202, in get_name
return self.get(uuid)['device_name']
KeyError: 'device_name'
When you go find the file /resin/models/device.py in the repo it talks about a large breaking change, so it seems something is just a bit off with the 4.0.0 update.
Thanks for the support!
This is returning the wrong app id and therefore the wrong devices. I assume this is because I'm an admin and my app name matches someone else on staging? @nghiant2710
This will make it much easier to test the renamed SDK before the new API has reached prod.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.