Files
RemoveWeeklyShapshot/README.md
2026-02-19 15:35:27 +08:00

70 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RemoveWeeklySnapshot
> 以下需求需要每周执行一次
- [x] 连接vCenter/Esxi/Hyper-V
- [x] 获取所有 vms
- [x] 获取所有 snapshots
- [x] 筛选出15天半个月前的snapshots
- [x] 以上内容以Excel表格的形式导出超出15天的快照蓝底标识
- [ ] 最后删除 15 天前的 snapshot并同时记录删除的 snapshot 日志信息
- [ ] 需要控制每台 vCenter 不可以同时删除超过4个快照
- [ ] 增加排除不能删除的快照
| 你想获取 | 代码 | 示例输出 |
| ------------ | ----------------------------------- | ---------------------------------------------- |
| **名称** | `vm.name` | `"WebServer-01"` |
| **MOID** | `vm._moId` | `"vm-12"` |
| **电源状态** | `vm.runtime.powerState` | `poweredOn` / `poweredOff` |
| **开机时间** | `vm.runtime.bootTime` | `datetime` 对象 |
| **CPU数** | `vm.config.hardware.numCPU` | `4` |
| **内存(MB)** | `vm.config.hardware.memoryMB` | `8192` |
| **操作系统** | `vm.config.guestFullName` | `"CentOS 7 (64-bit)"` |
| **IP地址** | `vm.guest.ipAddress` | `"192.168.1.100"` |
| **主机名** | `vm.guest.hostName` | `"webserver01.local"` |
| **存储路径** | `vm.config.files.vmPathName` | `"[Datastore1] WebServer-01/WebServer-01.vmx"` |
| **快照数量** | `len(vm.snapshot.rootSnapshotList)` | `3` |
>vm
>├── 基础标识
>│ ├── name VM名称
>│ └── _moId 内部ID (vm-12)
>│
>├── runtime 【运行状态】
>│ ├── powerState poweredOn/Off/Suspended
>│ ├── bootTime 开机时间
>│ └── host 所在物理机
>│
>├── config 【硬件配置】
>│ ├── hardware CPU/内存/硬盘
>│ ├── guestFullName 操作系统
>│ └── files VMX文件路径
>│
>├── guest 【客户机内部信息】
>│ ├── hostName 主机名
>│ ├── ipAddress IP地址
>│ └── toolsStatus VMware Tools状态
>│
>├── snapshot 【快照】
>│ └── rootSnapshotList 快照树
>│
>├── storage 【存储】
>│ └── perDatastoreUsage 各数据存储用量
>│
>├── network 【网络】
>│ └── [Network] 连接的端口组
>│
>└── summary 【快速汇总】
>├── overallStatus 整体健康状态
>└── quickStats 实时性能数据
[{'name': 'snap-02', 'description': 'test-Ansible snapshot', 'createTime': '2026-02-17 08:57:39', 'state': 'poweredOff', 'id': 2, 'moId': 'snapshot-27', 'sizeMB': None, 'quiesced': False, 'children': []}]
[{'name': 'snap-01', 'description': 'Ansible snapshot', 'createTime': '2026-02-17 03:26:08', 'state': 'poweredOff', 'id': 1, 'moId': 'snapshot-26', 'sizeMB': None, 'quiesced': False, 'children': [{'name': 'snap-02', 'description': 'test-Ansible snapshot', 'createTime': '2026-02-17 08:57:39', 'state': 'poweredOff', 'id': 2, 'moId': 'snapshot-27', 'sizeMB': None, 'quiesced': False, 'children': []}]}]
获取到 2 台VM