Skip to content

Commit

Permalink
load netbox device type library on startup (see idaholab#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Nov 21, 2022
1 parent 7be8ada commit f13fd12
Show file tree
Hide file tree
Showing 4 changed files with 694 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Dockerfiles/netbox.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ ENV SUPERCRONIC "supercronic-linux-amd64"
ENV SUPERCRONIC_SHA1SUM "d7f4c0886eb85249ad05ed592902fa6865bb9d70"
ENV SUPERCRONIC_CRONTAB "/etc/crontab"

ENV NETBOX_DEVICETYPE_LIBRARY_URL "https://codeload.github.com/netbox-community/devicetype-library/tar.gz/master"

ARG NETBOX_DEFAULT_SITE=Malcolm
ARG NETBOX_CRON=false

Expand All @@ -54,10 +56,12 @@ RUN apt-get -q update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
groupadd --gid ${DEFAULT_GID} ${PUSER} && \
useradd -m --uid ${DEFAULT_UID} --gid ${DEFAULT_GID} ${PUSER} && \
usermod -a -G tty ${PUSER} && \
mkdir -p /opt/unit && \
useradd -m --uid ${DEFAULT_UID} --gid ${DEFAULT_GID} ${PUSER} && \
usermod -a -G tty ${PUSER} && \
mkdir -p /opt/unit /opt/netbox-devicetype-library && \
chown -R $PUSER:$PGROUP /etc/netbox /opt/unit /opt/netbox && \
cd /opt && \
curl -sSL "$NETBOX_DEVICETYPE_LIBRARY_URL" | tar xzvf - -C ./netbox-devicetype-library --strip-components 1 && \
mkdir -p /opt/netbox/netbox/$BASE_PATH && \
mv /opt/netbox/netbox/static /opt/netbox/netbox/$BASE_PATH/static && \
jq '. += { "settings": { "http": { "discard_unsafe_fields": false } } }' /etc/unit/nginx-unit.json | jq ".routes[0].match.uri = \"/${BASE_PATH}/static/*\"" > /etc/unit/nginx-unit-new.json && \
Expand Down
20 changes: 20 additions & 0 deletions netbox/scripts/netbox_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (c) 2022 Battelle Energy Alliance, LLC. All rights reserved.

import argparse
import ipaddress
import json
Expand All @@ -13,6 +15,7 @@

from collections.abc import Iterable
from slugify import slugify
from netbox_library_import import import_library

###################################################################################################
args = None
Expand Down Expand Up @@ -204,6 +207,15 @@ def main():
required=False,
help="Device types(s) to create",
)
parser.add_argument(
'-l',
'--library',
dest='libraryDir',
type=str,
default=None,
required=False,
help="Directory containing NetBox device type library",
)
try:
parser.error = parser.exit
args = parser.parse_args()
Expand Down Expand Up @@ -424,6 +436,14 @@ def main():
except Exception as e:
logging.error(f"{type(e).__name__} processing sites: {e}")

# ###### Library ###############################################################################################
try:
counter = import_library(nb, args.libraryDir)
logging.debug(f"import library results: { counter }")

except Exception as e:
logging.error(f"{type(e).__name__} processing library: {e}")

# ###### Net Map ###############################################################################################
try:
# load net-map.json from file
Expand Down
Loading

0 comments on commit f13fd12

Please sign in to comment.