系统信息发现和资产跟踪
grainsv2的Python项目详细描述
系统信息发现和资产跟踪
安装
pip install grainsv2
开发安装
克隆grainsrepo并使用pip安装:
^{pr2}$执行
安装之后,现在应该可以使用grains命令。在
命令在垂直扩展之前没有输出(详细信息如下)。在
测试
安装要求-测试.txt使用pip并运行pytest:
pip install -r grains/requirements-test.txt pytest grains/tests
垂直应用程序合并
延伸晶粒说明
安装pop:
pip install --upgrade pop
为项目创建新目录:
mkdir grains_{project_name} cd grains_{project_name}
使用pop seed生成扩展粒度的项目结构:
pop-seed -t v grains_{project_name} -d grains
- “-t v”指定这是一个垂直应用程序合并的项目
- “-d grains”表示要实现“grains”的动态名称
请注意,已经为您创建了一些结构。 我们特别关注grains{project_name}/grains中的新目录
添加“谷物”到要求.txt公司名称:
echo "grains" >> requirements.txt
造粒
- 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.
示例:
async def load_my_grain(hub): hub.grains.GRAINS.new_grain = "Hello World!"
就这样!现在,请验证是否已从命令行收集颗粒:
grains new_grain
输出:
new_grain: Hello World!
- 项目
标签: