mirror of
https://github.com/xcat2/confluent.git
synced 2025-01-16 04:39:16 +00:00
232140899e
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.
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
#!/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))
|