Skip to content

Instantly share code, notes, and snippets.

@underscorephil
Created September 4, 2013 14:14
Show Gist options
  • Save underscorephil/6437529 to your computer and use it in GitHub Desktop.
Save underscorephil/6437529 to your computer and use it in GitHub Desktop.
<?php
// Include SoftLayer Client
require_once './softlayer-api-php-client/SoftLayer/SoapClient.class.php';
// Define our vars
$apiUser = '';
$apiKey = '';
$serverId = 12345;
$newPassword = '1234abcd';
// Create the necessary SLAPI clients
$hardwareService = SoftLayer_SoapClient::getClient('SoftLayer_Hardware_Server', $serverId, $apiUser, $apiKey);
$passwordService = SoftLayer_SoapClient::getClient('SoftLayer_Software_Component_Password', Null, $apiUser, $apiKey);
// templateObject which only includes the id and changed property(notes)
$hardwareTemplate = new stdClass();
$hardwareTemplate->notes = "Testing Note";
$hardwareTemplate->id = $serverId;
// Edit the hardware object and store the result
$hardwareResult = $hardwareService->editObject($hardwareTemplate);
// Define object mask to retrieve the password object's id. We list id on each level to limit returned properties
$objectMask = <<<END
mask[
id,
operatingSystem[
id,
passwords[
id,
password
]
]
]
END;
// Set the mask and pull down the server info
$hardwareService->setObjectMask($objectMask);
$server = $hardwareService->getObject();
// Create templateObject for the password with only the id and changed properties(password)
$passwordTemplate = new stdClass();
$passwordTemplate->id = $server->operatingSystem->passwords[0]->id;
$passwordTemplate->password = $newPassword;
// Set the init parameter and edit the object, storing the results
$passwordService->setInitParameter($passwordTemplate->id);
$passwordResult = $passwordService->editObject($passwordTemplate);
print "Hardware Edit: $hardwareResult - Password Edit: $passwordResult\n\r";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment