接近完善的代码,待生产环境测试。
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
# 管理节点配置(包含vCenter和ESXi)
|
||||
management_nodes:
|
||||
# vCenter节点
|
||||
- type: vcenter # 标记类型为vcenter
|
||||
name: vc1 # 节点名称(用于日志)
|
||||
host: 192.168.40.134 # 地址
|
||||
user: administrator@lan.com
|
||||
password: Root@2025
|
||||
max_delete_concurrent: 4 # 该节点最大并发删除数
|
||||
# - type: vcenter # 标记类型为vcenter
|
||||
# name: vc1 # 节点名称(用于日志)
|
||||
# host: 192.168.40.134 # 地址
|
||||
# user: administrator@lan.com
|
||||
# password: Root@2025
|
||||
# max_delete_concurrent: 4 # 该节点最大并发删除数
|
||||
|
||||
# ESXi节点(未接入 vCenter 的 Esxi 主机)
|
||||
# - type: esxi # 标记类型为esxi
|
||||
# name: esxi1
|
||||
# host: 192.168.40.133
|
||||
# user: root # ESXi默认用root
|
||||
# password: Root@2025
|
||||
# max_delete_concurrent: 2 # ESXi性能较弱,并发数可设小些
|
||||
- type: esxi # 标记类型为esxi
|
||||
name: esxi1
|
||||
host: 192.168.40.133
|
||||
user: root # ESXi默认用root
|
||||
password: Root@2025
|
||||
max_delete_concurrent: 2 # ESXi性能较弱,并发数可设小些
|
||||
|
||||
# - type: esxi
|
||||
# name: esxi2
|
||||
# host: 192.168.40.135
|
||||
# user: root
|
||||
# password: Root@2025
|
||||
# max_delete_concurrent: 2
|
||||
- type: esxi
|
||||
name: esxi2
|
||||
host: 192.168.40.135
|
||||
user: root
|
||||
password: Root@2025
|
||||
max_delete_concurrent: 2
|
||||
|
||||
# 全局策略配置
|
||||
global:
|
||||
snapshot_retention_days: 0 # 可选,使用默认值 15 天
|
||||
# excel_output_path: ./vm_snapshots_report.xlsx # 可选,使用默认值,如:/logs/2026-02-20_14-00-21-VMsSnapShots_report.xlsx
|
||||
# 'excel_output_path',: ./vm_snapshots_report.xlsx # 可选,使用默认值,如:/logs/2026-02-20_14-00-21-VMsSnapShots_report.xlsx
|
||||
# ESXi连接特殊配置(禁用SSL验证,ESXi默认自签证书)
|
||||
disable_ssl_verify: true
|
||||
disable_ssl_verify: true
|
||||
snapshot_retention_days: 15 # 可选,默认值 15 天
|
||||
# excel_output_path: ./vm_snapshots_report.xlsx # 可选,使用默认值,如:/logs/2026-02-20_14-00-21-VMsSnapShots_report.xlsx
|
||||
# 'excel_output_path',: ./vm_snapshots_report.xlsx # 可选,使用默认值,如:/logs/2026-02-20_14-00-21-VMsSnapShots_report.xlsx
|
||||
# ESXi连接特殊配置(禁用SSL验证,ESXi默认自签证书)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import yaml
|
||||
import os
|
||||
import yaml, os
|
||||
from datetime import datetime
|
||||
from utils.logger import logger
|
||||
|
||||
|
||||
def load_config():
|
||||
"""加载 YAML 配置文件并解析其内容"""
|
||||
try:
|
||||
@@ -17,10 +17,9 @@ def load_config():
|
||||
"SNAPSHOT_RETENTION_DAYS": int(global_config.get('snapshot_retention_days', 15)),
|
||||
# "EXCEL_OUTPUT_PATH": global_config.get('excel_output_path', f'/logs/{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}-VMsSnapShots_report.xlsx'),
|
||||
# "LOG_FILE_PATH": global_config.get('log_file_path', f'/logs/{datetime.now().strftime('%Y%m%d_%H%M%S')}-VMsSnapShots_cleanup.logs'), "EXCEL_OUTPUT_PATH": global_config.get('excel_output_path', f'/logs/{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}-VMsSnapShots_report.xlsx'),
|
||||
"EXCEL_OUTPUT_PATH": global_config.get('excel_output_path', f'D:\\PycharmProjects\\RemoveWeeklyShapshot\\output\\{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}-VMsSnapShots_report.xlsx'),
|
||||
"YAML_OUTPUT_PATH": global_config.get('yaml_output_path', f'D:\\PycharmProjects\\RemoveWeeklyShapshot\\output\\{datetime.now().strftime('%Y-%m-%d')}-old_snapshots.yaml'),
|
||||
"EXCEL_OUTPUT_PATH": global_config.get('excel_output_path', f'D:\\PycharmProjects\\RemoveWeeklySnapshot\\output\\vm_snapshots_report-{datetime.now().strftime('%Y-%m-%d')}.xlsx'),
|
||||
"YAML_OUTPUT_PATH": global_config.get('yaml_output_path', f'D:\\PycharmProjects\\RemoveWeeklySnapshot\\output\\old_snapshots-{datetime.now().strftime('%Y-%m-%d')}.yaml'),
|
||||
"DISABLE_SSL_VERIFY": global_config.get('disable_ssl_verify', True),
|
||||
# 算出的过期时间点
|
||||
}
|
||||
|
||||
# 验证配置
|
||||
@@ -54,10 +53,6 @@ YAML_OUTPUT_PATH = config["YAML_OUTPUT_PATH"]
|
||||
#LOG_FILE_PATH = config["LOG_FILE_PATH"]
|
||||
DISABLE_SSL_VERIFY = config["DISABLE_SSL_VERIFY"]
|
||||
|
||||
# 验证配置函数
|
||||
def validate_config():
|
||||
pass # 加载时已验证,此处留空
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 打印全局配置
|
||||
|
||||
Reference in New Issue
Block a user