Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNORE_SSL_ERRORS usage in image upload #101

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions netbox_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def __init__(self, settings):
self.connect_api()
self.verify_compatibility()
self.existing_manufacturers = self.get_manufacturers()
self.device_types = DeviceTypes(self.netbox, self.handle, self.counter)
self.device_types = DeviceTypes(self.netbox, self.handle, self.counter, self.ignore_ssl)

def connect_api(self):
try:
self.netbox = pynetbox.api(self.url, token=self.token)
if self.ignore_ssl:
self.handle.verbose_log("IGNORE_SSL_ERRORS is True, catching exception and disabling SSL verification.")
requests.packages.urllib3.disable_warnings()
#requests.packages.urllib3.disable_warnings()
self.netbox.http_session.verify = False
except Exception as e:
self.handle.exception("Exception", 'NetBox API Error', e)
Expand Down Expand Up @@ -183,11 +183,12 @@ class DeviceTypes:
def __new__(cls, *args, **kwargs):
return super().__new__(cls)

def __init__(self, netbox, handle, counter):
def __init__(self, netbox, handle, counter, ignore_ssl):
self.netbox = netbox
self.handle = handle
self.counter = counter
self.existing_device_types = self.get_device_types()
self.ignore_ssl = ignore_ssl

def get_device_types(self):
return {str(item): item for item in self.netbox.dcim.device_types.all()}
Expand Down Expand Up @@ -478,7 +479,7 @@ def upload_images(self,baseurl,token,images,device_type):
headers = { "Authorization": f"Token {token}" }

files = { i: (os.path.basename(f), open(f,"rb") ) for i,f in images.items() }
response = requests.patch(url, headers=headers, files=files, verify=False)
response = requests.patch(url, headers=headers, files=files, verify=(not self.ignore_ssl))

self.handle.log( f'Images {images} updated at {url}: {response}' )
self.counter["images"] += len(images)