Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created May 19, 2010 21:24
Show Gist options
  • Save softlayer/406851 to your computer and use it in GitHub Desktop.
Save softlayer/406851 to your computer and use it in GitHub Desktop.
"""
Perform a simple server OS reload.
Reload a server with its current operating system, software, and drive
partitions. SoftLayer provides a single method to perform a simple OS
reload. See the manual page for the reloadCurrentOperatingSystemConfiguration()
method in the SoftLayer_Hardware_Server API service
<http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/reloadCurrentOperatingSystemConfiguration>
for more information. Please perform server backups as necessary before
reloading your operating system.
This script is written for Python 2.x and assumes the SoftLayer API Python
client <http://github.com/softlayer/softlayer-api-python-client> is installed.
If you're using Python 3.x then adjust print() and exception catching syntax
accordingly.
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
License: http://sldn.softlayer.com/article/License
"""
# So we can talk to the SoftLayer API:
import SoftLayer.API
# Grab these from the SoftLayer portal.
username = "set me!"
apiKey = "set me too!"
# The id of the server we wish to reload. Call the getHardware() method from
# the SoftLayer_Hardware API service to get a list of hardware on your
# account, including id numbers.
serverId = 1234
# Create a connection to the SoftLayer_Hardware_Server API service.
client = SoftLayer.API.Client('SoftLayer_Hardware_Server', serverId, username, apiKey)
# Perform the OS reload. Normally the OS reload method retuns a confirmation
# token, which you pass to a second call to
# reloadCurrentOperatingSystemConfiguration(). Passing the parameter 'FORCE'
# ignores the confirmation key step and bypasses the need to make two API
# calls.
#
# An OS reload may take between 30 and 60 minutes depending on the software
# installed.
try:
result = client.reloadCurrentOperatingSystemConfiguration('FORCE')
print "OS reload started!"
except Exception, e:
print "Unable to reload server. ", e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment