Class: Offering

Inherits:
CloudstackCli::Base show all
Defined in:
lib/cloudstack-cli/commands/offering.rb

Instance Attribute Summary

Attributes inherited from CloudstackCli::Base

#config

Instance Method Summary collapse

Instance Method Details

#create(name) ⇒ Object



40
41
42
43
# File 'lib/cloudstack-cli/commands/offering.rb', line 40

def create(name)
  options[:name] = name
  puts "OK" if client.create_offering(options)
end

#delete(id) ⇒ Object



46
47
48
# File 'lib/cloudstack-cli/commands/offering.rb', line 46

def delete(id)
  puts "OK" if client.delete_offering(id)
end

#list(type = 'compute') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cloudstack-cli/commands/offering.rb', line 5

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

#sortObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cloudstack-cli/commands/offering.rb', line 52

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