X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=nodegroups.py;h=fcaaefe3bc33055df0adcfdfaea2206b57183de7;hb=518d32bd27e1b868b53da405959a25179591573e;hp=725d0e0317ef44f6dea97075a87fe05a412ab510;hpb=f38420ff4bc9fb114db5f62b01cc8990dc0a0af2;p=monitor.git diff --git a/nodegroups.py b/nodegroups.py index 725d0e0..fcaaefe 100755 --- a/nodegroups.py +++ b/nodegroups.py @@ -19,6 +19,7 @@ api = plc.PLC(auth.auth, auth.plc) from optparse import OptionParser from sets import Set +from nodequery import verify,query_to_dict,node_select from nodecommon import * import soltesz @@ -31,16 +32,24 @@ def main(): parser.set_defaults(nodegroup="Alpha", node=None, nodelist=None, - list=False, + list=True, add=False, + nocolor=False, notng=False, delete=False, + nodeselect=None, ) 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", help="List all nodes in the given nodegroup") parser.add_option("", "--add", dest="add", action="store_true", @@ -70,6 +79,22 @@ def main(): #nodelist = api.GetNodes(hostlist) group_str = "Given" + elif config.site: + site = api.GetSites(config.site) + if len (site) > 0: + site = site[0] + nodelist = api.GetNodes(site['node_ids']) + else: + nodelist = [] + + group_str = config.site + + elif config.nodeselect: + hostlist = node_select(config.nodeselect) + nodelist = api.GetNodes(hostlist) + + group_str = "selection" + else: ng = api.GetNodeGroups({'name' : config.nodegroup}) nodelist = api.GetNodes(ng[0]['node_ids']) @@ -94,15 +119,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) - 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) @@ -112,6 +130,14 @@ 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 + i = 1 + for node in nodelist: + print "%-2d" % i, + print nodegroup_display(node, fb, config) + i += 1 + else: print "no other options supported."