From db1ae0341501e96c6fe786dd037acc9e8a6de72d Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 17 May 2018 15:35:52 -0400 Subject: [PATCH] Sample script for mac to ipv6 translation Useful for some generic applications where nodediscover does not have full support, but must be used with care as it doesn't guarantee the mac address is what we expect it to be. --- .../samples/nodeattrib_from_switch.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 confluent_client/samples/nodeattrib_from_switch.py diff --git a/confluent_client/samples/nodeattrib_from_switch.py b/confluent_client/samples/nodeattrib_from_switch.py new file mode 100644 index 00000000..1e38d269 --- /dev/null +++ b/confluent_client/samples/nodeattrib_from_switch.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# This is a sample python script for going through all observed mac addresses +# and assuming they are BMC related and printing nodeattrib commands +# for each node to access the bmc using the interface specified on the command +# line + +# Not necessarily as useful if there may be mistakes in the +# net.switch/net.switchport attributes, but a handy utility in a pinch when +# you really know + + +import confluent.client as cl +import socket +import struct +c = cl.Command() +macs = [] +interface = sys.argv[1] +for mac in c.read('/networking/macs/by-mac/'): + macs.append(mac['item']['href']) +for mac in macs: + macinfo = list(c.read('/networking/macs/by-mac/{0}'.format(mac)))[0] + if 'possiblenode' in macinfo and macinfo['possiblenode']: + if macinfo['macsonport'] > 1: + print('Ambiguous set of macs on port for ' + macinfo[ + 'possiblenode']) + prefix = int(mac.replace('-', '')[:6], 16) ^ 0b100000000000000000 + prefix = prefix << 8 + prefix |= 0xff + suffix = int(mac.replace('-', '')[6:], 16) + suffix |= 0xfe000000 + rawn = struct.pack('!QLL', 0xfe80000000000000, prefix, suffix) + bmc = socket.inet_ntop(socket.AF_INET6, rawn) + print('nodeattrib {0} bmc={1}%{2}'.format(macinfo['possiblenode'], + bmc, interface))