Skip to content

Commit

Permalink
Beta Release Merge (#87)
Browse files Browse the repository at this point in the history
* Delete gitcmd.py

* Delete nb-dt-import.py

* Add files via upload

* Logging cleanup (#78)

* Removed multiple imports of settings.py

* stating to abstract the netbox api calls to their own class

* Abstracted away determine features from main script, implemented as part of class initialization

* added helper functions to get repos relative & absolute path

* renaming gitcmd to repo

* starting to abstract away the get_files

* fixed issue where spaces and commas in vendor list with/without spaces breaks matching

* Added prelim fix for slugs if same issue vendors arg was facing exists. untested

* Finished abstracting the get_files function. Reduced fors and ifs to be cleaner and more efficent

* abstracted getFiles to repo class. Fixed slug issue not matching because of new slug format. added non-halting log function and renamed exception handler to log handler.

* utilized new logging class throughout script to reduce excess logging

* Abstracted and optimized create manufacturers

* Abstracted the create interfaces for devices to the netbox api class

* Fixed regression where check manufactuerers did not have the latest list

* Fixed regression caused by externally calling script. Discovered from #76

* abstracted all device interfaces to the devicetype class. optimized function calls to reduce duplicate code and reduce extra log calls

* Ran against all devices and passed with flying colors

* formatting settings.py

* formatting repo.py

* formatting main file

* formatting log_handler.py

* added back executable on file (#79)

* Add more info to failed device_type creations (#81)

---------

Co-authored-by: Philipp Rintz <[email protected]>
  • Loading branch information
danner26 and p-rintz authored Mar 24, 2023
1 parent 8832370 commit 98857fc
Show file tree
Hide file tree
Showing 7 changed files with 628 additions and 875 deletions.
27 changes: 0 additions & 27 deletions exception_handler.py

This file was deleted.

45 changes: 0 additions & 45 deletions gitcmd.py

This file was deleted.

44 changes: 44 additions & 0 deletions log_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from sys import exit as system_exit


class LogHandler:
def __new__(cls, *args, **kwargs):
return super().__new__(cls)

def __init__(self, args):
self.args = args

def exception(self, exception_type, exception, stack_trace=None):
exception_dict = {
"EnvironmentError": f'Environment variable "{exception}" is not set.',
"SSLError": f'SSL verification failed. IGNORE_SSL_ERRORS is {exception}. Set IGNORE_SSL_ERRORS to True if you want to ignore this error. EXITING.',
"GitCommandError": f'The repo "{exception}" is not a valid git repo.',
"GitInvalidRepositoryError": f'The repo "{exception}" is not a valid git repo.',
"Exception": f'An unknown error occurred: "{exception}"'
}

if self.args.verbose and stack_trace:
print(stack_trace)
print(exception_dict[exception_type])
system_exit(1)

def verbose_log(self, message):
if self.args.verbose:
print(message)

def log(self, message):
print(message)

def log_device_ports_created(self, created_ports: list = [], port_type: str = "port"):
for port in created_ports:
self.verbose_log(f'{port_type} Template Created: {port.name} - '
+ f'{port.type if hasattr(port, "type") else ""} - {port.device_type.id} - '
+ f'{port.id}')
return len(created_ports)

def log_module_ports_created(self, created_ports: list = [], port_type: str = "port"):
for port in created_ports:
self.verbose_log(f'{port_type} Template Created: {port.name} - '
+ f'{port.type if hasattr(port, "type") else ""} - {port.module_type.id} - '
+ f'{port.id}')
return len(created_ports)
Loading

0 comments on commit 98857fc

Please sign in to comment.