Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created June 29, 2010 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softlayer/457682 to your computer and use it in GitHub Desktop.
Save softlayer/457682 to your computer and use it in GitHub Desktop.
<?php
/**
* Edit a server's basic information
*
* Change the notes property for a single server record to the sentence "This
* is my fastest server!" using the editObject() method in the
* SoftLayer_Hardware_Server API service. See below for more details.
*
* This assumes the SoftLayer API PHP client
* <http://github.com/softlayer/softlayer-api-php-client> is installed in the
* directory '/SoftLayer' in this script's path and that you wish to use the
* SOAP client instead of our XML-RPC client.
*
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
* @license <http://sldn.softlayer.com/article/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
// Include XmlrpcClient.class.php if you'd like to use our XML-RPC client
// instead.
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');
/**
* Your SoftLayer API username and key.
*
* Generate an API key at the SoftLayer Customer Portal:
* https://manage.softlayer.com/Administrative/apiKeychain
*/
$apiUsername = 'set me!';
$apiKey = 'set me too!';
/**
* The id of the server we wish to edit.
*
* Call the getHardware() method from the SoftLayer_Hardware API service to get
* a list of hardware on your account, including id numbers.
*
* @var int
*/
$serverId = 1234;
/**
* Define the new local properties to set.
*
* A SoftLayer_Hardware_Server record has a few local properties that you can
* change via the API. Every service's editObject() method takes a single
* parameter, a skeleton object that only defines the properties we wish to
* change. While we're only editing a server's notes in this example you can
* also use editObject() to edit the server's hostname and domain record.
*
* PHP's built-in stdClass type is best for modeling your edit template.
*
* @var stdClass
*/
$editTemplate = new StdClass();
$editTemplate->notes = 'This is my fastest server!';
//$editTemplate->hostname = 'test';
//$editTemplate->domain = 'example.org';
// Make a connection to the SoftLayer_Hardware_Server service.
$client = Softlayer_SoapClient::getClient('SoftLayer_Hardware_Server', $serverId, $apiUsername, $apiKey);
try {
// Edit our server record.
$result = $client->editObject($editTemplate);
echo 'Server edited!';
} catch (Exception $e) {
die('Unable to edit hardware record: ' . $e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment