class ComputeOffer
Public Instance Methods
create(name)
click to toggle source
# File lib/cloudstack-cli/commands/compute_offer.rb 37 def create(name) 38 resolve_domain 39 options[:name] = name 40 say("OK", :green) if client.create_service_offering(options) 41 end
delete(id)
click to toggle source
# File lib/cloudstack-cli/commands/compute_offer.rb 44 def delete(id) 45 offerings = client.list_service_offerings(id: id) 46 if offerings && offerings.size == 1 47 say "Are you sure you want to delete compute offering below?", :yellow 48 print_compute_offerings(offerings, false) 49 if yes?("[y/N]:", :yellow) 50 say("OK", :green) if client.delete_service_offering(id: id) 51 end 52 else 53 say "No offering with ID #{id} found.", :yellow 54 end 55 end
list()
click to toggle source
# File lib/cloudstack-cli/commands/compute_offer.rb 9 def list 10 resolve_domain 11 add_filters_to_options("listServiceOfferings") if options[:filter] 12 offerings = client.list_service_offerings(options) 13 offerings = filter_objects(offerings) if options[:filter] 14 if offerings.size < 1 15 puts "No offerings found." 16 else 17 case options[:format].to_sym 18 when :yaml 19 puts({compute_offers: offerings}.to_yaml) 20 when :json 21 puts JSON.pretty_generate(compute_offers: offerings) 22 else 23 print_compute_offerings(offerings) 24 end 25 end 26 end
print_compute_offerings(offerings, totals = true)
click to toggle source
# File lib/cloudstack-cli/commands/compute_offer.rb 76 def print_compute_offerings(offerings, totals = true) 77 table = [%w(Name Displaytext Domain Tags HostTags ID)] 78 offerings.each do |offering| 79 table << [ 80 offering["name"], 81 offering["displaytext"], 82 offering["domain"], 83 offering["tags"], 84 offering["hosttags"], 85 offering["id"] 86 ] 87 end 88 print_table table 89 say "Total number of offerings: #{offerings.size}" if totals 90 end
sort()
click to toggle source
# File lib/cloudstack-cli/commands/compute_offer.rb 58 def sort 59 offerings = client.list_service_offerings 60 sortkey = -1 61 offerings.group_by{|o| o["domain"]}.each_value do |offers| 62 offers.sort { 63 |oa, ob| [oa["cpunumber"], oa["memory"], oa["name"]] <=> [ob["cpunumber"], ob["memory"], ob["name"]] 64 }.each do |offer| 65 puts "#{sortkey.abs} #{offer['domain']} - #{offer["displaytext"]}" 66 client.update_service_offering( 67 id: offer['id'], 68 sortkey: sortkey 69 ) 70 sortkey -= 1 71 end 72 end 73 end