Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created June 17, 2010 18:11
Show Gist options
  • Save softlayer/442493 to your computer and use it in GitHub Desktop.
Save softlayer/442493 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# 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 Perl client
# <http://github.com/softlayer/softlayer-api-perl-client>.
#
# License: <http://sldn.softlayer.com/article/License>
# Author: SoftLayer Technologies, Inc. <[email protected]>
# Set this to the path of the SoftLayer API Perl client.
use lib '/path/to/client/';
use SoftLayer::API::SOAP;
use strict;
# Generate an API key in the SoftLayer customer portal.
my $username = 'set me!';
my $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.
my $serverId = 1234;
# Declare a new API service object for the SoftLayer_Hardware_Server API
# service.
my $client = SoftLayer::API::SOAP->new('SoftLayer_Hardware_Server', $serverId, $apiUsername, $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.
my $result = $client->rebootDefault();
# If there was an error returned from the SoftLayer API then die out with the
# error message.
if ($result->fault) {
die "Unable to reboot server. " . $result->faultstring;
}
print "Server rebooted!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment