4 from monitor.wrapper import plc
7 from monitor import parser as parsermodule
10 from monitor.common import *
11 from monitor.database.info.model import FindbadNodeRecord
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])
25 parser = parsermodule.getParser()
26 parser.set_defaults(nodelist=None,
32 parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt",
33 help="Use all nodes in the given file for operation.")
34 parser = parsermodule.getParser(['defaults'], parser)
35 config = parsermodule.parse_args(parser)
37 # COLLECT nodegroups, nodes and node lists
38 for node in config.args:
41 n = api.GetNodes(node)[0]
43 net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
46 node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
49 print "%15s == %s" % (k, diff_time(n[k]))
51 print "%15s == %s" % (k, n[k])
53 print network_config_to_str(net)
56 # print k, "==" , net[k]
58 print "Error with %s" % node
59 import traceback; print traceback.print_exc()
65 print " ---- Nodes in the %s Node Group ----" % group_str
69 fbdata = FindbadNodeRecord.get_latest_by(hostname=node['hostname'])
70 print nodegroup_display(node, fbdata.to_dict())
73 elif config.add and config.nodegroup:
74 for node in hostnames:
75 print "Adding %s to %s nodegroup" % (node, config.nodegroup)
76 api.AddNodeToNodeGroup(node, config.nodegroup)
79 for node in hostnames:
80 print "Deleting %s from %s nodegroup" % (node, config.nodegroup)
81 api.DeleteNodeFromNodeGroup(node, config.nodegroup)
84 print "no other options supported."
86 if __name__ == "__main__":