Skip to content

Instantly share code, notes, and snippets.

@hassenius
Last active September 2, 2016 20:52

Revisions

  1. hassenius revised this gist Apr 11, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions get_package_options.rb
    Original file line number Diff line number Diff line change
    @@ -62,7 +62,7 @@

    puts "Required Categories:"
    #configuration = package.object_mask("isRequired","itemCategory").object_with_id(package_id).getConfiguration()
    configuration = package.object_mask("isRequired","itemCategory").getConfiguration()
    configuration = package.object_mask("mask.isRequired","mask.itemCategory").getConfiguration()
    if options[:required_categories_only] == true then
    required_categories = configuration.select { |configuration_entry| 1 == configuration_entry['isRequired'] }
    else
    @@ -73,7 +73,7 @@
    puts "\t#{configuration_entry['itemCategory']['id']} -- #{configuration_entry['itemCategory']['name']}"
    end

    item_prices = softlayer_product_package.object_mask("id", "item.description", "categories.id").object_with_id(package_id).getItemPrices()
    item_prices = softlayer_product_package.object_mask("mask.id", "mask.item.description", "mask.categories.id").object_with_id(package_id).getItemPrices()
    required_categories.each do |configuration_entry|
    puts "Category \"#{configuration_entry['itemCategory']['name']}\":"
    category_prices = item_prices.map do |item|
  2. hassenius revised this gist Apr 10, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions get_package_options.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    ################################################################################
    # get_package_options.rb
    # ©Copyright IBM Corporation 2014.
    #
    # LICENSE: MIT (http://opensource.org/licenses/MIT)
    ################################################################################
    require 'rubygems'
    require 'softlayer_api'
    require 'optparse'
  3. hassenius created this gist Apr 10, 2014.
    82 changes: 82 additions & 0 deletions get_package_options.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    require 'rubygems'
    require 'softlayer_api'
    require 'optparse'
    require 'pp'

    $SL_API_USERNAME = " set me "
    $SL_API_KEY = " set me "

    options = {:package_id => nil, :required_categories_only => false}

    parser = OptionParser.new do |opts|
    opts.banner = "Usage: get_package_options.rb [options]"
    opts.on('-p', '--package packageID', Integer, 'Package id to query') do |package_id|
    options[:package_id] = package_id;
    end
    opts.on('-r', '--required', 'Only displayed required categories') do |required|
    options[:required_categories_only] = true;
    end


    opts.on('-h', '--help', 'Displays Help') do
    puts opts
    exit
    end

    end
    begin
    parser.parse!
    mandatory = [:package_id]
    missing = mandatory.select{ |param| options[param].nil? }
    unless missing.empty?
    puts parser
    unless options.empty?
    puts "\n Missing the following options: #{missing.join(', ')}"
    end
    exit
    end
    rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::InvalidArgument
    puts parser
    puts $!.to_s
    exit
    end

    softlayer_product_package = SoftLayer::Service.new("SoftLayer_Product_Package");
    softlayer_product_item_price = SoftLayer::Service.new("SoftLayer_Product_Item_Price")

    package_id = options[:package_id]


    # This creates a proxy of the product package service with the virtual guest package ID already
    # "integrated" into it.
    package = softlayer_product_package.object_with_id(package_id)


    # location_id = 138124

    puts "Required Categories:"
    #configuration = package.object_mask("isRequired","itemCategory").object_with_id(package_id).getConfiguration()
    configuration = package.object_mask("isRequired","itemCategory").getConfiguration()
    if options[:required_categories_only] == true then
    required_categories = configuration.select { |configuration_entry| 1 == configuration_entry['isRequired'] }
    else
    required_categories = configuration
    end

    required_categories.each do |configuration_entry|
    puts "\t#{configuration_entry['itemCategory']['id']} -- #{configuration_entry['itemCategory']['name']}"
    end

    item_prices = softlayer_product_package.object_mask("id", "item.description", "categories.id").object_with_id(package_id).getItemPrices()
    required_categories.each do |configuration_entry|
    puts "Category \"#{configuration_entry['itemCategory']['name']}\":"
    category_prices = item_prices.map do |item|
    item["categories"].map do |category|
    item if category["id"] == configuration_entry["itemCategory"]["id"]
    end if item.include?("categories")
    end.flatten.compact

    category_prices.each do |category_price|
    puts "\t #{category_price['id']} -- #{category_price['item']['description']}"
    end
    end