3 # This script is used to manipulate the operational state of nodes in
4 # different node groups. These are basically set operations on nodes via the
7 # Take the ng name as an argument....
10 # * Set some or all in the set to rins.
11 # * get a list of nodes in the Alpha nodegroup.
13 # Given a nodelist, it could tag each one with a nodegroup name.
18 api = plc.PLC(auth.auth, auth.plc)
20 from config import config
21 from optparse import OptionParser
24 fb = soltesz.dbLoad("findbad")
26 def get_current_state(fbnode):
27 state = fbnode['state']
29 if l == "debug": return 'dbg'
32 parser = OptionParser()
33 parser.set_defaults(nodegroup="Alpha",
40 parser.add_option("", "--nodegroup", dest="nodegroup", metavar="NodegroupName",
41 help="Specify a nodegroup to perform actions on")
42 parser.add_option("", "--list", dest="list", action="store_true",
43 help="List all nodes in the given nodegroup")
44 parser.add_option("", "--add", dest="add", action="store_true",
45 help="Add nodes to the given nodegroup")
46 parser.add_option("", "--delete", dest="delete", action="store_true",
47 help="Delete nodes from the given nodegroup")
48 parser.add_option("", "--node", dest="node", metavar="nodename.edu",
49 help="A single node name to add to the nodegroup")
50 parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt",
51 help="Use all nodes in the given file for operation.")
52 config = config(parser)
55 # COLLECT nodegroups, nodes and node lists
56 ng = api.GetNodeGroups({'name' : config.nodegroup})
57 nodelist = api.GetNodes(ng[0]['node_ids'])
58 hostnames = [ n['hostname'] for n in nodelist ]
60 if config.node or config.nodelist:
61 if config.node: hostnames = [ config.node ]
62 else: hostnames = config.getListFromFile(config.nodelist)
66 print " ---- Nodes in the %s Node Group ----" % config.nodegroup
70 if node['hostname'] in fb['nodes']:
71 node['current'] = get_current_state(fb['nodes'][node['hostname']]['values'])
73 node['current'] = 'none'
74 print "%(hostname)-38s %(boot_state)5s %(current)5s %(key)s" % node
78 for node in hostnames:
79 print "Adding %s to %s nodegroup" % (config.node, config.nodegroup)
80 api.AddNodeToNodeGroup(config.node, config.nodegroup)
83 for node in hostnames:
84 print "Deleting %s from %s nodegroup" % (config.node, config.nodegroup)
85 api.DeleteNodeFromNodeGroup(config.node, config.nodegroup)
88 print "no other options supported."