6 api = plc.PLC(auth.auth, auth.plc)
8 from optparse import OptionParser
11 from nodecommon import *
14 def network_config_to_str(net):
17 static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
19 str += "%15s == %s\n" % (k, net[k])
25 from config import config
26 fb = database.dbLoad("findbad")
28 parser = OptionParser()
29 parser.set_defaults(nodelist=None,
35 parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt",
36 help="Use all nodes in the given file for operation.")
37 config = config(parser)
40 # COLLECT nodegroups, nodes and node lists
41 for node in config.args:
44 n = api.GetNodes(node)[0]
46 net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
49 node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
52 print "%15s == %s" % (k, diff_time(n[k]))
54 print "%15s == %s" % (k, n[k])
56 print network_config_to_str(net)
59 # print k, "==" , net[k]
61 print "Error with %s" % node
62 import traceback; print traceback.print_exc()
68 print " ---- Nodes in the %s Node Group ----" % group_str
72 print nodegroup_display(node, fb)
75 elif config.add and config.nodegroup:
76 for node in hostnames:
77 print "Adding %s to %s nodegroup" % (node, config.nodegroup)
78 api.AddNodeToNodeGroup(node, config.nodegroup)
81 for node in hostnames:
82 print "Deleting %s from %s nodegroup" % (node, config.nodegroup)
83 api.DeleteNodeFromNodeGroup(node, config.nodegroup)
86 print "no other options supported."
88 if __name__ == "__main__":