mirror of
https://github.com/netbox-community/Device-Type-Library-Import.git
synced 2024-11-21 15:13:12 +01:00
Added try except block to catch ssl errors. (#74)
If IGNORE_SSL_ERRORS is true, then silence SSL verification & continue. If IGNORE_SSL_ERRORS is false, then raise the error with custom message. Added verbose option to assist with reducing output and allowing for verbose logging if desired. If IGNORE_SSL_ERRORS is false, and --verbose is specified, then print the exception.
This commit is contained in:
parent
3726326225
commit
1345a9d89e
3
.gitignore
vendored
3
.gitignore
vendored
@ -102,7 +102,8 @@ celerybeat.pid
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.env*
|
||||
!.env.example
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
|
@ -10,6 +10,7 @@ import os
|
||||
import settings
|
||||
import sys
|
||||
import re
|
||||
import requests
|
||||
|
||||
|
||||
counter = Counter(
|
||||
@ -768,21 +769,7 @@ def main():
|
||||
|
||||
cwd = os.getcwd()
|
||||
startTime = datetime.now()
|
||||
|
||||
nbUrl = settings.NETBOX_URL
|
||||
nbToken = settings.NETBOX_TOKEN
|
||||
nb = pynetbox.api(nbUrl, token=nbToken)
|
||||
|
||||
determine_features(nb)
|
||||
|
||||
if settings.IGNORE_SSL_ERRORS:
|
||||
import requests
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
session = requests.Session()
|
||||
session.verify = False
|
||||
nb.http_session = session
|
||||
|
||||
|
||||
|
||||
VENDORS = settings.VENDORS
|
||||
REPO_URL = settings.REPO_URL
|
||||
|
||||
@ -798,8 +785,27 @@ def main():
|
||||
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")
|
||||
parser.add_argument('--verbose', action='store_true',
|
||||
help="Print verbose output")
|
||||
args = parser.parse_args()
|
||||
|
||||
nbUrl = settings.NETBOX_URL
|
||||
nbToken = settings.NETBOX_TOKEN
|
||||
nb = pynetbox.api(nbUrl, token=nbToken)
|
||||
|
||||
try:
|
||||
determine_features(nb)
|
||||
except requests.exceptions.SSLError as e:
|
||||
if args.verbose:
|
||||
print(e)
|
||||
if not settings.IGNORE_SSL_ERRORS:
|
||||
print("IGNORE_SSL_ERRORS is False. SSL verification failed, exiting.")
|
||||
sys.exit(1)
|
||||
print("IGNORE_SSL_ERRORS is True, catching exception and disabling SSL verification.")
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
nb.http_session.verify = False
|
||||
determine_features(nb)
|
||||
|
||||
try:
|
||||
if os.path.isdir('./repo'):
|
||||
print(f"Package devicetype-library is already installed, "
|
||||
|
Loading…
Reference in New Issue
Block a user