shit works now
This commit is contained in:
parent
b49b9aa6f0
commit
64162106ff
1 changed files with 13 additions and 21 deletions
34
server.py
34
server.py
|
@ -4,15 +4,14 @@ import subprocess
|
||||||
# Server IPMI details
|
# Server IPMI details
|
||||||
IPMIHOST = "192.168.1.223"
|
IPMIHOST = "192.168.1.223"
|
||||||
IPMIUSER = "root"
|
IPMIUSER = "root"
|
||||||
IPMIPASS = "fuck pizza hut"
|
IPMIPASS = "<password>"
|
||||||
|
|
||||||
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
|
result = subprocess.run(full_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
result = subprocess.run(full_command, shell=True, capture_output=True, text=True)
|
print(result.stdout.decode().strip())
|
||||||
print(result.stdout)
|
|
||||||
if result.stderr:
|
if result.stderr:
|
||||||
print(result.stderr)
|
print(result.stderr.decode().strip())
|
||||||
|
|
||||||
def power_on():
|
def power_on():
|
||||||
print("Powering on the server...")
|
print("Powering on the server...")
|
||||||
|
@ -24,8 +23,7 @@ def 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.
|
fan_speed_value = int((speed * 255) / 100)
|
||||||
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 enable_dynamic_fan_control():
|
def enable_dynamic_fan_control():
|
||||||
|
@ -39,32 +37,26 @@ def disable_dynamic_fan_control():
|
||||||
# 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', choices=['on', 'off'], 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()
|
||||||
|
|
||||||
|
# Check for no action
|
||||||
|
if not any([args.power, args.fan, args.dynamic]):
|
||||||
|
parser.print_help()
|
||||||
|
exit()
|
||||||
|
|
||||||
# Execute based on arguments
|
# Execute based on arguments
|
||||||
if args.power == 'on':
|
if args.power == 'on':
|
||||||
power_on()
|
power_on()
|
||||||
elif args.power == 'off':
|
elif args.power == 'off':
|
||||||
power_off()
|
power_off()
|
||||||
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 == 'on':
|
if args.dynamic == 'on':
|
||||||
enable_dynamic_fan_control()
|
enable_dynamic_fan_control()
|
||||||
elif args.dynamic == 'off':
|
elif args.dynamic == 'off':
|
||||||
disable_dynamic_fan_control()
|
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)
|
|
Loading…
Reference in a new issue