Skip to content

Instantly share code, notes, and snippets.

@chechuironman
Last active August 29, 2015 14:00
Show Gist options
  • Save chechuironman/e5e3cff9887870cfbbf9 to your computer and use it in GitHub Desktop.
Save chechuironman/e5e3cff9887870cfbbf9 to your computer and use it in GitHub Desktop.
Interactive provisioning CCI
#!/usr/bin/ruby
##################################################################################
# Create CCI interactive
# ©Copyright IBM Corporation 2014.
# LICENSE: MIT (http://opensource.org/licenses/MIT)
# gems used:
# rubygems, softlayer-api
##################################################################################
require 'rubygems'
require 'softlayer_api'
$SL_API_USERNAME = "xxx"
$SL_API_KEY = "xxxx"
# These are the services we'll be using
softlayer_product_package = SoftLayer::Service.new("SoftLayer_Product_Package");
softLayer_product_item_price = SoftLayer::Service.new("SoftLayer_Product_Item_Price");
softLayer_product_order = SoftLayer::Service.new( "SoftLayer_Product_Order");
$product_order = {
'complexType' => 'SoftLayer_Container_Product_Order_Virtual_Guest', # a constant that will tell the server what type of thing we're sending it.
'quantity' => 1, # We only want 1 virtual guest.
'virtualGuests' => [
{
'hostname' => ask("\n Hostname? ", String), # in your own code you would replace this with your own hostname
'domain' => ask("\n Domain? ", String) # in your own code you would replace this with your own domain name
}
],
# These are fields we'll fill in below with more explaination
'location' => nil,
'packageId' => nil,
'prices' => nil,
'sshKeys' => 'test',
'useHourlyPricing'=> ask("\n Hourly rate? (1=yes, 0=no) ", Integer),
}
Virtual_Guest_Package_ID = 46
# set the package id in the product order
$product_order["packageId"] = Virtual_Guest_Package_ID
# This creates a proxy of the product package service with the virtual guest package ID already
# "integrated" into it.
$virtual_guest_package = softlayer_product_package.object_with_id(Virtual_Guest_Package_ID)
puts $virtual_guest_package.getLocations().inspect
$product_order["location"] = ask("\n ID? ", Integer)
puts "Required Categories:"
virtual_guest_configuration = $virtual_guest_package.object_mask("isRequired","itemCategory").getConfiguration()
required_categories = virtual_guest_configuration.select { |configuration_entry| 1 == configuration_entry['isRequired'] }
required_categories.each do |configuration_entry|
puts "\t#{configuration_entry['itemCategory']['id']} -- #{configuration_entry['itemCategory']['name']}"
end
answers = []
item_prices = $virtual_guest_package.object_mask("id", "item.description", "categories.id").getItemPrices()
required_categories.each do |configuration_entry|
puts "Category \"#{configuration_entry['itemCategory']['name']}\":"
category_prices = item_prices.select do |item_price|
if item_price['categories']
item_price['categories'].any? {|category| category['id'] == configuration_entry['itemCategory']['id']}
end
end
category_prices.each do |category_price|
puts "\t #{category_price['id']} -- #{category_price['item']['description']}"
end
answers << ask("\n ID? ", Integer)
puts "\n"
end
puts "NON Required fields"
virtual_guest_configuration = $virtual_guest_package.object_mask("isRequired","itemCategory").getConfiguration()
non_required_categories = virtual_guest_configuration.select { |configuration_entry| 0 == configuration_entry['isRequired'] }
non_required_categories.each do |configuration_entry|
puts "\t#{configuration_entry['itemCategory']['id']} -- #{configuration_entry['itemCategory']['name']}"
end
$cat = ask("ID? ", Integer)
item_prices = $virtual_guest_package.object_mask("id", "item.description", "categories.id").getItemPrices()
non_required_categories.each do |configuration_entry|
if configuration_entry['itemCategory']['id'] == $cat
puts "Category \"#{configuration_entry['itemCategory']['name']}\":"
category_prices = item_prices.select do |item_price|
if item_price['categories']
item_price['categories'].any? {|category| category['id'] == configuration_entry['itemCategory']['id']}
end
end
category_prices.each do |category_price|
puts "\t #{category_price['id']} -- #{category_price['item']['description']}"
end
end
end
answers << ask("\n ID? ", Integer)
$product_order["prices"] = [
{ "id" => answers[0] }, # 1640 -- 1 x 2.0 GHz Cores [Computing Instance]
{ "id" => answers[1] }, # 1645 -- 2 GB [Ram]
{ "id" => answers[2] }, # 905 -- Reboot / Remote Console [Remote Management]
{ "id" => answers[3] }, # 273 -- 100 Mbps public & private networks - default
{ "id" => answers[4] }, # 613 -- 1000 GB Bandwidth for Public bandwidth - default
{ "id" => answers[5] }, # 21 -- 1 IP Address [Primary IP Addresses]
{ "id" => answers[6]}, # 13899 -- First disk: 25 GB
{ "id" => answers[7] }, # 17446 -- Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)
{ "id" => answers[8] }, # 55 -- Host Ping [Monitoring]
{ "id" => answers[9] }, # 57 -- Email and Ticket [Notification]
{ "id" => answers[10] }, # 58 -- Automated Notification [Response]
{ "id" => answers[11] }, # 420 -- Unlimited SSL VPN Users &amp; 1 PPTP VPN User per account [VPN Management - Private Network]
{ "id" => answers[12] }, # 418 -- Nessus Vulnerability Assessment &amp; Reporting [Vulnerability Assessments &amp; Management]
{ "id" => answers[13] } # 22429 -- 1 GB NAS
]
puts $product_order.inspect
begin
result = softLayer_product_order.verifyOrder($product_order)
puts "The order was verified successfully"
# softLayer_product_order.placeOrder($product_order)
rescue => error_reason
puts "The order could not be verified by the server #{error_reason}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment