Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add an id for Docker containers Usual Linux images for Docker containers, does not have the originally listed files. Following the conversation at denisbrodbeck/machineid#10, I am including the following: Because `/proc/self/cgroup` seams to not be working on same Docker versions, I am also including `/proc/self/mountinfo`. Tested on `Python 3.11` running on `Debian GNU/Linux 11 (bullseye)` inside a Docker. * Included "if 'docker' in mountinfo" for "linux" Following your review, I made some updates on the patch. * Update __init__.py * Fixed the indentation to 2. * Checked on a Docker container the `if 'docker' in cgroup:` works when the `docker` is not found. Same test with `mountinfo`. * When the full code does not find an ID raises the following: `Python 3.11.0 (main, Nov 15 2022, 19:58:01) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import machineid >>> print(machineid.id()) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.11/site-packages/machineid/__init__.py", line 90, in id raise Exception('failed to obtain id on platform {}'.format(platform)) Exception: failed to obtain id on platform linux` * Update __init__.py Check if `cgroup` and `mountinfo` are not None, before checking if `docker` is inside the file. To not rise a possible error when is trying to check `if 'docker' in None` (when the file does not exist).
- Loading branch information