add readme and update some bits

This commit is contained in:
Alexander GITTINGS 2020-02-26 14:49:12 +00:00
parent cd8439127d
commit 7b81c3b0cd
4 changed files with 95 additions and 12 deletions

View File

@ -1,9 +1,5 @@
from git import Repo, exc, RemoteProgress
import os
import argparse
import glob
import yaml
import pynetbox
import yaml, pynetbox, glob, argparse, os, settings
parser = argparse.ArgumentParser(description='Import Netbox Device Types')
parser.add_argument('--vendor', nargs='+')
@ -12,8 +8,8 @@ args = parser.parse_args()
cwd = os.getcwd()
url = 'https://github.com/netbox-community/devicetype-library.git'
nbUrl = 'http://192.168.3.119'
nbToken = '0123456789abcdef0123456789abcdef01234567'
nbUrl = settings.NETBOX_URL
nbToken = settings.NETBOX_TOKEN
def update_package(path: str):
try:
@ -243,13 +239,12 @@ nb = pynetbox.api(nbUrl, token=nbToken)
if args.vendor is None:
print("No Vendor Specified, Gathering All Device-Types")
files, vendors = getFiles()
deviceTypes = readYAMl(files)
print(vendors)
createManufacturers(vendors, nb)
createDeviceTypes(deviceTypes, nb)
# print(json)
print(str(len(vendors)) + " Vendors Found")
print(str(len(files)) + " Device-Types Found")
deviceTypes = readYAMl(files)
createManufacturers(vendors, nb)
createDeviceTypes(deviceTypes, nb)
else:
print("Vendor Specified, Gathering All Matching Device-Types")
files, vendors = getFiles(args.vendor)

65
readme.md Normal file
View File

@ -0,0 +1,65 @@
# Netbox Device Type Import
This library is intended to be your friend and help you import all the device-types defined within the the [NetBox Device Type Library Repository](https://github.com/netbox-community/devicetype-library).
## Getting Started
These instructions will get you a copy of the project on your machine to allow you to import the device types you would like without copy and pasting them into the NetBox UI.
### Prerequisites
This script is written in python so this must be installed.
```
Python3
Python PIP
```
## Using the Repo
Cloning the repo
```
git clone https://github.com/minitriga/Netbox-Device-Type-Library-Import.git
```
Installing the requirements
```
pip install -r requirements.txt
```
### Setting your variables
There are a number of variables that are required when using this script to import device types into your netbox environment.
```
export NETBOX_URL=http://netbox.company.com
export NETBOX_TOKEN=0123456789abcdef0123456789abcdef01234567
```
### Using the script
To use the script simply run the following.
```
python nb-dt-import.py
```
This will pull the device-type library from Gitlab and install it into the `.repo` directory. if this directory is already there it will perform a git pull to update the reposity.
#### Arguments
This script currently accepts vendors so that only a few vendors are imported into your NetBox Environment.
This can be done the following.
```
python nb-dt-import.py --vendors apc
```
`--vendors` also accepts a list of vendors so that multiple vendors could be imported.
```
python nb-dt-import.py --vendors apc juniper
```

13
requirements.txt Normal file
View File

@ -0,0 +1,13 @@
certifi==2019.11.28
chardet==3.0.4
gitdb2==3.0.2
GitPython==3.0.8
idna==2.8
progressbar2==3.47.0
pynetbox==4.2.5
python-utils==2.3.0
PyYAML==5.3
requests==2.22.0
six==1.14.0
smmap2==2.0.5
urllib3==1.25.8

10
settings.py Normal file
View File

@ -0,0 +1,10 @@
import os
NETBOX_URL = str(os.getenv("NETBOX_URL"))
NETBOX_TOKEN = str(os.getenv("NETBOX_TOKEN"))
MANDATORY_ENV_VARS = ["NETBOX_URL", "NETBOX_TOKEN"]
for var in MANDATORY_ENV_VARS:
if var not in os.environ:
raise EnvironmentError("Failed because {} is not set.".format(var))