Skip to content

Instantly share code, notes, and snippets.

@emaadmanzoor
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emaadmanzoor/6db702d1aae02c7f906e to your computer and use it in GitHub Desktop.
Save emaadmanzoor/6db702d1aae02c7f906e to your computer and use it in GitHub Desktop.
from optparse import OptionParser
from pyipmi import make_bmc
from pyipmi.bmc import LanBMC
from pyipmi.server import Server
"""
A simple script to power on/off a server using IPMI.
This uses pyipmi version 0.11.0.
Here is the help on this command line utility:
python power-ipmi.py -h
Usage: power-ipmi.py [options]
Options:
-h, --help show this help message and exit
-H HOST, --host=HOST IP address of the BMC server
-u USERNAME, --username=USERNAME
username
-p PASSWORD, --password=PASSWORD
password
-m MODE, --mode=MODE power mode: on/off
"""
parser = OptionParser()
parser.add_option( "-H", "--host", dest="host", type=str, default="1.1.1.1",
help="IP address of the BMC server" )
parser.add_option( "-u", "--username", type=str, dest="username", default="default",
help="username" )
parser.add_option( "-p", "--password", type=str, dest="password", default="password",
help="password" )
parser.add_option( "-m", "--mode", type=str, dest="mode", default="on",
help="power mode: on/off" )
( args, op ) = parser.parse_args()
bmc = make_bmc( LanBMC, hostname=args.host, username=args.username, password=args.password )
server = Server( bmc )
if args.mode == "on":
print "Powering on the server."
server.power_on()
sleep(10)
else:
print "Powering off the server."
server.power_off()
print "The server is in state: %s" % server.is_powered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment