跳转到主要内容

NetBox Labs, Diode SDK

项目描述

Diode SDK Python

Diode SDK Python是一个用于利用gRPC与Diode摄入服务交互的Python库。

Diode是一个新的NetBox摄入服务,极大地简化并增强了在NetBox中添加和更新网络数据的过程,确保您的网络真相源始终准确且值得信赖,可用于驱动您的网络自动化流程。

有关Diode的更多信息,请参阅https://netboxlabs.com/blog/introducing-diode-streamlining-data-ingestion-in-netbox/

安装

pip install netboxlabs-diode-sdk

用法

环境变量

  • DIODE_API_KEY - Diode服务的API密钥
  • DIODE_SDK_LOG_LEVEL - SDK的日志级别(默认:INFO
  • DIODE_SENTRY_DSN - 可选的Sentry DSN用于错误报告

示例

  • target 应为Diode服务的地址,例如不安全连接的 grpc://localhost:8081 或安全连接的 grpcs://example.com
from netboxlabs.diode.sdk import DiodeClient
from netboxlabs.diode.sdk.ingester import (
    Device,
    Entity,
)


def main():
    with DiodeClient(
        target="grpc://localhost:8081",
        app_name="my-test-app",
        app_version="0.0.1",
    ) as client:
        entities = []

        """
        Ingest device with device type, platform, manufacturer, site, role, and tags.
        """

        device = Device(
            name="Device A",
            device_type="Device Type A",
            platform="Platform A",
            manufacturer="Manufacturer A",
            site="Site ABC",
            role="Role ABC",
            serial="123456",
            asset_tag="123456",
            status="active",
            tags=["tag 1", "tag 2"],
        )

        entities.append(Entity(device=device))

        response = client.ingest(entities=entities)
        if response.errors:
            print(f"Errors: {response.errors}")


if __name__ == "__main__":
    main()

支持实体(对象类型)

开发笔记

netboxlabs/diode/sdk/diode/*中的代码由Protocol Buffers定义生成(将很快发布并在此引用)。

代码检查

ruff netboxlabs/
black netboxlabs/

测试

pytest tests/

许可证

在Apache 2.0许可证下分发。更多信息请见LICENSE.txt

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

netboxlabs-diode-sdk-0.4.0.tar.gz (39.9 kB 查看哈希值)

上传时间: 源代码

由以下支持