Created
May 14, 2010 21:49
-
-
Save softlayer/401715 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Order a new server. | |
* | |
* Build a SoftLayer_Container_Product_Order_Hardware_Server object for a new | |
* server order and pass it to the SoftLayer_Product_Order API service to order | |
* it. In this care we'll order a Xeon 3060 server with 2G RAM, 100mbit NICs, | |
* 2000GB bandwidth, a 250G SATA drive, CentOS 5 64-bit, and default server | |
* order options. 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. | |
* | |
* Important manual pages: | |
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Hardware_Server | |
* http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server | |
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Item_Price | |
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder | |
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder | |
* | |
* @license <http://sldn.softlayer.com/article/License> | |
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com> | |
*/ | |
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php'); | |
/** | |
* Your SoftLayer API username. | |
* | |
* @var string | |
*/ | |
$username = 'set me'; | |
/** | |
* Your SoftLayer API key. | |
* | |
* Generate one at https://manage.softlayer.com/Administrative/apiKeychain | |
* | |
* @var string | |
*/ | |
$key = 'set me too!'; | |
/** | |
* The number of servers you wish to order in this configuration. | |
* | |
* @var int; | |
*/ | |
$quantity = 1; | |
/** | |
* The hostname of the server you wish to order. | |
* | |
* @var string | |
*/ | |
$hostname = 'test'; | |
/** | |
* The domain name of the server you wish to order. | |
* | |
* @var string | |
*/ | |
$domain = 'example.org'; | |
/** | |
* The id of the SoftLayer_Product_Package you wish to order. | |
* | |
* In this case the Xeon 3060's package id is 23. | |
* | |
* @var int | |
*/ | |
$packageId = 23; | |
/** | |
* The id's of the items you wish to order in your server. | |
* | |
* Every item in SoftLayer's product catalog is assigned an id. Use these ids | |
* to tell the SoftLayer API which options you want in your new server. Use | |
* the getActivePackages() method in the SoftLayer_Account API service to get | |
* a list of available item and price options per available package. | |
* | |
* @var array | |
*/ | |
$prices = array | |
( | |
670, // Intel Xeon 3060 CPU | |
156, // 2GB DDR2 667 RAM | |
906, // Reboot/KVM over IP remote management | |
273, // 100mbit public and private network connections | |
21, // One primary IP address | |
22, // Four public IP address | |
1481, // One /64 IPv6 address block | |
34, // 2000GB bandwidth | |
876, // Standard, non-RAID disk controller | |
19, // 250G SATA-II Hard Drive | |
51, // 1GB Lockbox NAS | |
683, // CentOS 5 64-bit | |
55, // Host ping monitoring | |
57, // Email and ticket monitoring notification | |
58, // Automated notification response | |
418, // Vulnerability scanner | |
420, // Unlimited SSL VPN users and 1 PPTP VPN user | |
); | |
/** | |
* Where you'd like your new server provisioned. | |
* | |
* This can either be the id of the datacenter you wish your new server to be | |
* provisioned in or the string 'FIRST_AVAILABLE' if you have no preference | |
* where your server is provisioned. | |
* | |
* Location id 3 = Dallas | |
* Location id 18171 = Seattle | |
* Location id 37473 = Washington, D.C. | |
* | |
* @var mixed | |
*/ | |
$location = 'FIRST_AVAILABLE'; | |
// Convert our item list into an array of skeleton | |
// SoftLayer_Product_Item_Price objects. These objects contain much more than | |
// ids, but SoftLayer's ordering system only needs the price's id to know what | |
// you want to order. | |
$orderPrices = array(); | |
foreach ($prices as $priceId){ | |
$price = new stdClass(); | |
$price->id = $priceId; | |
$orderPrices[] = $price; | |
} | |
// Build a skeleton SoftLayer_Hardware_Server object to model the hostname and | |
// domain we want for our server. If you set $quantity greater then 1 then you | |
// need to define one hostname/domain pair per server you wish to order. | |
$hardware = new stdClass(); | |
$hardware->hostname = $hostname; | |
$hardware->domain = $domain; | |
$orderHardware = array | |
( | |
$hardware, | |
); | |
// Build a SoftLayer_Container_Product_Order_Hardware_Server object containing | |
// the order you wish to place. | |
$orderTemplate = new stdClass(); | |
$orderTemplate->location = $location; | |
$orderTemplate->packageId = $packageId; | |
$orderTemplate->prices = $orderPrices; | |
$orderTemplate->quantity = $quantity; | |
$orderTemplate->hardware = $orderHardware; | |
// Create a SoftLayer API client object to the SoftLayer_Product_Order service. | |
$client = SoftLayer_SoapClient::getClient | |
( | |
'SoftLayer_Product_Order', | |
null, | |
$username, | |
$key | |
); | |
// Place the order for the new server. | |
try { | |
// Re-declare the order template as a SOAP variable, so the SoftLayer | |
// ordering system knows what type of order you're placing. | |
$orderTemplate = new SoapVar | |
( | |
$orderTemplate, | |
SOAP_ENC_OBJECT, | |
'SoftLayer_Container_Product_Order_Hardware_Server', | |
'http://api.service.softlayer.com/soap/v3/' | |
); | |
// verifyOrder() will check your order for errors. Replace this with a call | |
// to placeOrder() when you're ready to order. Both calls return a receipt | |
// object that you can use for your records. | |
// | |
// Once your order is placed it'll go through SoftLayer's approval and | |
// provisioning process. When it's done you'll have a new | |
// SoftLayer_Hardware_Server object and server ready to use. | |
$receipt = $client->verifyOrder($orderTemplate); | |
print_r($receipt); | |
} catch (Exception $e) { | |
echo 'Unable to place server order: ' . $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment