From 136344d70597edefd38850aaa8efb9122f0387f0 Mon Sep 17 00:00:00 2001 From: "Daniel W. Anner" Date: Tue, 1 Aug 2023 10:32:57 -0400 Subject: [PATCH] Release v2.0.2 (#102) * Fix image upload v2 (#91) * Add upload_image functionality to new beta script * Updated for new location of files with Boolean flag for front/rear image * fixing the requests verify missing issue #95 (#96) * Bumping deps. Closes PR#99 and PR#98 (#100) * Added ability for IGNORE_SSL_ERRORS to dictate if the images upload verifys the request (#101) --------- Co-authored-by: J vanBemmel --- netbox_api.py | 9 +++++---- requirements.txt | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/netbox_api.py b/netbox_api.py index 539ef8d..f848d49 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -27,14 +27,14 @@ class NetBox: 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) @@ -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()} @@ -478,7 +479,7 @@ class DeviceTypes: 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) diff --git a/requirements.txt b/requirements.txt index 6dd2bc9..30ac661 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -GitPython==3.1.31 +GitPython==3.1.32 pynetbox==7.0.1 python-dotenv==1.0.0 -PyYAML==6.0 \ No newline at end of file +PyYAML==6.0.1 \ No newline at end of file