update
This commit is contained in:
@@ -54,8 +54,16 @@ def save_ip_addresses(ips: str, folder: str | os.PathLike[str]) -> list[tuple[st
|
||||
# 개별 IP 처리
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
|
||||
def _build_command(script: str, ip_file: str, xml_file: str | None) -> list[str]:
|
||||
script_path = Path(Config.SCRIPT_FOLDER) / script
|
||||
def _build_command(script: str, ip_file: str, xml_file: str | None, profile_name: str | None = None) -> list[str]:
|
||||
# unified 스크립트는 data/scripts/unified 폴더에 있음
|
||||
# 기존 레거시 스크립트는 data/scripts 폴더에 있음
|
||||
# script 인자가 "unified/..." 로 시작하면 해당 경로 사용, 아니면 data/scripts 기준
|
||||
|
||||
if script.startswith("unified/"):
|
||||
script_path = Path(Config.SCRIPT_FOLDER) / script
|
||||
else:
|
||||
script_path = Path(Config.SCRIPT_FOLDER) / script
|
||||
|
||||
if not script_path.exists():
|
||||
raise FileNotFoundError(f"스크립트를 찾을 수 없습니다: {script_path}")
|
||||
|
||||
@@ -73,14 +81,23 @@ def _build_command(script: str, ip_file: str, xml_file: str | None) -> list[str]
|
||||
else:
|
||||
raise ValueError(f"지원되지 않는 스크립트 형식: {script_path.suffix}")
|
||||
|
||||
# 프로파일이 있으면 추가 (unified 스크립트용)
|
||||
if profile_name:
|
||||
cmd.append(profile_name)
|
||||
|
||||
if xml_file:
|
||||
cmd.append(xml_file)
|
||||
return cmd
|
||||
|
||||
|
||||
def process_ip(ip_file: str, script: str, xml_file: str | None = None) -> None:
|
||||
def process_ip(ip_file: str, script: str, xml_file: str | None = None, profile_name: str | None = None, slot_priority: str | None = None) -> None:
|
||||
ip = Path(ip_file).read_text(encoding="utf-8").strip()
|
||||
cmd = _build_command(script, ip_file, xml_file)
|
||||
cmd = _build_command(script, ip_file, xml_file, profile_name)
|
||||
|
||||
# 환경 변수 설정 (기존 환경 변수 복사 + 슬롯 우선순위 추가)
|
||||
env = os.environ.copy()
|
||||
if slot_priority:
|
||||
env["GUID_SLOT_PRIORITY"] = slot_priority
|
||||
|
||||
logging.info("🔧 실행 명령: %s", " ".join(cmd))
|
||||
try:
|
||||
@@ -91,6 +108,7 @@ def process_ip(ip_file: str, script: str, xml_file: str | None = None) -> None:
|
||||
check=True,
|
||||
cwd=str(Path(Config.SCRIPT_FOLDER)),
|
||||
timeout=int(os.getenv("SCRIPT_TIMEOUT", "1800")), # 30분 기본
|
||||
env=env,
|
||||
)
|
||||
logging.info("[%s] ✅ stdout:\n%s", ip, result.stdout)
|
||||
if result.stderr:
|
||||
@@ -105,14 +123,14 @@ def process_ip(ip_file: str, script: str, xml_file: str | None = None) -> None:
|
||||
# 병렬 처리 진입점
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
|
||||
def process_ips_concurrently(ip_files, job_id, observer: Observer, script: str, xml_file: str | None):
|
||||
def process_ips_concurrently(ip_files, job_id, observer: Observer, script: str, xml_file: str | None, profile_name: str | None = None, slot_priority: str | None = None):
|
||||
total = len(ip_files)
|
||||
completed = 0
|
||||
_set_progress(job_id, 0)
|
||||
|
||||
try:
|
||||
with ThreadPoolExecutor(max_workers=Config.MAX_WORKERS) as pool:
|
||||
futures = {pool.submit(process_ip, ip_path, script, xml_file): ip for ip, ip_path in ip_files}
|
||||
futures = {pool.submit(process_ip, ip_path, script, xml_file, profile_name, slot_priority): ip for ip, ip_path in ip_files}
|
||||
for fut in as_completed(futures):
|
||||
ip = futures[fut]
|
||||
try:
|
||||
@@ -135,7 +153,7 @@ def process_ips_concurrently(ip_files, job_id, observer: Observer, script: str,
|
||||
# 외부에서 한 번에 처리(동기)
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
|
||||
def handle_ip_processing(ip_text: str, script: str, xml_file: str | None = None) -> str:
|
||||
def handle_ip_processing(ip_text: str, script: str, xml_file: str | None = None, profile_name: str | None = None) -> str:
|
||||
job_id = str(uuid.uuid4())
|
||||
|
||||
temp_dir = Path(Config.UPLOAD_FOLDER) / job_id
|
||||
@@ -148,5 +166,5 @@ def handle_ip_processing(ip_text: str, script: str, xml_file: str | None = None)
|
||||
observer.schedule(handler, Config.IDRAC_INFO_FOLDER, recursive=False)
|
||||
observer.start()
|
||||
|
||||
process_ips_concurrently(ip_files, job_id, observer, script, xml_path)
|
||||
process_ips_concurrently(ip_files, job_id, observer, script, xml_path, profile_name, None)
|
||||
return job_id
|
||||
Reference in New Issue
Block a user