4 from monitor.wrapper import plc
7 from monitor import parser as parsermodule
10 from monitor.database.info.model import FindbadNodeRecord
12 def network_config_to_str(net):
15 static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
17 str += "%15s == %s\n" % (k, net[k])
24 parser = parsermodule.getParser()
25 parser.set_defaults(nodelist=None,
31 parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt",
32 help="Use all nodes in the given file for operation.")
33 parser = parsermodule.getParser(['defaults'], parser)
34 config = parsermodule.parse_args(parser)
36 # COLLECT nodegroups, nodes and node lists
37 for node in config.args:
40 n = api.GetNodes(node)[0]
42 net = api.GetInterfaces(n['interface_ids'])[0]
45 node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
48 #print "%15s == %s" % (k, diff_time(n[k]))
49 print "%15s == %s" % (k, n[k])
51 print "%15s == %s" % (k, n[k])
53 print network_config_to_str(net)
56 # print k, "==" , net[k]
58 #from monitor.common import email_exception
59 print "Error with %s" % node
61 import traceback; print traceback.print_exc()
67 print " ---- Nodes in the %s Node Group ----" % group_str
71 fbdata = FindbadNodeRecord.get_latest_by(hostname=node['hostname'])
72 print nodegroup_display(node, fbdata.to_dict())
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__":