7 from optparse import OptionParser
10 from nodecommon import *
13 def network_config_to_str(net):
16 static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
18 str += "%15s == %s\n" % (k, net[k])
24 from config import config
25 fb = database.dbLoad("findbad")
27 parser = OptionParser()
28 parser.set_defaults(nodelist=None,
34 parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt",
35 help="Use all nodes in the given file for operation.")
36 config = config(parser)
39 # COLLECT nodegroups, nodes and node lists
40 for node in config.args:
43 n = api.GetNodes(node)[0]
45 net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
48 node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
51 print "%15s == %s" % (k, diff_time(n[k]))
53 print "%15s == %s" % (k, n[k])
55 print network_config_to_str(net)
58 # print k, "==" , net[k]
60 print "Error with %s" % node
61 import traceback; print traceback.print_exc()
67 print " ---- Nodes in the %s Node Group ----" % group_str
71 print nodegroup_display(node, fb)
74 elif config.add and config.nodegroup:
75 for node in hostnames:
76 print "Adding %s to %s nodegroup" % (node, config.nodegroup)
77 api.AddNodeToNodeGroup(node, config.nodegroup)
80 for node in hostnames:
81 print "Deleting %s from %s nodegroup" % (node, config.nodegroup)
82 api.DeleteNodeFromNodeGroup(node, config.nodegroup)
85 print "no other options supported."
87 if __name__ == "__main__":