Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. def threaded_function(params):
  2. """the custom function
  3.  
  4. :param kwargs params: device details packed as keyword arguments
  5. :returns: dictionary containing the results of each step
  6. """
  7.  
  8. logging.debug('TEST')
  9. logging.info('TEST2')
  10. logging.error('TEST3')
  11.  
  12.  
  13.  
  14. def main_loop():
  15. logging.getLogger("netmiko").propagate = False
  16. logging.getLogger("netmiko").disabled = True
  17. logging.getLogger("paramiko").propagate = False
  18. logging.getLogger("paramiko").disabled = True
  19.  
  20. log_time = datetime.now().strftime("%Y%m%d-%H%M%S")
  21. LOG_FILE = os.path.basename(input_file) + '.txt'
  22.  
  23. logger = logging.getLogger()
  24. logger.setLevel(logging.DEBUG)
  25.  
  26. if args.log2file:
  27. log_format_file = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
  28. rfh = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=1048576, backupCount=10)
  29. rfh.setLevel(args.filelevel)
  30. rfh.setFormatter(log_format_file)
  31. logger.addHandler(rfh)
  32.  
  33. if args.log2con:
  34. log_format_con = logging.Formatter('%(message)s')
  35. ch = logging.StreamHandler()
  36. ch.setLevel(args.conlevel)
  37. ch.setFormatter(log_format_con)
  38. logger.addHandler(ch)
  39.  
  40. if not args.log2file and not args.log2con:
  41. logger.disabled = True
  42. logger.propagate = False
  43.  
  44. logging.info("JOB STARTED: " + str(log_time))
  45.  
  46.  
  47. pool = multiprocessing.Pool(max_cpu_count)
  48. with tqdm(total=len(input_list), ascii=True, unit="dev", desc='processing',
  49. disable=(False if args.log2con else True)) as t:
  50. for _ in pool.imap_unordered(threaded_function, input_list):
  51. t.update(1)
  52. results.append(_)
  53.  
  54.  
  55.  
  56. if __name__ == "__main__":
  57. main_loop()
Add Comment
Please, Sign In to add comment