Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
seperated updating database from regular usage
Browse files Browse the repository at this point in the history
  • Loading branch information
David Whiteside committed Nov 28, 2016
1 parent f6b12ce commit a6a794d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
=======

Expand Down
28 changes: 26 additions & 2 deletions lib/tracknodes/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Command Line Interface Module """
import optparse
from tracknodes import TrackNodes


Expand All @@ -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()
12 changes: 7 additions & 5 deletions lib/tracknodes/tracknodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit a6a794d

Please sign in to comment.