X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=nodegroups.py;h=f5d46bae0f4cc3d621a093d93be3d10b0ab9a487;hb=refs%2Fheads%2F1.0;hp=20f1513cb9ee4fbcd243bc1aceb2bbeb62991f96;hpb=77f84f1e8242cdc45eb091ab65eef940a23493a6;p=monitor.git diff --git a/nodegroups.py b/nodegroups.py index 20f1513..f5d46ba 100755 --- a/nodegroups.py +++ b/nodegroups.py @@ -14,40 +14,28 @@ # * import plc -import auth -api = plc.PLC(auth.auth, auth.plc) +api = plc.getAuthAPI() -from optparse import OptionParser +import parser as parsermodule from sets import Set from nodequery import verify,query_to_dict,node_select from nodecommon import * -import soltesz +import database +import util.file def main(): - from config import config - fb = soltesz.dbLoad("findbad") - - parser = OptionParser() - parser.set_defaults(nodegroup="Alpha", - node=None, - nodelist=None, - list=True, + fb = database.dbLoad("findbad") + + parser = parsermodule.getParser(['nodesets']) + parser.set_defaults( list=True, add=False, nocolor=False, notng=False, - delete=False, - nodeselect=None, - ) + delete=False,) + parser.add_option("", "--not", dest="notng", action="store_true", help="All nodes NOT in nodegroup.") - parser.add_option("", "--nodegroup", dest="nodegroup", metavar="NodegroupName", - help="Specify a nodegroup to perform actions on") - parser.add_option("", "--nodeselect", dest="nodeselect", metavar="querystring", - help="Specify a query to perform on findbad db") - parser.add_option("", "--site", dest="site", metavar="site name", - help="Specify a site to view node status") - parser.add_option("", "--nocolor", dest="nocolor", action="store_true", help="Enable color") parser.add_option("", "--list", dest="list", action="store_true", @@ -56,19 +44,16 @@ def main(): help="Add nodes to the given nodegroup") parser.add_option("", "--delete", dest="delete", action="store_true", help="Delete nodes from the given nodegroup") - parser.add_option("", "--node", dest="node", metavar="nodename.edu", - help="A single node name to add to the nodegroup") - parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt", - help="Use all nodes in the given file for operation.") - config = config(parser) - config.parse_args() + + parser = parsermodule.getParser(['defaults'], parser) + config = parsermodule.parse_args(parser) # COLLECT nodegroups, nodes and node lists if config.node or config.nodelist: if config.node: hostlist = [ config.node ] else: - hostlist = config.getListFromFile(config.nodelist) + hostlist = util.file.getListFromFile(config.nodelist) # NOTE: preserve order given in file. Otherwise, return values are not in order # given to GetNodes @@ -96,7 +81,7 @@ def main(): group_str = "selection" else: - ng = api.GetNodeGroups({'name' : config.nodegroup}) + ng = api.GetNodeGroups({'grouname' : config.nodegroup}) nodelist = api.GetNodes(ng[0]['node_ids']) group_str = config.nodegroup @@ -119,15 +104,8 @@ def main(): hostnames = [ n['hostname'] for n in nodelist ] # commands: - if config.list: - print " ---- Nodes in the %s Node Group ----" % group_str - i = 1 - for node in nodelist: - print "%-2d" % i, - print nodegroup_display(node, fb, config) - i += 1 - elif config.add and config.nodegroup: + if config.add and config.nodegroup: for node in hostnames: print "Adding %s to %s nodegroup" % (node, config.nodegroup) api.AddNodeToNodeGroup(node, config.nodegroup) @@ -137,6 +115,15 @@ def main(): print "Deleting %s from %s nodegroup" % (node, config.nodegroup) api.DeleteNodeFromNodeGroup(node, config.nodegroup) + elif config.list: + print " ---- Nodes in the %s Node Group ----" % group_str + print " Hostname plc obs pcu key kernel last_contact, last change, comon uptime" + i = 1 + for node in nodelist: + print "%-2d" % i, + print nodegroup_display(node, fb, config) + i += 1 + else: print "no other options supported."