-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyvmomi_datastore.py
More file actions
59 lines (47 loc) · 1.7 KB
/
pyvmomi_datastore.py
File metadata and controls
59 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import ssl
# Disable SSL warnings for lab environments
context = ssl._create_unverified_context()
def sizeof_fmt(num, suffix="B"):
for unit in ['','K','M','G','T','P']:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
def get_datastore_health(datastore):
summary = datastore.summary
health = {
"Name": summary.name,
"Type": summary.type,
"Accessible": summary.accessible,
"Capacity": sizeof_fmt(summary.capacity),
"Free Space": sizeof_fmt(summary.freeSpace),
"Uncommitted": sizeof_fmt(summary.uncommitted) if summary.uncommitted else "N/A",
"Maintenance Mode": getattr(summary, 'maintenanceMode', "N/A"),
"Multiple Host Mount": getattr(summary, 'multipleHostAccess', "N/A"),
"Overall Status": getattr(datastore, 'overallStatus', "unknown")
}
# vSAN / heartbeat info if available
if hasattr(summary, 'redundancyStatus'):
health["vSAN Redundancy"] = summary.redundancyStatus
return health
def main():
si = SmartConnect(
host="vcenter.anthony.com",
user="administrator@vsphere.local",
pwd="VMware123!",
sslContext=context
)
content = si.RetrieveContent()
datastores = content.viewManager.CreateContainerView(
content.rootFolder, [vim.Datastore], True
).view
print("\n=== DATASTORE HEALTH REPORT ===\n")
for ds in datastores:
health = get_datastore_health(ds)
for key, val in health.items():
print(f"{key:20}: {val}")
print("-" * 60)
Disconnect(si)
if __name__ == "__main__":
main()