From 53363905dd9aed52ce6f37d5fef98fa100fc6d34 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 17 Aug 2020 12:33:13 -0400 Subject: [PATCH] Add ability to call apiclient to configbmc Next to put it into various profiles and genesis. --- misc/configbmc.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/misc/configbmc.py b/misc/configbmc.py index 1ce7dbfc..610b3c9c 100644 --- a/misc/configbmc.py +++ b/misc/configbmc.py @@ -19,9 +19,16 @@ import json from select import select import socket import struct +import os +import subprocess import sys import time +if os.path.exists('/opt/confluent/bin/apiclient'): + apiclient = '/opt/confluent/bin/apiclient' +elif os.path.exists('/etc/confluent/apiclient'): + apiclient = '/etc/confluent/apiclient' + class IpmiMsg(ctypes.Structure): _fields_ = [('netfn', ctypes.c_ubyte), ('cmd', ctypes.c_ubyte), @@ -296,9 +303,15 @@ def main(): a.add_argument('-p', help='Which port to use (dedicated, lom, ocp, ml2)') a.add_argument('-i', help='JSON configuration file to read for ' 'configuration') + a.add_argument('-c', help='Use Confluent API to direct BMC configuration', + action='store_true') args = a.parse_args() if args.i: bmccfg = json.load(open(args.i)) + elif args.c: + bmccfgsrc = subprocess.check_output( + [sys.executable, apiclient, '/confluent-api/self/bmcconfig', '-j']) + bmccfg = json.loads(bmccfgsrc) else: bmccfg = {} if args.p is not None: @@ -317,13 +330,13 @@ def main(): model = model[:4].lower() s = Session('/dev/ipmi0') if not bmccfg: - print("No configuration requested, exiting...") + print("No BMC configuration specified, exiting.") return - if bmccfg.get('bmcport', None) is not None: + if bmccfg.get('bmcport', None): channel = set_port(s, bmccfg['bmcport'], vendor, model) else: channel = get_lan_channel(s) - if bmccfg.get('bmcvlan', None) is not None: + if bmccfg.get('bmcvlan', None): set_vlan(s, bmccfg['bmcvlan'], channel) if bmccfg.get('bmcipv4', None): set_ipv4(s, bmccfg['bmcipv4'], channel)