Skip to main content

Netbox Plugin to store textfiles(e.g. configs) alongside devices

Project description

netbox_textdatastore

Store raw text files for devices, like configuration files, unparsed command output or test results Use version 0.0.5 for netbox 3.6

TextData Object: ''' { "id": Int, # unique id "name": String, # Object Name, eg "device config" 'device': Device ID, # Device ID from Netbox 'hash': String, # Hash of your Text Data 'data': String, # Your text data, eg Device Configfile } '''

Example:

extend python-netbox

https://github.com/jagter/python-netbox

''' from netbox import NetBox as NetBoxOrig

class textdata(object):

def __init__(self, netbox_con):
    self.netbox_con = netbox_con

def get_data(self, **kwargs):
    return self.netbox_con.get('/plugins/textdata/data/', **kwargs)

def add_data(self, device, name, hash, data,  **kwargs):
    required_fields = {
        "name": name,
        'device': device,
        'hash': hash,
        'data': data,
        }
    print(required_fields)

    return self.netbox_con.post(
        '/plugins/textdata/data/',
        required_fields,
        **kwargs
    )

def update_data_id(self, pk, **kwargs):
    return self.netbox_con.patch(
        '/plugins/textdata/data/',
        pk,
        **kwargs
    )

class NetBox(NetBoxOrig):

def __init__(self, host, **kwargs):
    super().__init__(host, **kwargs)
    self.textdata = textdata(self.connection)

'''

use it in napalm

''' def store_config(task, obj, content): """store config to netbox"""

hasher = md5()
hasher.update(content.encode('utf-8'))
hash = hasher.hexdigest()
device_id = task.host.data["id"]
res = obj.netbox.textdata.get_data(
    device_id=device_id,
    name="device config"
)
if(len(res) > 0):
    res = res[0]
    if(res["hash"] == hash):
        print("No change")
        return
    print(obj.netbox.textdata.update_data_id(
        pk=res["pk"],
        data=content,
        hash=hash
    ))
    return
print(obj.netbox.textdata.add_data(
    device=device_id,
    name="device config",
    hash=hash,
    data=content
))

def backup_config(task, obj): """ get config from devices"""

from nornir_napalm.plugins.tasks import napalm_get
device_config = task.run(task=napalm_get, getters=["config"])
task.run(
    task=store_config,
    obj=obj,
    content=device_config.result["config"]["running"]
)

'''

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

netbox_textdatastore-0.1.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

netbox_textdatastore-0.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file netbox_textdatastore-0.1.0.tar.gz.

File metadata

  • Download URL: netbox_textdatastore-0.1.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for netbox_textdatastore-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd302c25ba3ef661d1dbc98e34d24742a3490d5d0aa38dba6ef27a8f1263461a
MD5 fc9a605bc9a22f7d0378e1f086d3278b
BLAKE2b-256 457f195ab92d775c6fe6e2cc541fdd23c9f756dabcb7c2dbc321f86ea86f26ce

See more details on using hashes here.

File details

Details for the file netbox_textdatastore-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for netbox_textdatastore-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a6ff30089c8bc40d8bc894b70af07cb90b583030ce9c7971b1b28d3301a07b8
MD5 a40df2504c6298fb7a1ce07330a91471
BLAKE2b-256 7479b60b7e2b24a85b9d62671357ff075acb8c6b0511b4e22ba91c137300b7c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page