Add various scripts for server power management and build process
- Introduced .gitignore to exclude unnecessary files - Added scripts for powering on/off servers via IPMI and iLO - Implemented multi_powercycle script to manage multiple servers - Created build script for packaging multi_powercycle with PyInstaller - Enhanced logging functionality across scripts Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -5,6 +5,15 @@ import os
|
||||
import sys
|
||||
import urllib3
|
||||
import redfish
|
||||
from datetime import datetime
|
||||
|
||||
def log(message, is_error=False):
|
||||
"""Print message with timestamp"""
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
if is_error:
|
||||
print(f"[{timestamp}] {message}", file=sys.stderr)
|
||||
else:
|
||||
print(f"[{timestamp}] {message}")
|
||||
|
||||
# Suppress SSL warnings for self-signed iLO certificates
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
@@ -22,7 +31,7 @@ args = parser.parse_args()
|
||||
# password = yourpassword
|
||||
cred_path = args.credentials
|
||||
if not os.path.exists(cred_path):
|
||||
print(f"Error: credentials file not found: {cred_path}", file=sys.stderr)
|
||||
log(f"Error: credentials file not found: {cred_path}", is_error=True)
|
||||
sys.exit(1)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
@@ -31,7 +40,7 @@ try:
|
||||
LOGIN_ACCOUNT = config.get("ilo_credentials", "username", fallback="root")
|
||||
LOGIN_PASSWORD = config.get("ilo_credentials", "password")
|
||||
except (configparser.NoSectionError, configparser.NoOptionError) as e:
|
||||
print(f"Error reading credentials file: {e}", file=sys.stderr)
|
||||
log(f"Error reading credentials file: {e}", is_error=True)
|
||||
sys.exit(1)
|
||||
|
||||
BASE_URL = f"https://{args.hostname}"
|
||||
@@ -46,6 +55,6 @@ REDFISHOBJ.login(auth="session")
|
||||
sys_response = REDFISHOBJ.get("/redfish/v1/Systems/1/")
|
||||
power_state = sys_response.dict.get("PowerState", "Unknown")
|
||||
|
||||
print(f"Power State: {power_state}")
|
||||
log(f"Power State: {power_state}")
|
||||
|
||||
REDFISHOBJ.logout()
|
||||
|
||||
Reference in New Issue
Block a user