Sha256: d51474dce14707465ef04e91291fc62ee213b7b1beba0fb8877cdc9fe43dcd22

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

class ComputeOffer < CloudstackCli::Base

  desc 'list', 'list compute offerings'
  option :domain, desc: "the domain associated with the compute offering"
  def list
    resolve_domain
    offerings = client.list_service_offerings(options)
    if offerings.size < 1
      puts "No offerings found."
    else
      table = [["Name", "Displaytext", "Domain", "ID"]]
      offerings.each do |offering|
        table << [
          offering["name"],
          offering["displaytext"],
          offering["domain"],
          offering["id"]
        ]
      end
      print_table table
      say "Total number of offerings: #{offerings.size}"
    end
  end

  desc 'create NAME', 'create compute offering'
  option :cpunumber, required: true
  option :cpuspeed, required: true
  option :displaytext, required: true
  option :memory, required: true
  option :domain
  option :ha, type: :boolean
  option :tags
  def create(name)
    resolve_domain
    options[:name] = name
    puts "OK" if client.create_offering(options)
  end

  desc 'delete ID', 'delete compute offering'
  def delete(id)
    puts "OK" if client.delete_service_offering(id: id)
  end

  desc 'sort', 'sort by cpu and memory grouped by domain'
  def sort
    offerings = client.list_service_offerings
    sortkey = -1
    offerings.group_by{|o| o["domain"]}.each_value do |offers|
      offers.sort {
        |oa, ob| [oa["cpunumber"], oa["memory"]] <=> [ob["cpunumber"], ob["memory"]]
      }.each do |offer|
        puts "#{sortkey.abs} #{offer['domain']} - #{offer["displaytext"]}"
        client.update_service_offering(
          id: offer['id'],
          sortkey: sortkey
        )
        sortkey -= 1
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cloudstack-cli-1.0.0.rc4 lib/cloudstack-cli/commands/compute_offer.rb
cloudstack-cli-1.0.0.rc3 lib/cloudstack-cli/commands/compute_offer.rb
cloudstack-cli-1.0.0.rc2 lib/cloudstack-cli/commands/compute_offer.rb
cloudstack-cli-1.0.0.rc1 lib/cloudstack-cli/commands/compute_offer.rb