forked from lamw/vmware-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvsan-smarts-data-sample.py
More file actions
executable file
·128 lines (104 loc) · 4.15 KB
/
vsan-smarts-data-sample.py
File metadata and controls
executable file
·128 lines (104 loc) · 4.15 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
VSAN 6.6 Management SDK sample exercising retrieving
SMARTS data from vSAN
Usage:
python vsan-smarts-data-sample.py -s 192.168.1.100 \
-u 'administrator@vsphere.local' -p 'VMware1!' \
-c VSAN-Cluster
"""
__author__ = 'VMware, Inc'
from prettytable import PrettyTable
from pyVmomi import vim
from pyVim.connect import SmartConnect, Disconnect
import sys
import ssl
import atexit
import argparse
import getpass
# import the VSAN API python bindings
import vsanmgmtObjects
import vsanapiutils
def GetArgs():
"""
Supports the command-line arguments listed below.
"""
parser = argparse.ArgumentParser(
description='Process args for VSAN SDK sample application')
parser.add_argument('-s', '--host', required=True, action='store',
help='Remote host to connect to')
parser.add_argument('-o', '--port', type=int, default=443, action='store',
help='Port to connect on')
parser.add_argument('-u', '--user', required=True, action='store',
help='User name to use when connecting to host')
parser.add_argument('-p', '--password', required=False, action='store',
help='Password to use when connecting to host')
parser.add_argument('-c', '--cluster', dest='clusterName', required=True,
action='store')
args = parser.parse_args()
return args
def getClusterInstance(clusterName, serviceInstance):
content = serviceInstance.RetrieveContent()
searchIndex = content.searchIndex
datacenters = content.rootFolder.childEntity
for datacenter in datacenters:
cluster = searchIndex.FindChild(datacenter.hostFolder, clusterName)
if cluster is not None:
return cluster
return None
# Start program
def main():
args = GetArgs()
if args.password:
password = args.password
else:
password = getpass.getpass(prompt='Enter password for host %s and '
'user %s: ' % (args.host, args.user))
# For python 2.7.9 and later, the defaul SSL conext has more strict
# connection handshaking rule. We may need turn of the hostname checking
# and client side cert verification
context = None
if sys.version_info[:3] > (2, 7, 8):
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
si = SmartConnect(host=args.host,
user=args.user,
pwd=password,
port=int(args.port),
sslContext=context)
atexit.register(Disconnect, si)
# for detecting whether the host is VC or ESXi
aboutInfo = si.content.about
if aboutInfo.apiType == 'VirtualCenter':
majorApiVersion = aboutInfo.apiVersion.split('.')[0]
if int(majorApiVersion) < 6:
print('The Virtual Center with version %s (lower than 6.0) \
is not supported.' % aboutInfo.apiVersion)
return -1
vcMos = vsanapiutils.GetVsanVcMos(si._stub, context=context)
vchs = vcMos['vsan-cluster-health-system']
cluster = getClusterInstance(args.clusterName, si)
if cluster is None:
print("Cluster %s is not found for %s" % (args.clusterName,
args.host))
return -1
smartsData = vchs.VsanQueryVcClusterSmartStatsSummary(cluster=cluster)
for data in smartsData:
print("ESXi Host: %s" % data.hostname)
for smartStat in data.smartStats:
print("\nDisk: %s" % smartStat.disk)
diskTable = PrettyTable(['Parameter', 'Value',
'Threshold', 'Worst'])
diskTable.align = "l"
stats = smartStat.stats
for stat in stats:
diskTable.add_row([stat.parameter,
stat.value,
stat.threshold,
stat.worst])
print(diskTable)
# Start program
if __name__ == "__main__":
main()