Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created May 19, 2010 23:49
Show Gist options
  • Save softlayer/407007 to your computer and use it in GitHub Desktop.
Save softlayer/407007 to your computer and use it in GitHub Desktop.
"""
Perform a server OS reload with custom partitions.
Reload a server with its current operating system, software, but with custom
drive partitions. SoftLayer's standard reloadOperatingSystem() method in the
SoftLayer_Hardware_Server API service
<http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/reloadOperatingSystem>
takes care of the heavy lifting after you've defined your new drive partitions.
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
"""
Define new partitions.
Partitions and other custom reload options exist in a
SoftLayer_Container_Hardware_Server_Configuration object
<http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Hardware_Server_Configuration>.
The hardDrives property in your configuration object models your drive's
partitions. Each partition must have at least its name and minimumSize defined.
Name defines your partition's mount point, and minimumSize specifies its size
in gigabytes.
UNIX partition schemes must have at least one swap partition, defined by the
partition name /swap0. Set the partition's grow property to 1 to indicate that
partition should expand to fill the remainder of the disk. You must have one
grow partition in your partition scheme.
Windows partitioning is a little simpler. Specify the C: partition with the
name /os, with drives letters D:, E:, F:, etc as /disk0, /disk1, /disk2, and
so on.
This example sets up the following partition scheme:
* swap: 1G
* /boot: 100M
* /test: 15G
* /: grown to fill disk space
Specify the complex type of the hard drive object as a
SoftLayer_Hardware_Component_HardDrive type so the SoftLayer API will know to
look for partitioning information.
"""
configuration = {
'hardDrives' : [
{
'complexType' : 'SoftLayer_Hardware_Component_HardDrive',
'partitions': [
{
'name' : '/swap0',
'minimumSize' : '1',
},
{
'name' : '/boot',
'minimumSize' : '.1',
},
{
'name' : '/test',
'minimumSize' : '15',
},
{
'name' : '/',
'minimumSize' : '1',
'grow' : '1',
},
]
}
]
}
# 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 reloadOperatingSystem(). 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.reloadOperatingSystem('FORCE', configuration)
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