Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created September 8, 2010 19:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softlayer/570676 to your computer and use it in GitHub Desktop.
Save softlayer/570676 to your computer and use it in GitHub Desktop.
// Order a monthly billed Bare Metal Computing instance.
//
// Build a SoftLayer_Container_Product_Order_Hardware_Server object for a new
// Bare Metal Cloud (BMC) order and pass it to the SoftLayer_Product_Order API
// service to order it. In this care we'll order a 4 core instance with 16G
// RAM, 1000mbit NICs, 2000GB bandwidth, a 250G SATA drive, Windows 2008 R2
// Datacenter edition (64-bit) with Hyper-V, and default server order options.
// 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/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>
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!";
// Your new BMC's hostname.
string hostname = "myhost";
// Your new BMC's domain name.
string domain = "example.org";
// Where you'd like your new server provisioned.
//
// This can either be the id of the datacenter you wish your new
// BMC to be provisioned in or the string 'FIRST_AVAILABLE' if you
// have no preference where your BMC is provisioned.
//
// Location id "3" = Dallas
// Location id "18171" = Seattle
// Location id "37473" = Washington, D.C.
string location = "FIRST_AVAILABLE";
// 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 BMC. Use the getActivePackages() method in the
// SoftLayer_Account API service to get a list of available item
// and price options per available package.
int[] prices = {
2165, // 4 cores + 16G RAM
19, // 250G hard drive
274, // 1000mbps public & private network
34, // 2000GB monthly bandwidth allocation
905, // reboot / remote console access
21, // single primary IP address
22, // 4x public IP addresses
1867, // Windows 2008 R2, Datacenter Edition (64-bit) with Hyper-v
894, // Windows Firewall
55, // host ping monitoring
57, // email and ticket monitoring notification
58, // automated notification response
420, // unlimited SSL and 1 PPTP VPN users per account
418, // Nessus vulnerability and assessment reporting
};
// Create the order template that we'll pass to the
// SoftLayer_Product_Order API service and set up all of its
// options.
SoftLayer_Container_Product_Order_Hardware_Server orderTemplate = new SoftLayer_Container_Product_Order_Hardware_Server();
// Most orders placed from softlayer require a package id. In this
// case package id 50 denotes we wish to order from SoftLayer's
// Bare Metal Cloud type of dedicated server.
orderTemplate.packageId = 50;
orderTemplate.packageIdSpecified = true;
orderTemplate.location = location;
// If you choose to order more than one BMC then increase the
// quantity and add another hostname/domain pair to the order
// template.
orderTemplate.quantity = 1;
orderTemplate.quantitySpecified = true;
orderTemplate.hardware = new SoftLayer_Hardware_Server[1];
orderTemplate.hardware[0] = new SoftLayer_Hardware_Server();
orderTemplate.hardware[0].hostname = hostname;
orderTemplate.hardware[0].domain = domain;
// Convert our array of order option price ids into
// SoftLayer_Product_Item_Price objects. SoftLayer's ordering
// system only needs the id property populated to know what you
// intend to order.
List<SoftLayer_Product_Item_Price> orderPrices = new List<SoftLayer_Product_Item_Price>();
foreach(int priceId in prices)
{
SoftLayer_Product_Item_Price price = new SoftLayer_Product_Item_Price();
price.id = priceId;
price.idSpecified = true;
orderPrices.Add(price);
}
orderTemplate.prices = orderPrices.ToArray();
// 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_Hardware_Server object and server ready to use.
try
{
SoftLayer_Container_Product_Order_Hardware_Server verifiedOrder = (SoftLayer_Container_Product_Order_Hardware_Server) 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