Created
May 25, 2012 19:03
-
-
Save softlayer/2789898 to your computer and use it in GitHub Desktop.
OSreload multiple servers by IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('SoftLayer/SoapClient.class.php'); | |
/** | |
* Set your SoftLayer API username and key. | |
*/ | |
$apiUsername = ''; | |
$apiKey = ''; | |
$hardwareClient = SoftLayer_SoapClient::getClient('SoftLayer_Hardware_Server', NULL, $apiUsername, $apiKey); | |
$ipsToReload = array('1.1.1.1', '2.2.2.2', '3.3.3.3'); | |
$serversToReload = array(); | |
$objectMask = new SoftLayer_ObjectMask(); | |
$objectMask->billingItem->package->items->prices; | |
$hardwareClient->setObjectMask($objectMask); | |
foreach ($ipsToReload as $key => $ipToReload) { | |
$server = $hardwareClient->findByIpaddress($ipToReload); | |
$serversToReload[$key]['id'] = $server->id; | |
foreach ($server->billingItem->package->items as $item) { | |
if ($item->description == 'CentOS 6.0 - Minimal Install (32 bit)') { | |
$serversToReload[$key]['priceId'] = $item->prices[0]->id; | |
break; | |
} else { | |
$serversToReload[$key]['priceId'] = 'None found'; | |
} | |
} | |
} | |
$failedReloads = array(); | |
foreach ($serversToReload as $soonToBeReloadedServer) { | |
if ($soonToBeReloadedServer['priceId'] != 'None found') { | |
$hardwareClient->setInitParameter($soonToBeReloadedServer['id']); | |
$config = new stdClass(); | |
$config->itemPrices = array(); | |
$config->itemPrices[] = (object)array('id' => $soonToBeReloadedServer['priceId']); | |
$hardwareClient->reloadOperatingSystem('FORCE', $config); | |
} else { | |
$failedReloads[] = $soonToBeReloadedServer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment