Skip to main content

A CLI tool and library for interacting with Thoth

Project description

A CLI tool and library for communicating with Thoth backend.

Using Thamos as a CLI tool

Thamos is released on PyPI. See installation instructions bellow to setup Thoth/Thamos for your repository:

# Install Thamos CLI tool:
$ pip3 install thamos  # keep in mind: requires Python 3.6+!!
# Go to repository that should be managed by Thoth which already has Pipfile present:
$ cd ~/git/repo/
# Setup Thamos configuration:
$ thamos config
# Ask Thoth for software stack recommendations:
$ thamos advise
# Retrieve logs of the last analysis:
$ thamos log

As Thamos notes analysis ids for better UX of thamos log, it’s recommended to add .thoth_last_analysis_id file to .gitignore.

Adjusting configuration based on environment variables

You can adjust content of configuration file each time Thamos CLI or Thamos library loads it by expanding entries with environment variables. This can be handy if you would like to parameterize some of the options at runtime (e.g. in deployment).

This behaviour is (due to security reasons) explicitly turned off by default. However you can turn it on by setting THAMOS_CONFIG_EXPAND_ENV environment variable to 1 (0 explicitly turns this behaviour off, default value):

THOTH_HOST=test.thoth-station.ninja THAMOS_CONFIG_EXPAND_ENV=1 thamos advise
2019-03-13 11:22:59,562 [18639] INFO     thamos.config: Expanding configuration file based on environment variables

Entries which should be expanded have environment variables in curly braces like the following example:

host: {THOTH_HOST}

Note the expansion is done by replacing these values directly with values of environment variable, this means types need to be taken into account (environment variable with value “true” is put into configuration file as true).

Using custom configuration file template

You can use your own custom configuration file as a template. This is especially useful if you want to have some configuration entries constant and let expand only some of the configuration options. In other words, you can parametrize configuration file.

An example of configuration file template can be:

host: {THOTH_SERVICE_HOST}
tls_verify: true
requirements_format: pipenv

runtime_environments:
  - name: '{os_name}:{os_version}'
    operating_system:
      name: {os_name}
      version: '{os_version}'
    hardware:
      cpu_family: {cpu_family}
      cpu_model: {cpu_model}
    python_version: '{python_version}'
    cuda_version: {cuda_version}
    recommendation_type: stable
    limit_latest_versions: null

Then, you need to supply this configuration file to the following command:

thamos config --template template.yaml

Listing of automatically expanded configuration options which are supplied the config sub-command (these options are optional and will be expanded based on HW or SW discovery):

Configuration option

Explanation

Example

os_name

name of operating system

fedora

os_version

version of operating system

30

cpu_family

CPU family identifier

6

cpu_model

CPU model identifier

94

python_version

Python version (major.minor)

3.6

cuda_version

CUDA version (major.minor)

9.0

These configuration options are optional and can be mixed with adjustment based on environment variables (see THOTH_SERVICE_HOST example above). Note the environment variables are not expanded on thamos config call but rather on other sub-commands issued (e.g. thamos advise or others).

Using Thoth and thamos in OpenShift’s s2i

Using configuration templates is especially useful for OpenShift builds where you can specify your template in an s2i repository (omit Pipfile.lock to enable call to thamos advise as shown in this repository).

Then, you need to provide following environment variables:

  • THAMOS_CONFIG_TEMPLATE - holds path to template - use /tmp/src prefix to point to root of s2i repository (e.g. /tmp/src/template.yaml if template.yaml is the configuration template and is stored in root of your Git repository).

  • THAMOS_NO_INTERACTIVE - set to 1 if you don’t want to omit interactive thamos (suitable for automated s2i builds happening in the cluster).

  • THAMOS_NO_PROGRESSBAR - set to 1 to disable progressbar while waiting for response from Thoth backend - it can cause annoying too verbose output printed to OpenShift console during the build.

  • THAMOS_CONFIG_EXPAND_ENV - set to 1 to enable expansion based on environment variables when generating .thoth.yaml file - this needs to be explicitly turned on due to possible security implications.

  • THAMOS_FORCE - set to 1 not use cached results, always force analysis on Thoth’s side (note this option can be ignored by a Thoth operator based on deployment configuration).

  • THAMOS_VERBOSE - set to 1 to run thamos in verbose mode to show what’s going on (verbosity on client side).

  • THAMOS_DEBUG - set to 1 to run analyzes (adviser, provenance checker, …) on Thoth’s backend side in debug mode, you can obtain logs by running thamos logs or directly on Thoth’s user API; the analysis id gets printed into the console during the build process in OpenShift (verbosity on server side).

See OpenShift s2i documentation on how to pin build to a specific node in the cluster. This is needed if you would like to perform automatic hardware discovery to get optimized stacks on your hardware.

Using Thamos as a library

from thamos.lib import image_analysis
from thamos.config import config

# Set global context.
# Host to Thoth's User API. API discovery will be done
# transparently and the most appropriate API version will be used.
config.explicit_host = "thoth-user-api.redhat.com"
# TLS verification when communicating with Thoth API.
config.tls_verify = True

image_analysis(
  image="registry.redhat.com/fedora:29",
  registry_user="fridex",
  registry_password="secret!",
  # TLS verification when communicating with registry.
  verify_tls=True,
  nowait=False
)

Autogenerated client from OpenAPI

Most parts of Thamos consist of automatic generated code. You can update Thamos by running the following command:

$ ./swagger-codegen.sh

The command above will download and run automatic code generation tool against the most recent OpenAPI specification of User API. Results of the tool are automatically placed into this repository in thamos/swagger_client/ and Documentation/. They consist of automatically generated code as well as documentation on how to use the code. Thamos itself provides routines built on top of this automated generated code to simplify usage in thamos/lib.

Project details


Release history Release notifications | RSS feed

This version

0.7.5

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thamos-0.7.5.tar.gz (53.8 kB view details)

Uploaded Source

Built Distribution

thamos-0.7.5-py3-none-any.whl (114.7 kB view details)

Uploaded Python 3

File details

Details for the file thamos-0.7.5.tar.gz.

File metadata

  • Download URL: thamos-0.7.5.tar.gz
  • Upload date:
  • Size: 53.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/36.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for thamos-0.7.5.tar.gz
Algorithm Hash digest
SHA256 9f9cd31aca946c469232282aa37f84875b7d464527822adff878bc413ba5deec
MD5 83b3d64fdfde9c71af9c7c938f6eccb9
BLAKE2b-256 de28c8d1ebc5e2a02e9b266972b1680ec20af0e6a28feb227e00f2e1972604cd

See more details on using hashes here.

File details

Details for the file thamos-0.7.5-py3-none-any.whl.

File metadata

  • Download URL: thamos-0.7.5-py3-none-any.whl
  • Upload date:
  • Size: 114.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/36.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for thamos-0.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d91e1370756d18f4e0af044a5ccf0b4360a623d29cdd1ab5e56a06e93e476886
MD5 12857ae861f35a5c0b8162198cb91f49
BLAKE2b-256 d033f592210f81b463a9c7f8396634097f2698a9423cdcf4ace82b9209146686

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page