mirror of
https://github.com/netbox-community/Device-Type-Library-Import.git
synced 2024-11-21 23:23:17 +01:00
Merge pull request #33 from rsp2k/master
Add SLUGS option to specify a space-separated list of device_type slug…
This commit is contained in:
commit
ed737e22ee
@ -3,3 +3,4 @@ NETBOX_TOKEN=
|
||||
REPO_URL=https://github.com/netbox-community/devicetype-library.git
|
||||
REPO_BRANCH=master
|
||||
IGNORE_SSL_ERRORS=False
|
||||
#SLUGS=c9300-48u isr4431 isr4331
|
||||
|
@ -8,6 +8,7 @@ import glob
|
||||
import argparse
|
||||
import os
|
||||
import settings
|
||||
import sys
|
||||
|
||||
|
||||
counter = Counter(added=0, updated=0, manufacturer=0)
|
||||
@ -54,7 +55,8 @@ def getFiles(vendors=None):
|
||||
return files, discoveredVendors
|
||||
|
||||
|
||||
def readYAMl(files):
|
||||
def readYAMl(files, **kwargs):
|
||||
slugs = kwargs.get('slugs', None)
|
||||
deviceTypes = []
|
||||
manufacturers = []
|
||||
for file in files:
|
||||
@ -68,6 +70,11 @@ def readYAMl(files):
|
||||
data['manufacturer'] = {}
|
||||
data['manufacturer']['name'] = manufacturer
|
||||
data['manufacturer']['slug'] = slugFormat(manufacturer)
|
||||
|
||||
if slugs and data['slug'] not in slugs:
|
||||
print(f"Skipping {data['model']}")
|
||||
continue
|
||||
|
||||
deviceTypes.append(data)
|
||||
manufacturers.append(manufacturer)
|
||||
return deviceTypes
|
||||
@ -388,19 +395,21 @@ def main():
|
||||
|
||||
VENDORS = settings.VENDORS
|
||||
REPO_URL = settings.REPO_URL
|
||||
REPO_BRANCH = settings.REPO_BRANCH
|
||||
|
||||
SLUGS = settings.SLUGS
|
||||
REPO_BRANCH = settings.REPO_BRANCH
|
||||
|
||||
parser = argparse.ArgumentParser(description='Import Netbox Device Types')
|
||||
parser.add_argument('--vendors', nargs='+', default=VENDORS,
|
||||
help="List of vendors to import eg. apc cisco")
|
||||
parser.add_argument('--url', '--git', default=REPO_URL,
|
||||
help="Git URL with valid Device Type YAML files")
|
||||
parser.add_argument('--slugs', nargs='+', default=SLUGS,
|
||||
help="List of device-type slugs to import eg. ap4431 ws-c3850-24t-l")
|
||||
parser.add_argument('--branch', default=REPO_BRANCH,
|
||||
help="Git branch to use from repo")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
try:
|
||||
if os.path.isdir('./repo'):
|
||||
print(f"Package devicetype-library is already installed, "
|
||||
@ -421,8 +430,8 @@ def main():
|
||||
|
||||
|
||||
print(str(len(vendors)) + " Vendors Found")
|
||||
print(str(len(files)) + " Device-Types Found")
|
||||
deviceTypes = readYAMl(files)
|
||||
deviceTypes = readYAMl(files, slugs=args.slugs)
|
||||
print(str(len(deviceTypes)) + " Device-Types Found")
|
||||
createManufacturers(vendors, nb)
|
||||
createDeviceTypes(deviceTypes, nb)
|
||||
|
||||
|
@ -11,6 +11,10 @@ IGNORE_SSL_ERRORS = (os.getenv("IGNORE_SSL_ERRORS", "False") == "True")
|
||||
# optionnally load vendors through a space separated list as env var
|
||||
VENDORS = os.getenv("VENDORS", "").split()
|
||||
|
||||
# optionally load device types through a space separated list as env var
|
||||
SLUGS = os.getenv("SLUGS", "").split()
|
||||
|
||||
|
||||
MANDATORY_ENV_VARS = ["REPO_URL", "NETBOX_URL", "NETBOX_TOKEN"]
|
||||
|
||||
for var in MANDATORY_ENV_VARS:
|
||||
|
Loading…
Reference in New Issue
Block a user