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
23 parser = OptionParser()
24 parser.set_defaults(nodegroup="Alpha",
31 parser.add_option("", "--nodegroup", dest="nodegroup", metavar="NodegroupName",
32 help="Specify a nodegroup to perform actions on")
33 parser.add_option("", "--list", dest="list", action="store_true",
34 help="List all nodes in the given nodegroup")
35 parser.add_option("", "--add", dest="add", action="store_true",
36 help="Add nodes to the given nodegroup")
37 parser.add_option("", "--delete", dest="delete", action="store_true",
38 help="Delete nodes from the given nodegroup")
39 parser.add_option("", "--node", dest="node", metavar="nodename.edu",
40 help="A single node name to add to the nodegroup")
41 parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt",
42 help="Use all nodes in the given file for operation.")
43 config = config(parser)
46 # COLLECT nodegroups, nodes and node lists
47 ng = api.GetNodeGroups({'name' : config.nodegroup})
48 nodelist = api.GetNodes(ng[0]['node_ids'])
49 hostnames = [ n['hostname'] for n in nodelist ]
51 if config.node or config.nodelist:
52 if config.node: hostnames = [ config.node ]
53 else: hostnames = config.getListFromFile(config.nodelist)
57 print " ---- Nodes in the %s Node Group ----" % config.nodegroup
61 print "%(hostname)-38s %(boot_state)5s %(key)s" % node
65 for node in hostnames:
66 print "Adding %s to %s nodegroup" % (config.node, config.nodegroup)
67 api.AddNodeToNodeGroup(config.node, config.nodegroup)
70 for node in hostnames:
71 print "Deleting %s from %s nodegroup" % (config.node, config.nodegroup)
72 api.DeleteNodeFromNodeGroup(config.node, config.nodegroup)
75 print "no other options supported."