Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created June 17, 2010 18:03
Show Gist options
  • Save softlayer/442482 to your computer and use it in GitHub Desktop.
Save softlayer/442482 to your computer and use it in GitHub Desktop.
"""
Reboot a SoftLayer server
Given a server id call the rebootDefault() method in the
SoftLayer_Hardware_Server service to attempt to reboot the server via IPMI or
its power strip if remote management is unavailable. See
<http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/rebootDefault>
for more information.
This script assumes you're using the SoftLayer API Python client
<http://github.com/softlayer/softlayer-api-python-client>. It's been written
Python 2.x. If you're using Python 3 then please adjust print() usage and
exception handling accordingly.
License: <http://sldn.softlayer.com/article/License>
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
# So we can talk to the SoftLayer API:
import SoftLayer.API
# Generate an API key in the SoftLayer customer portal.
username = 'set me!'
apiKey = 'set me too!'
# If you don't know your server id you can call getHardware() in the
# SoftLayer_Account API service to get a list of hardware or call
# findByIpAddress() in the SoftLayer_Hardware_Server service if you already
# know your server's primary IP address.
serverId = 1234
# Create a connection to the SoftLayer_Hardware_Server API service.
client = SoftLayer.API.Client('SoftLayer_Hardware_Server', serverId, username, apiKey)
# There are three other reboot methods you can call instead of rebootDefault().
# rebootSoft() attempts a soft IPMI server reboot, akin to the ctrl-alt-del
# sequence. rebootHard() performs a hard IPMI server boot, similar to hitting
# the server's reset button. powerCycle() physically flips power to the server
# via its power strip, and should only be used as a last resort.
# rebootDefault() is a great compromise amongst the server reboot options.
try:
client.rebootDefault()
print "Server rebooted!"
except Exception, e:
print "Unable to reboot server. ", e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment