Cleaned up and added a more traditional toggle for turning dynamic fan on and off.

This commit is contained in:
Tristan Smith 2024-03-21 20:50:07 -04:00
parent d089e0209d
commit b49b9aa6f0

View file

@ -4,10 +4,10 @@ import subprocess
# Server IPMI details # Server IPMI details
IPMIHOST = "192.168.1.223" IPMIHOST = "192.168.1.223"
IPMIUSER = "root" IPMIUSER = "root"
IPMIPASS = "<password>" IPMIPASS = "fuck pizza hut"
def execute_ipmi_command(command): def execute_ipmi_command(command):
full_command = f"ipmitool -I lanplus -H {IPMIHOST} -U {IPMIUSER} -P {IPMIPASS} {command}" full_command = f"ipmitool -I lanplus -H {IPMIHOST} -U {IPMIUSER} -P \"{IPMIPASS}\" {command}"
print(f"Executing command: {full_command}") # Print the full command to debug print(f"Executing command: {full_command}") # Print the full command to debug
result = subprocess.run(full_command, shell=True, capture_output=True, text=True) result = subprocess.run(full_command, shell=True, capture_output=True, text=True)
print(result.stdout) print(result.stdout)
@ -18,23 +18,29 @@ def power_on():
print("Powering on the server...") print("Powering on the server...")
execute_ipmi_command("chassis power on") execute_ipmi_command("chassis power on")
def power_off():
print("Powering off the server...")
execute_ipmi_command("chassis power off")
def set_fan_speed(speed): def set_fan_speed(speed):
print(f"Setting fan speed to {speed}%...") print(f"Setting fan speed to {speed}%...")
# You'll need to convert the percentage to your server's specific command. # You'll need to convert the percentage to your server's specific command.
# This is a placeholder for how you might implement it.
fan_speed_value = int((speed * 255) / 100) # Example conversion fan_speed_value = int((speed * 255) / 100) # Example conversion
execute_ipmi_command(f"raw 0x30 0x30 0x02 0xff {hex(fan_speed_value)}") execute_ipmi_command(f"raw 0x30 0x30 0x02 0xff {hex(fan_speed_value)}")
def toggle_dynamic_fan_control(): def enable_dynamic_fan_control():
print("Toggling dynamic fan control...") print("Enabling dynamic fan control...")
# Placeholder - Implement the actual IPMI command to toggle dynamic control execute_ipmi_command("raw 0x30 0x30 0x01 0x01")
execute_ipmi_command("raw 0x30 0x30 0x01 0x01") # This command may need to be adjusted
def disable_dynamic_fan_control():
print("Disabling dynamic fan control...")
execute_ipmi_command("raw 0x30 0x30 0x01 0x00")
# Argument Parsing # Argument Parsing
parser = argparse.ArgumentParser(description='Server Management Script') parser = argparse.ArgumentParser(description='Server Management Script')
parser.add_argument('-p', '--power', choices=['on', 'off'], help='Power on or off the server') parser.add_argument('-p', '--power', choices=['on', 'off'], help='Power on or off the server')
parser.add_argument('-f', '--fan', type=int, choices=range(0,101), metavar="[0-100]", help='Set fan speed percentage') parser.add_argument('-f', '--fan', type=int, choices=range(0,101), metavar="[0-100]", help='Set fan speed percentage')
parser.add_argument('-d', '--dynamic', action='store_true', help='Toggle dynamic fan control') parser.add_argument('-d', '--dynamic', choices=['on', 'off'], help='Toggle dynamic fan control')
args = parser.parse_args() args = parser.parse_args()
@ -42,9 +48,23 @@ args = parser.parse_args()
if args.power == 'on': if args.power == 'on':
power_on() power_on()
elif args.power == 'off': elif args.power == 'off':
# Here, you can add a function to power off if desired power_off()
pass else:
print("No action specified. Exiting...")
if args.fan is not None: if args.fan is not None:
set_fan_speed(args.fan) set_fan_speed(args.fan)
if args.dynamic: if args.dynamic == 'on':
toggle_dynamic_fan_control() enable_dynamic_fan_control()
elif args.dynamic == 'off':
disable_dynamic_fan_control()
if not (args.power or args.fan or args.dynamic):
parser.print_help()
else:
if args.power == 'on':
power_on()
elif args.power == 'off':
# Here, you can add a function to power off if desired
pass
if args.fan is not None:
set_fan_speed(args.fan)