Class: Offering

Inherits:
Thor
  • Object
show all
Includes:
CommandLineReporter
Defined in:
lib/cloudstack-cli/commands/offering.rb

Instance Method Summary collapse

Instance Method Details

#create(name) ⇒ Object



48
49
50
51
52
# File 'lib/cloudstack-cli/commands/offering.rb', line 48

def create(name)
  options[:name] = name
  cs_cli = CloudstackCli::Helper.new(options[:config])
  puts "OK" if cs_cli.create_offering(options)
end

#delete(id) ⇒ Object



55
56
57
58
# File 'lib/cloudstack-cli/commands/offering.rb', line 55

def delete(id)
  cs_cli = CloudstackCli::Helper.new(options[:config])
  puts "OK" if cs_cli.delete_offering(id)
end

#list(type = 'compute') ⇒ Object



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
31
32
33
34
35
36
37
38
# File 'lib/cloudstack-cli/commands/offering.rb', line 6

def list(type='compute')
  cs_cli = CloudstackCli::Helper.new(options[:config])
  offerings = cs_cli.server_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(border: true) do
      row do
        column 'Name', width: 20
        column 'Description', width: 30
        column 'ID', width: 30
        column 'Domain', width: 16
      end
      offerings.each do |offering|
        row do
          column offering["name"]
          column offering["id"]
          column offering["displaytext"]
          column offering["domain"]
        end
      end
    end
  end
end

#sortObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cloudstack-cli/commands/offering.rb', line 62

def sort
  cs_cli = CloudstackCli::Helper.new(options[:config])
  offerings = cs_cli.server_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"]}"
      cs_cli.update_offering({
        "id" => offer['id'],
        'sortkey' => sortkey
      })
      sortkey -= 1
    end
  end
end