Network Server of Truth, or NSoT, is designed to run on multiple architectures and environments that support Python. Provided the host is properly configured, NSoT can be installed with a single command line entry.
$ pip install nsot
import sys | |
import string | |
from trigger.cmds import Commando | |
from twisted.python import log | |
log.startLogging(sys.stdout, setStdout=False) | |
devices = ["pe1.demo.localdomain", "pe2.demo.localdomain"] | |
Managment commands are assumed to be unique across all apps in a Django project. This can lead to long or obscure command names in attempt to namespace those commands.
Subcommander acts as a proxy command giving the real commands a namespace. The subcommander module can be named after the app name or some derivation. The structure looks as follows:
myapp/
management/
commands/
def select_option_for_select2(driver, id, text=None): | |
element = driver.find_element(By.XPATH, '//*[@id="{}"]/following-sibling::*[1]'.format(id)) | |
element.click() | |
if text: | |
element = driver.find_element(By.CSS_SELECTOR, "input[type=search]") | |
element.send_keys(text) | |
try: | |
element.send_keys(Keys.ENTER) |
from nautobot.dcim.models import Device | |
from nautobot.dcim.models import Interface | |
from nautobot.dcim.choices import InterfaceTypeChoices | |
from nautobot.ipam.models import VLAN | |
from nautobot.extras.jobs import Job | |
class TestJob(Job): | |
class Meta: | |
description = "Some job jo!" |
def merge_dicts(dict_list): | |
"""Merge all values from dict list into a single dict | |
>>> d1 = {'a': 1, 'b': 2} | |
>>> d2 = {'a': 2, 'b': 3} | |
>>> merge_dicts([d1, d2]) | |
{'a': [1, 2], 'b': [2, 3]} | |
""" | |
kviter = chain.from_iterable(d.iteritems() for d in dict_list) |
import contextlib | |
import hashlib | |
import logging | |
from collections import defaultdict | |
from decimal import Decimal | |
from django.db.models import DecimalField, ForeignKey | |
log = logging.getLogger(__name__) |