Skip to main content

GRAINS

System information discovery and asset tracking

INSTALLATION

pip install grainsv2

INSTALLATION FOR DEVELOPMENT

Clone the grains repo and install with pip:

git clone https://gitlab.com/saltstack/pop/grains.git
pip install -e grains

EXECUTION

After installation the grains command should now be available.

The command will have no output until it is vertically extended (details below).

TESTING

install requirements-test.txt with pip and run pytest:

pip install -r grains/requirements-test.txt
pytest grains/tests

VERTICAL APP-MERGING

Instructions for extending grains

Install pop:

pip install --upgrade pop

Create a new directory for the project:

mkdir grains_{project_name}
cd grains_{project_name}

Use pop-seed to generate the structure of a project that extends grains:

pop-seed -t v grains_{project_name} -d grains

  • “-t v” specifies that this is a vertically app-merged project

  • “-d grains” says that we want to implement the dynamic name of “grains”

Notice that some structure has been created for you. We especially care about the new directory in grains_{project_name}/grains

Add “grains” to the requirements.txt:

echo "grains" >> requirements.txt

CREATING GRAINS

  • Create a new file in “grains_{project_name}/grains”
    • The directory should already have been created by pop-seed.

    • The file name is arbitrary.

    • Every file in this directory, then it’s subdirectories, will be parsed “simultaneously” (as far as that makes sense for asyncio).

    • Grains that are dependant on each other should be assigned in the same function.

    • Do NOT rely on the collector’s recursion strategy for grains to depend on each other.

    • Use hub.grains.init.wait_for(“grains”) to wait for grains to be generated by another sub

  • Add your new project to the python path
    • alternatively, run “pip install -e .” from your project’s root directory
      • you only need to do this once

  • Create an async function in this file with a descriptive yet arbitrary name
    • By convention it should start with “load”

    • Make it async unless you have a really really really good reason.

    • Grains that depend on each other already belong in the same function, don’t depend on synchronous programming for determinism

    • Use hub.grains.init.wait_for(“specific_grain”) to explicitly wait for an external grain to become available before moving on

    • Grains can be accessed and assigned like a dictionary, but our convention is to use the namespace

    • Use hub.grains.GRAINS._dict() or copy.copy(hub.grains.GRAINS) to retrieve a JSON serializable version of grains.

Example:

async def load_my_grain(hub):
    hub.grains.GRAINS.new_grain = "Hello World!"

And that’s it! Now verify that your grain is collected from the command line:

grains new_grain

Output:

new_grain:
    Hello World!

Metadata

Release files for grainsv2 9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grainsv2 9
File Size Uploaded
grainsv2-9.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grainsv2 9
File Interpreter ABI Platform
grainsv2-9-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / grainsv2-9.tar.gz

Download URL grainsv2-9.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a87446b533ac30ffe5742f2313bfdf97ea9b6296690befda200c760a7602b17c
BLAKE2b-256 checksum
How to use checksums
23d098432bac072db6762d59577feae66f29ac86dfd4be050a0deb57b983ce32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / grainsv2-9-py3-none-any.whl

Download URL grainsv2-9-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0af9e8409076a842d0ead9c71434f04dfc1a808e8496be8a91856365f7df9b32
BLAKE2b-256 checksum
How to use checksums
c10e5372b08f21f6efc9f37fdd3727bfc5d4cfbac077c560310b5a956bfa01c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release history Release notifications | RSS feed

11.10

2 release files

11.9

2 release files

11.8

2 release files

11.7

2 release files

11.6

2 release files

11.3

2 release files

10.1

2 release files

10

2 release files

9.2

2 release files

9.1

2 release files

This release

9 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page