update
This commit is contained in:
@@ -45,18 +45,31 @@ class RedfishClient:
|
||||
ip: str,
|
||||
username: str,
|
||||
password: str,
|
||||
timeout: int = 15,
|
||||
verify_ssl: bool = False
|
||||
timeout: Optional[int] = None,
|
||||
verify_ssl: Optional[bool] = None
|
||||
):
|
||||
self.ip = ip
|
||||
self.base_url = f"https://{ip}/redfish/v1"
|
||||
self.host_url = f"https://{ip}" # ← 추가: 호스트 URL
|
||||
self.timeout = timeout
|
||||
self.verify_ssl = verify_ssl
|
||||
self.host_url = f"https://{ip}"
|
||||
|
||||
# Config defaults
|
||||
default_timeout = 15
|
||||
default_verify = False
|
||||
|
||||
try:
|
||||
from flask import current_app
|
||||
if current_app:
|
||||
default_timeout = current_app.config.get("REDFISH_TIMEOUT", 15)
|
||||
default_verify = current_app.config.get("REDFISH_VERIFY_SSL", False)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
self.timeout = timeout if timeout is not None else default_timeout
|
||||
self.verify_ssl = verify_ssl if verify_ssl is not None else default_verify
|
||||
|
||||
self.session = requests.Session()
|
||||
self.session.auth = (username, password)
|
||||
self.session.verify = verify_ssl
|
||||
self.session.verify = self.verify_ssl
|
||||
self.session.headers.update({
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
@@ -214,11 +227,77 @@ class RedfishClient:
|
||||
"PercentComplete": str(percent),
|
||||
"Message": message_text,
|
||||
"ScheduledStartTime": job_data.get("ScheduledStartTime", ""),
|
||||
"StartTime": job_data.get("StartTime", ""),
|
||||
"EndTime": job_data.get("EndTime", ""),
|
||||
"LastUpdateTime": job_data.get("EndTime") or job_data.get("StartTime", ""),
|
||||
}
|
||||
|
||||
def export_system_configuration(self, share_parameters: Dict[str, Any], target: str = "ALL") -> str:
|
||||
"""
|
||||
시스템 설정 내보내기 (SCP Export)
|
||||
:param share_parameters: 네트워크 공유 설정 (IP, ShareName, FileName, UserName, Password 등)
|
||||
:param target: 내보낼 대상 (ALL, IDRAC, BIOS, NIC, RAID)
|
||||
:return: Job ID
|
||||
"""
|
||||
url = f"{self.host_url}/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/DellManager.ExportSystemConfiguration"
|
||||
|
||||
payload = {
|
||||
"ExportFormat": "XML",
|
||||
"ShareParameters": share_parameters,
|
||||
"Target": target
|
||||
}
|
||||
|
||||
logger.info(f"{self.ip}: Exporting system configuration to {share_parameters.get('FileName')}")
|
||||
response = self.session.post(url, json=payload, verify=False)
|
||||
response.raise_for_status()
|
||||
|
||||
# Job ID 추출 (Location 헤더 또는 응답 본문)
|
||||
job_id = ""
|
||||
if response.status_code == 202:
|
||||
location = response.headers.get("Location")
|
||||
if location:
|
||||
job_id = location.split("/")[-1]
|
||||
|
||||
if not job_id:
|
||||
# 응답 본문에서 시도 (일부 펌웨어 버전 대응)
|
||||
try:
|
||||
data = response.json()
|
||||
# 일반적인 JID 포맷 확인 필요
|
||||
# 여기서는 간단히 헤더 우선으로 처리하고 없으면 에러 처리하거나 데이터 파싱
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
return job_id
|
||||
|
||||
def import_system_configuration(self, share_parameters: Dict[str, Any], import_mode: str = "Replace", target: str = "ALL") -> str:
|
||||
"""
|
||||
시스템 설정 가져오기 (SCP Import)
|
||||
:param share_parameters: 네트워크 공유 설정
|
||||
:param import_mode: Replace, Append 등
|
||||
:param target: 가져올 대상
|
||||
:return: Job ID
|
||||
"""
|
||||
url = f"{self.host_url}/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/DellManager.ImportSystemConfiguration"
|
||||
|
||||
payload = {
|
||||
"ImportSystemConfigurationXMLFile": share_parameters.get("FileName"),
|
||||
"ShareParameters": share_parameters,
|
||||
"ImportMode": import_mode,
|
||||
"Target": target,
|
||||
"ShutdownType": "Graceful" # 적용 후 재부팅 방식
|
||||
}
|
||||
|
||||
logger.info(f"{self.ip}: Importing system configuration from {share_parameters.get('FileName')}")
|
||||
response = self.session.post(url, json=payload, verify=False)
|
||||
response.raise_for_status()
|
||||
|
||||
job_id = ""
|
||||
if response.status_code == 202:
|
||||
location = response.headers.get("Location")
|
||||
if location:
|
||||
job_id = location.split("/")[-1]
|
||||
|
||||
return job_id
|
||||
|
||||
def close(self):
|
||||
"""세션 종료"""
|
||||
self.session.close()
|
||||
|
||||
Reference in New Issue
Block a user