Index: /tools/gformat.py
===================================================================
--- /tools/gformat.py	(revision 13273)
+++ /tools/gformat.py	(revision 13274)
@@ -1672,6 +1672,35 @@
          'wzoeterwoude' : 'Stichting Wireless Leiden - Afdeling Zoeterwoude - Free-WiFi Project',
          'walphen' : 'Stichting Wireless Alphen',
-         'westeinder' : 'WestEinder Plassen',
+         'westeinder' : 'Westeinder Plassen',
       }
+
+      # Convert IP to Host
+      ip2host = {'root' : 'root'}
+      for host in get_hostlist():
+        datadump = get_yaml(host)
+        ip2host[datadump['masterip']] = datadump['autogen_fqdn']
+        for iface in datadump['autogen_iface_keys']:
+          ip2host[datadump[iface]['autogen_gateway']] = datadump['autogen_fqdn']
+
+      # Find dependency tree based on output of lvrouted.mytree of nearest node
+      parent = defaultdict(list)
+      stack = ['root']
+      prev_depth = 0
+      for line in open('lvrouted.mytree').readlines():
+        depth = line.count('\t')
+        ip = line.strip().split()[0]
+      
+        if prev_depth < depth:
+          print ip2host[stack[-1]], " -> ", ip2host[ip]
+          parent[ip2host[ip]].append(ip2host[stack[-1]])
+          stack.append(ip)
+        elif prev_depth > depth:
+          stack = stack[:(depth - prev_depth)]
+
+        prev_depth = depth
+      # Observe that some nodes has themself as parent or multiple parents
+      # for now take only the first parent, other behaviour is yet to be explained
+
+
 
       params = {
@@ -1835,7 +1864,14 @@
         host_name             %(autogen_fqdn)s
         address               %(masterip)s
-        hostgroups            srv_hybrid,%(monitoring_group)s
+        hostgroups            srv_hybrid,%(monitoring_group)s\
+''' % datadump
+        if len(parent[datadump['autogen_fqdn']]) > 0:
+          print '''\
+        parent                %(parent)s\
+''' % { 'parent' : parent[datadump['autogen_fqdn']][0] }
+        print '''\
 }
-''' % datadump
+'''
+
 
       for name,alias in hostgroup_details.iteritems(): 
