Skip to content

数据后端

数据源 可以定义为引用存在于 NetBox 之外的记录系统上的数据,例如 git 存储库或 Amazon S3 存储桶。插件可以注册自己的后端类来支持额外的资源类型。这可以通过继承 NetBox 的 DataBackend 类来完成。

data_backends.py
from netbox.data_backends import DataBackend

class MyDataBackend(DataBackend):
    name = 'mybackend'
    label = 'My Backend'
    ...

要在 NetBox 中注册一个或多个数据后端,请在此文件的末尾定义一个名为 backends 的列表:

data_backends.py
backends = [MyDataBackend]

提示

可以通过在 PluginConfig 实例中设置 data_backends 来修改搜索索引列表的路径。

DataBackend

A data backend represents a specific system of record for data, such as a git repository or Amazon S3 bucket.

Attributes:

Name Type Description
name

The identifier under which this backend will be registered in NetBox

label

The human-friendly name for this backend

is_local

A boolean indicating whether this backend accesses local data

parameters

A dictionary mapping configuration form field names to their classes

sensitive_parameters

An iterable of field names for which the values should not be displayed to the user

init_config(self)

A hook to initialize the instance's configuration. The data returned by this method is assigned to the instance's config attribute upon initialization, which can be referenced by the fetch() method.

fetch(self)

A context manager which performs the following:

  1. Handles all setup and synchronization
  2. Yields the local path at which data has been replicated
  3. Performs any necessary cleanup