Initial commit
This commit is contained in:
54
data/scripts/04-tsr_save.py
Normal file
54
data/scripts/04-tsr_save.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
import subprocess
|
||||
from dotenv import load_dotenv
|
||||
import sys
|
||||
from multiprocessing import Pool
|
||||
|
||||
# 환경 변수 로드
|
||||
load_dotenv() # .env 파일에서 환경 변수 로드
|
||||
|
||||
# 사용자 이름 및 비밀번호 설정
|
||||
IDRAC_USER = os.getenv("IDRAC_USER")
|
||||
IDRAC_PASS = os.getenv("IDRAC_PASS")
|
||||
OME_USER = os.getenv("OME_USER")
|
||||
OME_PASS = os.getenv("OME_PASS")
|
||||
|
||||
# IP 주소 파일 로드 및 유효성 검사
|
||||
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.")
|
||||
with open(ip_file_path, "r") as file:
|
||||
return [line.strip() for line in file if line.strip()]
|
||||
|
||||
# iDRAC 정보를 가져오는 함수
|
||||
def fetch_idrac_info(idrac_ip):
|
||||
print(f"Collecting TSR report for iDRAC IP: {idrac_ip}")
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
"racadm", "-r", idrac_ip, "-u", IDRAC_USER, "-p", IDRAC_PASS,
|
||||
"techsupreport", "export", "-l", "//10.10.3.251/share/", "-u", OME_USER, "-p", OME_PASS
|
||||
],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
print(
|
||||
f"Successfully collected TSR report for {idrac_ip}"
|
||||
if result.returncode == 0
|
||||
else f"Failed to collect TSR report for {idrac_ip}: {result.stderr.strip()}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Exception occurred for {idrac_ip}: {e}")
|
||||
|
||||
# 메인 함수
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit("Usage: python script.py <ip_file>")
|
||||
|
||||
ip_list = load_ip_file(sys.argv[1])
|
||||
|
||||
# 병렬로 iDRAC 정보를 가져오는 작업 수행
|
||||
with Pool() as pool:
|
||||
pool.map(fetch_idrac_info, ip_list)
|
||||
|
||||
print("설정 완료.")
|
||||
Reference in New Issue
Block a user