Skip to main content

System information discovery and asset tracking

Project description

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!

Project details


Download files

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

Source Distribution

grainsv2-11.7.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

grainsv2-11.7-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file grainsv2-11.7.tar.gz.

File metadata

  • Download URL: grainsv2-11.7.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for grainsv2-11.7.tar.gz
Algorithm Hash digest
SHA256 895b5be16fdffcc62a9abdefe68d01520d0a98e8cf2d10460f2e7b7bfe467d51
MD5 7877401fa5e93da2adce8a7da1aae43f
BLAKE2b-256 9086e86b6a5a76e1116f903e0206db62615c4a01d608ee4cf0b9e23fe745dda5

See more details on using hashes here.

File details

Details for the file grainsv2-11.7-py3-none-any.whl.

File metadata

  • Download URL: grainsv2-11.7-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for grainsv2-11.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7ccf80a59db8178f9a812caa3bb34f51ebbf53fd5c578c7077413468c25774d8
MD5 4ed784dd2678dd5fb5d3314abcb4f9a9
BLAKE2b-256 670f5d4fdded6e34c374574afc8e2c857e2bb7e1c79cc94d266d011ee8e5c06b

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