diff --git a/qwalk.py b/qwalk.py index 5e84d0f..24ce7e1 100755 --- a/qwalk.py +++ b/qwalk.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import argparse +import datetime +import getpass import os import sys @@ -16,11 +18,12 @@ def main() -> None: "-u", help="Qumulo API user", default=os.getenv("QUSER") or "admin" ) parser.add_argument( - "-p", help="Qumulo API password", default=os.getenv("QPASS") or "admin" + "-p", help="Qumulo API password", default=os.getenv("QPASS") ) parser.add_argument("-d", help="Starting directory", required=True) parser.add_argument("-g", help="Run with filesystem changes", action="store_true") - parser.add_argument("-l", help="Log file", default="output-walk-log.txt") + parser.add_argument("-l", help="Log file. Use 'None' to disable logging.", default=datetime.datetime.now().strftime("%Y%m%dT%H%M%S-") + "output-walk-log.txt") + parser.add_argument("-f", help="Force script to run on directly on a Qumulo node.", action="store_true") parser.add_argument( "-c", help="Class to run.", @@ -38,6 +41,21 @@ def main() -> None: print("-" * 80) sys.exit(0) + # Make sure we're not running directly on a Qumulo node + RunningOnNode=os.system("qq cluster_conf | jq -cr .cluster_name > " + os.devnull + " 2>&1 ") + if RunningOnNode == 0: + print("The qwalk command should not be executed direcly on a Qumulo node.") + if not args.f: + exit(1) + + # Prompt for password if one was not given by ENV or command entry + if not args.p: + args.p = getpass.getpass() + + # If the log parameter is set to "None" send logs to devNull + if args.l == "None": + args.l == os.devnull + QWalkWorker.run_all( args.s, args.u,