summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2016-06-02 23:39:10 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2016-06-02 23:39:10 +0200
commit41eaecd927452eda97875d388f12da2009d6a6cf (patch)
tree2f717e12fcf6562683a7815c84ea7caf339309ea
parent57be36071e3adcb8c7d59f096cfb82d2f47ce8c5 (diff)
downloadhaircontrol-41eaecd927452eda97875d388f12da2009d6a6cf.zip
haircontrol-41eaecd927452eda97875d388f12da2009d6a6cf.tar.gz
haircontrol-41eaecd927452eda97875d388f12da2009d6a6cf.tar.bz2
Make room for direct_neighbours, add inter.py for use in interactive python shell.
-rw-r--r--.gitignore1
-rw-r--r--haircontrol/data.py5
-rw-r--r--haircontrol/discovery.py28
-rwxr-xr-xtests/inter.py25
-rwxr-xr-xtests/test_discovery.py3
5 files changed, 59 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index bee8a64..8d35cb3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
__pycache__
+*.pyc
diff --git a/haircontrol/data.py b/haircontrol/data.py
index 2ab8268..1eb4d3b 100644
--- a/haircontrol/data.py
+++ b/haircontrol/data.py
@@ -60,8 +60,9 @@ class Interface:
self.name = name
self.mac = mac
self.mac_seen = []
+ self.direct_neighbours = []
def __repr__(self):
- return repr( ( self.mac, self.name, self.mac_seen ) )
- #return repr( ( self.mac, self.name, '[ %i mac_seen ]'%len(self.mac_seen) ) )
+ #return repr( ( self.mac, self.name, self.direct_neighbours, self.mac_seen ) )
+ return repr( ( self.mac, self.name, self.direct_neighbours, '[ %i mac_seen ]'%len(self.mac_seen) ) )
diff --git a/haircontrol/discovery.py b/haircontrol/discovery.py
index d6839b2..a9639be 100644
--- a/haircontrol/discovery.py
+++ b/haircontrol/discovery.py
@@ -179,3 +179,31 @@ class Discovery:
print("Notice: Nothing inspected on %s"%e)
i.disconnect()
+ def compute_neighbourhood(self):
+ print("**********compute_neighbourhood************")
+ # net.equipments[<mgmt_ip>].ifaces[<ifname>].mac_seen[i]
+
+ # Fake algorithm
+ random_e = '172.16.0.254'
+ for (mgmt_ip,e) in self.net.equipments.items():
+ for (ifname,i) in e.ifaces.items():
+ last = None
+ for mac_seen in i.mac_seen:
+ last = mac_seen
+ if last and last in self.net.mac2ip:
+ random_e = self.net.mac2ip[last]
+ i.direct_neighbours.append(random_e)
+
+# for (mgmt_ip,e) in self.net.equipments.items():
+# print("%s (%s)"%(mgmt_ip,e.name))
+# for (ifname,i) in e.ifaces.items():
+# print("\t%s"%i.name)
+# for mac_seen in i.mac_seen:
+# print("\t\tseen %s"%mac_seen)
+# for remote_mgmtip in i.direct_neighbours:
+# e = self.net.equipments[remote_mgmtip]
+# print("\t\tdirect_neighbour %s (%s)"%(remote_mgmtip, e.name))
+
+
+ print("**********compute_neighbourhood************")
+
diff --git a/tests/inter.py b/tests/inter.py
new file mode 100755
index 0000000..961aa83
--- /dev/null
+++ b/tests/inter.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+# TO USE this in interfactive mode :
+# python3
+# >>> from inter import eq
+# >>> eq['172.16.20.210'].ifaces
+# {'?': ('c0:4a:00:fe:1f:87', '?', [], '[ 0 mac_seen]')}
+
+import context
+from haircontrol import discovery, data #, inspectors
+
+discovery = discovery.Discovery() #MockInspector('../test-data/input'))
+discovery.discover_lldp_hinting(data.Equipment('stg2', '172.16.0.253'))
+discovery.discover_static_hinting([
+ ('SW_SergeGOUSSE', '172.16.30.23'),
+ ('SW_PI_EGL', '172.16.30.27'),
+ ('SW_Eglise_ESTANCARBON', '172.16.30.38'),
+])
+discovery.discover_from_root(data.Equipment('stg', '172.16.0.254'))
+discovery.compute_neighbourhood()
+
+eq = discovery.net.equipments
+
+
+
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
index 2e7b308..d89d6f6 100755
--- a/tests/test_discovery.py
+++ b/tests/test_discovery.py
@@ -20,8 +20,9 @@ class TestDiscovery(unittest.TestCase):
('SW_Eglise_ESTANCARBON', '172.16.30.38'),
])
self.discovery.discover_from_root(data.Equipment('stg', '172.16.0.254'))
+ self.discovery.compute_neighbourhood()
# self.assertEqual(self.ref_net.get_equipment_list_sorted(), list(self.discovery.net.get_equipment_list_sorted()))
- print(self.discovery.net)
+ print(self.discovery.net) # <----- ya un gros print ici qui affiche... tout.
if __name__ == '__main__':
unittest.main()