Update 2025-12-19 20:23:59
This commit is contained in:
@@ -4,6 +4,14 @@ import time
|
||||
from dotenv import load_dotenv
|
||||
import sys
|
||||
from multiprocessing import Pool
|
||||
import logging
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s [INFO] root: %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv() # Load variables from .env file
|
||||
@@ -14,26 +22,27 @@ IDRAC_USER, IDRAC_PASS = os.getenv("IDRAC_USER"), os.getenv("IDRAC_PASS")
|
||||
# Load IP addresses from file
|
||||
def load_ip_file(ip_file_path):
|
||||
if not os.path.isfile(ip_file_path):
|
||||
sys.exit(f"IP file {ip_file_path} does not exist.")
|
||||
logging.error(f"IP file {ip_file_path} does not exist.")
|
||||
sys.exit(1)
|
||||
with open(ip_file_path, "r") as file:
|
||||
return [line.strip() for line in file if line.strip()]
|
||||
|
||||
# Delete all jobs for given iDRAC IP
|
||||
def delete_all_jobs(idrac_ip):
|
||||
print(f"Deleting all jobs for iDRAC IP: {idrac_ip}")
|
||||
logging.info(f"Deleting all jobs for iDRAC IP: {idrac_ip}")
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["racadm", "-r", idrac_ip, "-u", IDRAC_USER, "-p", IDRAC_PASS, "jobqueue", "delete", "-i", "ALL"],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
print(
|
||||
f"Successfully deleted all jobs for {idrac_ip}"
|
||||
if result.returncode == 0
|
||||
else f"Failed to delete jobs for {idrac_ip}: {result.stderr.strip()}"
|
||||
)
|
||||
if result.returncode == 0:
|
||||
logging.info(f"Successfully deleted all jobs for {idrac_ip}")
|
||||
else:
|
||||
logging.error(f"Failed to delete jobs for {idrac_ip}: {result.stderr.strip()}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Exception occurred for {idrac_ip}: {e}")
|
||||
logging.error(f"Exception occurred for {idrac_ip}: {e}")
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
@@ -48,4 +57,4 @@ if __name__ == "__main__":
|
||||
pool.map(delete_all_jobs, ip_list)
|
||||
|
||||
elapsed_time = time.time() - start_time
|
||||
print(f"Job delete 완료. 완료 시간: {int(elapsed_time // 3600)} 시간, {int((elapsed_time % 3600) // 60)} 분, {int(elapsed_time % 60)} 초.")
|
||||
logging.info(f"Job delete 완료. 완료 시간: {int(elapsed_time // 3600)} 시간, {int((elapsed_time % 3600) // 60)} 분, {int(elapsed_time % 60)} 초.")
|
||||
Reference in New Issue
Block a user