3 from monitor.wrapper import plc
8 HOSTS_FILE="/etc/hosts"
10 def is_in_file(filename, pattern):
11 f = os.popen("grep %s %s" % ( pattern, filename))
17 def add_to_file(filename, data):
18 os.system("echo '%s' >> %s" % (data, filename))
19 #print "echo '%s' >> %s" % (data, filename)
21 sites = api.GetSites({'login_base' : 'mlab*'}, ['node_ids'])
23 nodes = api.GetNodes(s['node_ids'], ['hostname', 'interface_ids'])
26 i = api.GetInterfaces({ 'interface_id' : node['interface_ids'], 'is_primary' : True})
28 #print "%s %s" % (i[0]['ip'], node['hostname'])
29 if not is_in_file(HOSTS_FILE, node['hostname']):
30 add_to_file(HOSTS_FILE, "%s %s" % (i[0]['ip'], node['hostname']))