forked from lamw/vmware-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure_esxi_power_policy.py
executable file
·42 lines (37 loc) · 1.47 KB
/
configure_esxi_power_policy.py
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
#!/usr/bin/python
# Author: Alan Castonguay (contributed)
# Website: N/A
# Product: VMware ESXi
# Description: Python script to configure power management policy on ESXi host
# Reference: http://www.virtuallyghetto.com/2012/08/configuring-esxi-power-management.html
import sys
from pyVim.connect import Connect
def main(argv):
si = Connect()
content = si.RetrieveContent()
rootFolder = content.GetRootFolder()
dataCenter = rootFolder.GetChildEntity()[0]
hostFolder = dataCenter.hostFolder
host = hostFolder.childEntity[0]
hostSystem = host.host[0]
configManager = hostSystem.GetConfigManager()
powerSystem = configManager.GetPowerSystem()
hostConfigInfo = hostSystem.config
if len(argv)>0:
for policy in hostConfigInfo.powerSystemCapability.availablePolicy:
if policy.shortName == argv[0]:
r=powerSystem.ConfigurePowerPolicy(policy.key)
if r == None:
return 0
print r
return 1
print 'Policy shortName "{0}" not found.'.format(argv[0])
return 1
else:
print "{0:4} {1:10} {2:10} {3}".format("key", "current", "shortName","name")
for policy in hostConfigInfo.powerSystemCapability.availablePolicy:
print "{0!s:4} {1!r:10} {2:10} {3}".format(policy.key, policy.name == hostConfigInfo.powerSystemInfo.currentPolicy.name, policy.shortName, policy.name)
return 0
# Start program
if __name__ == "__main__":
exit(main(sys.argv[1:]))