From a6a794d3ce1881bfb1556d836e08bd57fe2912cb Mon Sep 17 00:00:00 2001 From: David Whiteside Date: Mon, 28 Nov 2016 15:35:31 -0700 Subject: [PATCH] seperated updating database from regular usage --- README.md | 18 +++++++++++++++++- lib/tracknodes/cli.py | 28 ++++++++++++++++++++++++++-- lib/tracknodes/tracknodes.py | 12 +++++++----- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0c08953..0ff5739 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Setup a cronjob on the admin node. ```shell $ crontab -u root -e # Track Node State Every Minute -* * * * * (/usr/bin/tracknodes >/dev/null 2>&1) +* * * * * (/usr/bin/tracknodes --update >/dev/null 2>&1) ``` Use the below command to see the history of node changes. @@ -51,6 +51,22 @@ n021 | 2016-11-26 19:00:01 | offline,down | 'DIMM Configuration Error' -- -- ``` +Use --help to show all options. + +```shell +$ tracknodes --help +Usage: tracknodes [options] + +Options: + -h, --help show this help message and exit + -U, --update Update Database From PBS + -f DBFILE, --dbfile=DBFILE + SQL-Lite Database File + -c PBSNODESCMD, --pbsnodes_cmd=PBSNODESCMD + pbsnodes binary location, example: /opt/pbsnodes + -v, --verbose Verbose Output +``` + License ======= diff --git a/lib/tracknodes/cli.py b/lib/tracknodes/cli.py index 2ac1259..104d587 100644 --- a/lib/tracknodes/cli.py +++ b/lib/tracknodes/cli.py @@ -1,4 +1,5 @@ """ Command Line Interface Module """ +import optparse from tracknodes import TrackNodes @@ -7,9 +8,32 @@ class Cli(object): def __init__(self): """ Setup Arguments and Options for CLI """ - pass + parser = optparse.OptionParser() + parser.add_option("-U", "--update", dest="update", + help="Update Database From PBS", + metavar="UPDATE", + action="store_true", + default=False) + parser.add_option("-f", "--dbfile", dest="dbfile", + help="SQL-Lite Database File", + metavar="DBFILE", + default=None) + parser.add_option("-c", "--pbsnodes_cmd", dest="pbsnodes_cmd", + help="pbsnodes binary location, example: /opt/pbsnodes", + metavar="PBSNODESCMD", + default="pbsnodes") + parser.add_option("-v", "--verbose", dest="verbose", + help="Verbose Output", + metavar="VERBOSE", + action="store_true", + default=False) + (options, args) = parser.parse_args() + self.update = options.update + self.pbsnodes_cmd = options.pbsnodes_cmd + self.dbfile = options.dbfile + self.verbose = options.verbose def run(self): """ EntryPoint Of Application """ - pbsnodes = TrackNodes() + pbsnodes = TrackNodes(update=self.update, dbfile=self.dbfile, pbsnodes_cmd=self.pbsnodes_cmd, verbose=self.verbose) pbsnodes.print_history() diff --git a/lib/tracknodes/tracknodes.py b/lib/tracknodes/tracknodes.py index 086cf09..d0bdc0b 100644 --- a/lib/tracknodes/tracknodes.py +++ b/lib/tracknodes/tracknodes.py @@ -5,7 +5,7 @@ class TrackNodes: - def __init__(self, dbfile=None, pbsnodes_cmd=None, verbose=False): + def __init__(self, update=False, dbfile=None, pbsnodes_cmd=None, verbose=False): """ Create initial sqlite database and initialize connection """ @@ -14,7 +14,7 @@ def __init__(self, dbfile=None, pbsnodes_cmd=None, verbose=False): self.current_failed = [] self.dbfile = dbfile - self.pbsnodes_cmd = pbsnodes_cmd + self.pbsnodes_cmd = TrackNodes.which(pbsnodes_cmd) self.verbose = verbose # Look for pbsnodes as option, in PATH, then specific locations @@ -50,9 +50,11 @@ def __init__(self, dbfile=None, pbsnodes_cmd=None, verbose=False): self.cur.execute("CREATE TABLE NodeStates(Name TEXT, State INT, Comment TEXT, Time TEXT)") self.con.commit() - self.parse_pbsnodes() - self.online_nodes() - self.fail_nodes() + # Get Latest Node Information, Update Database + if update: + self.parse_pbsnodes() + self.online_nodes() + self.fail_nodes() def online_nodes(self): """