Created
September 13, 2010 21:52
-
-
Save softlayer/578121 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
// 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. | |
// | |
// Backend code to call the SoftLayer API was generated with the wsdl.exe | |
// utility: | |
// | |
// wsdl.exe /language:CS /out:"C:\path\to\project\SoftLayer_API.cs" /sharetypes http://api.service.softlayer.com/soap/v3/SoftLayer_Product_Order?wsdl | |
// | |
// Important manual pages: | |
// http://sldn.softlayer.com/article/C_Sharp | |
// 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> | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Your SoftLayer API username. | |
string username = "set me!"; | |
// Your SoftLayer API key. | |
// | |
// Generate one at https://manage.softlayer.com/Administrative/apiKeychain | |
string apiKey = "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 | |
int priceId = 0; | |
// The id of the IP address that you want to route a static subnet | |
// to. | |
int endPointIpAddressId = 0; | |
// The id of the VLAN that you want to route a portable subnet to. | |
int endPointVlanId = 0; | |
// The number of subnets you wish to order | |
int quantity = 1; | |
// Build a SoftLayer_Container_Product_Order_Network_Subnet object | |
// containing the order you wish to place. Subnets 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. | |
SoftLayer_Container_Product_Order_Network_Subnet orderTemplate = new SoftLayer_Container_Product_Order_Network_Subnet(); | |
orderTemplate.packageId = 0; | |
orderTemplate.packageIdSpecified = true; | |
orderTemplate.prices = new SoftLayer_Product_Item_Price[1]; | |
orderTemplate.prices[0] = new SoftLayer_Product_Item_Price(); | |
orderTemplate.prices[0].id = priceId; | |
orderTemplate.prices[0].idSpecified = true; | |
orderTemplate.endPointIpAddressId = endPointIpAddressId; | |
orderTemplate.endPointIpAddressIdSpecified = true; | |
orderTemplate.endPointVlanId = endPointVlanId; | |
orderTemplate.endPointVlanIdSpecified = true; | |
orderTemplate.quantity = quantity; | |
orderTemplate.quantitySpecified = true; | |
// Create a connection to the SoftLayer_Product_Order API service | |
// and bind our API username and key to it. | |
authenticate authenticate = new authenticate(); | |
authenticate.username = username; | |
authenticate.apiKey = apiKey; | |
SoftLayer_Product_OrderService orderService = new SoftLayer_Product_OrderService(); | |
orderService.authenticateValue = authenticate; | |
// 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. | |
try | |
{ | |
SoftLayer_Container_Product_Order_Network_Subnet verifiedOrder = (SoftLayer_Container_Product_Order_Network_Subnet)orderService.verifyOrder(orderTemplate); | |
Console.WriteLine("Order verified!"); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Invalid order: " + e.Message); | |
} | |
// Hit <enter> to exit. | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment