diff --git a/misc/cfg-dhcp-redfish-bmcs-by-switch.py b/misc/cfg-dhcp-redfish-bmcs-by-switch.py new file mode 100755 index 00000000..797edc5d --- /dev/null +++ b/misc/cfg-dhcp-redfish-bmcs-by-switch.py @@ -0,0 +1,120 @@ +#!/usr/bin/python3 +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright 2017-2021 Lenovo +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +sys.path.append('/opt/confluent/lib/python') +import confluent.client as cli +import eventlet.greenpool +import gzip +import io +import json +import os +import struct +import subprocess +import time + +webclient = eventlet.import_patched('pyghmi.util.webclient') + + +bmcsbyuuid = {} +def checkfish(addr, mac): + wc = webclient.SecureHTTPConnection(addr, 443, verifycallback=lambda x: True) + wc.connect() + wc.request('GET', '/redfish/v1') + rsp = wc.getresponse() + body = rsp.read() + if body[:2] == b'\x1f\x8b': + body = gzip.GzipFile(fileobj=io.BytesIO(body)).read() + try: + body = json.loads(body) + except json.decoder.JSONDecodeError: + return + uuid = body.get('UUID', None) + if not uuid: + return + #This part is needed if a bmc sticks 'wire format' uuid in the json body + #Should be skipped for bmcs that present it sanely + uuidparts = uuid.split('-') + uuidparts[0] = '{:08x}'.format(struct.unpack('!I', struct.pack('