Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created April 23, 2010 23:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save softlayer/377302 to your computer and use it in GitHub Desktop.
Save softlayer/377302 to your computer and use it in GitHub Desktop.
<?php
/**
* Order a new SoftLayer IP subnet
*
* Build a SoftLayer_Container_Product_Order_Network_Subnet object for a new
* IP subnet order and pass it to the SoftLayer_Product_Order API service to
* order it. 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/services/SoftLayer_Container_Product_Order_Network_Subnet
* http://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet_IpAddress
* http://sldn.softlayer.com/reference/services/SoftLayer_Network_Vlan
* 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 id of the SoftLayer_Product_Item_Price entry corresponding to the type
* of subnet you wish to order.
*
* Item prices represent individual items in the SoftLayer product catalog.
* You can order two types of subnets: public static subnets and portable
* subnets.
*
* Static subnets are routed directly to IP addresses. If you're ordering a
* static subnet then set $endPointIpAddressId to the id of the
* SoftLayer_Network_Subnet_IpAddress entry that you wish to route this subnet
* to. You may not route a static subnet to a network identifier, gateway, or
* broadcast IP address.
*
* Public static subnets price ids:
* 1084 - 4 static public addresses
* 1090 - 8 static public addresses
* 1091 - 16 static public addresses
* 1092 - 32 static public addresses
* 1093 - 64 static public addresses
*
* Portable subnets are routed to network VLANs instead of individual IP
* addresses. If you're ordering a portable subnet then set $endPointVlanId to
* the id of the SoftLayer_Network_Vlan entry that you wish to route this
* subnet to.
*
* Portable subnet price ids:
* 1085 - 8 portable public and 8 portable private addresses
* 1086 - 16 portable public and 16 portable private addresses
* 1087 - 32 protable public and 32 portable private addresses
* 1088 - 64 portable public and 64 portable private addresses
*
* @var int
*/
$priceId = null;
/**
* The id of the IP address that you want to route a static subnet to.
*
* @var int
*/
$endPointIpAddressId = null;
/**
* The id of the VLAN that you want to route a portable subnet to.
*
* @var int
*/
$endPointVlanId = null;
/**
* The number of subnets you wish to order
*
* @var int;
*/
$quantity = 1;
// Build a SoftLayer_Container_Product_Order_Network_Subnet object containing
// the order you wish to place. Subnet's don't have a package, so set packageId
// to 0. Since this order is for one item with no sub-options you only have to
// set a single price id in this order.
$orderTemplate = new stdClass();
$orderTemplate->packageId = 0;
$orderTemplate->prices = array();
$orderTemplate->prices[0] = new stdClass();
$orderTemplate->prices[0]->id = $priceId;
$orderTemplate->endPointIpAddressId = $endPointIpAddressId;
$orderTemplate->endPointVlanId = $endPointVlanId;
$orderTemplate->quantity = $quantity;
// 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 subnet.
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_Network_Subnet',
'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_Network_Subnet object ready to use.
$receipt = $client->verifyOrder($orderTemplate);
print_r($receipt);
} catch (Exception $e) {
echo 'Unable to place subnet order: ' . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment