Sha256: a693239f7320232808beb51d4b0021c26e2f4be36f63e7326ec4954a47449d99

Contents?: true

Size: 1.82 KB

Versions: 6

Compression:

Stored size: 1.82 KB

Contents

class Offering < CloudstackCli::Base

  desc 'list', 'list offerings by type [compute|network|storage]'
  option :domain
  def list(type='compute')
    offerings = client.list_service_offerings(options[:domain])

    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 "#{offer['domain']} - #{offer["displaytext"]}"
      end
    end

    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
    end
  end

  desc 'create NAME', 'create 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)
    options[:name] = name
    puts "OK" if client.create_offering(options)
  end

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


  desc 'sort', 'sort by cpu and memory grouped by domain'
  def sort
    offerings = client.list_service_offerings(options[:domain])
    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_offering({
          "id" => offer['id'],
          'sortkey' => sortkey
        })
        sortkey -= 1
      end
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cloudstack-cli-0.1.5 lib/cloudstack-cli/commands/offering.rb
cloudstack-cli-0.1.4 lib/cloudstack-cli/commands/offering.rb
cloudstack-cli-0.1.3 lib/cloudstack-cli/commands/offering.rb
cloudstack-cli-0.1.2 lib/cloudstack-cli/commands/offering.rb
cloudstack-cli-0.1.1 lib/cloudstack-cli/commands/offering.rb
cloudstack-cli-0.1.0 lib/cloudstack-cli/commands/offering.rb