Skip to content

Commit 98857fc

Browse files
danner26p-rintz
andauthored
Beta Release Merge (#87)
* 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]>
1 parent 8832370 commit 98857fc

7 files changed

+628
-875
lines changed

exception_handler.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

gitcmd.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

log_handler.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from sys import exit as system_exit
2+
3+
4+
class LogHandler:
5+
def __new__(cls, *args, **kwargs):
6+
return super().__new__(cls)
7+
8+
def __init__(self, args):
9+
self.args = args
10+
11+
def exception(self, exception_type, exception, stack_trace=None):
12+
exception_dict = {
13+
"EnvironmentError": f'Environment variable "{exception}" is not set.',
14+
"SSLError": f'SSL verification failed. IGNORE_SSL_ERRORS is {exception}. Set IGNORE_SSL_ERRORS to True if you want to ignore this error. EXITING.',
15+
"GitCommandError": f'The repo "{exception}" is not a valid git repo.',
16+
"GitInvalidRepositoryError": f'The repo "{exception}" is not a valid git repo.',
17+
"Exception": f'An unknown error occurred: "{exception}"'
18+
}
19+
20+
if self.args.verbose and stack_trace:
21+
print(stack_trace)
22+
print(exception_dict[exception_type])
23+
system_exit(1)
24+
25+
def verbose_log(self, message):
26+
if self.args.verbose:
27+
print(message)
28+
29+
def log(self, message):
30+
print(message)
31+
32+
def log_device_ports_created(self, created_ports: list = [], port_type: str = "port"):
33+
for port in created_ports:
34+
self.verbose_log(f'{port_type} Template Created: {port.name} - '
35+
+ f'{port.type if hasattr(port, "type") else ""} - {port.device_type.id} - '
36+
+ f'{port.id}')
37+
return len(created_ports)
38+
39+
def log_module_ports_created(self, created_ports: list = [], port_type: str = "port"):
40+
for port in created_ports:
41+
self.verbose_log(f'{port_type} Template Created: {port.name} - '
42+
+ f'{port.type if hasattr(port, "type") else ""} - {port.module_type.id} - '
43+
+ f'{port.id}')
44+
return len(created_ports)

0 commit comments

Comments
 (0)