Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OSreload multiple servers by IP
<?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
You can’t perform that action at this time.