Index: /tools/gformat.py
===================================================================
--- /tools/gformat.py	(revision 13335)
+++ /tools/gformat.py	(revision 13336)
@@ -715,4 +715,6 @@
   datadump['autogen_normal_proxies_ips'] = ','.join([x['masterip'] for x in normal_proxies])
   datadump['autogen_normal_proxies_names'] = ','.join([x['autogen_item'] for x in normal_proxies])
+  datadump['autogen_attached_devices'] = [x[2] for x in get_attached_devices(datadump)]
+  datadump['autogen_neighbours'] = [x[1] for x in get_neighbours(datadump)]
 
   output = generate_header(datadump, "#");
@@ -850,4 +852,11 @@
 
 #
+# Script variables
+#
+attached_devices="{{ autogen_attached_devices|join(' ') }}"
+neighbours="{{ autogen_neighbours|join(' ') }}"
+
+
+#
 # Interface definitions
 #\n
@@ -932,4 +941,49 @@
 
   return nameservers_cache[0:max_servers]
+
+
+def get_neighbours(datadump):
+  (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
+
+  (poel, errors) = make_relations()
+  table = []
+  for iface,addrs in sorted(addrs_list.iteritems()):
+    if iface in ['lo0']:
+      continue
+
+    for addr, comment in sorted(addrs,key=lambda x: parseaddr(x[0].split('/')[0])):
+      if not addr.startswith('172.'):
+        # Avoid listing internet connections as pool
+        continue
+      for neighbour in poel[network(addr)]:
+        if neighbour[0] != datadump['autogen_item']:
+          table.append((iface, neighbour[1]['ip'].split('/')[0], neighbour[0] + " (" + neighbour[1]['autogen_ifname'] + ")", neighbour[1]['comment']))
+  return table
+
+
+def get_attached_devices(datadump, url=False):
+  table = []
+  for iface_key in get_interface_keys(datadump, True):
+    # Quick to avoid listing ath(4) interface as attached device
+    if 'ath0' in iface_key:
+      continue
+    ifacedump = datadump[iface_key]
+    if ifacedump.has_key('ns_ip'):
+      x_ip = ifacedump['ns_ip'].split('/')[0]
+    else:
+      x_ip = ifacedump['ip'].split('/')[0]
+
+    if 'mode' in ifacedump:
+      x_mode = ifacedump['mode']
+    else:
+      x_mode = 'unknown'
+
+    if 'bridge_type' in ifacedump:
+      device_type = ifacedump['bridge_type']
+    else:
+      device_type = 'Unknown'
+
+    table.append((ifacedump['autogen_ifname'], x_mode, 'http://%s' % x_ip if url else x_ip, device_type))
+  return table
 
 
@@ -1071,47 +1125,10 @@
 Attached devices:
 """
-  table = []
-  for iface_key in get_interface_keys(datadump, True):
-    # Quick to avoid listing ath(4) interface as attached device
-    if 'ath0' in iface_key:
-      continue
-    ifacedump = datadump[iface_key]
-    if ifacedump.has_key('ns_ip'):
-      x_ip = ifacedump['ns_ip'].split('/')[0]
-    else:
-      x_ip = ifacedump['ip'].split('/')[0]
-
-    if 'mode' in ifacedump:
-      x_mode = ifacedump['mode']
-    else:
-      x_mode = 'unknown'
-
-    if 'bridge_type' in ifacedump:
-      device_type = ifacedump['bridge_type']
-    else:
-      device_type = 'Unknown'
-
-    table.append((ifacedump['autogen_ifname'], x_mode, "http://%s" % x_ip, device_type))
-
-  output += make_table(table)
+  output += make_table(get_attached_devices(datadump, url=True))
   output += '\n'
   output += """\
 Available neighbours:
 """
-  (poel, errors) = make_relations()
-  table = []
-  for iface,addrs in sorted(addrs_list.iteritems()):
-    if iface in ['lo0']:
-      continue
-
-    for addr, comment in sorted(addrs,key=lambda x: parseaddr(x[0].split('/')[0])):
-      if not addr.startswith('172.'):
-        # Avoid listing internet connections as pool
-        continue
-      for neighbour in poel[network(addr)]:
-        if neighbour[0] != datadump['autogen_item']:
-          table.append((iface, neighbour[1]['ip'].split('/')[0], neighbour[0] + " (" + neighbour[1]['autogen_ifname'] + ")", neighbour[1]['comment']))
-
-  output += make_table(table)
+  output += make_table(get_neighbours(datadump))
 
   return output
