If you have python running you can use the script I wrote below to wake up and shutdown your ESXi server. I have a Dell R810 at home that I use as my Cisco VIRL Server and other things but i only power it up when I need it. It is downstairs so i wanted a way that i could start it and stop it from upstairs. I have enabled Wake On Lan on the primary NIC on the server (CTRL-S as it is booting and enable for your primary NIC). In vSphere set your VMs to start and stop with the server as this script will shutdown your VMs and power off the server. Enable ssh for your ESXi server, enter the MAC of the primary NIC, and change the root password, server ip, and path to python below.
python esxi.py -w Will Wake the server by sending the WOL magic packet.
python esxi.py -s will shutdown your VMs and power-off your server.
Dependencies
paramiko
wakeonlan
argparse
####################Start Script
#!/home/mikepartain/scripts/esxi/bin/python
from wakeonlan import wol
import time, argparse, paramiko
parser = argparse.ArgumentParser()
parser.add_argument('-w', action='store_true', dest='wakeup')
parser.add_argument('-s', action='store_true', dest='shutdown')
args = parser.parse_args()
if args.wakeup:
print 'Waking up ESXI Server'
wol.send_magic_packet('f0.4d.a2.aa.aa.aa')
if args.shutdown:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.178.10', username='root', password='#PASSWORD#')
stdin, stdout, stderr = ssh.exec_command('powerOffVms && halt')
print 'Shutting down ESXi Server'
ssh.close()
####################END Script
If this works for you, or if you have a way to improve it, please let me know!
Mike Partain