lib/cloudstack-cli/commands/offering.rb in cloudstack-cli-0.0.5 vs lib/cloudstack-cli/commands/offering.rb in cloudstack-cli-0.1.0
- old
+ new
@@ -1,13 +1,11 @@
-class Offering < Thor
- include CommandLineReporter
+class Offering < CloudstackCli::Base
- desc 'offering list', 'list offerings by type [compute|network|storage]'
+ desc 'list', 'list offerings by type [compute|network|storage]'
option :domain
def list(type='compute')
- cs_cli = CloudstackCli::Helper.new(options[:config])
- offerings = cs_cli.server_offerings(options[:domain])
+ 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|
@@ -16,60 +14,51 @@
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
+ 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 'offering create NAME', 'create offering'
+ 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
- cs_cli = CloudstackCli::Helper.new(options[:config])
- puts "OK" if cs_cli.create_offering(options)
+ puts "OK" if client.create_offering(options)
end
desc 'delete ID', 'delete offering'
def delete(id)
- cs_cli = CloudstackCli::Helper.new(options[:config])
- puts "OK" if cs_cli.delete_offering(id)
+ puts "OK" if client.delete_offering(id)
end
- desc 'offering sort', 'sort by cpu and memory grouped by domain'
+ desc 'sort', 'sort by cpu and memory grouped by domain'
def sort
- cs_cli = CloudstackCli::Helper.new(options[:config])
- offerings = cs_cli.server_offerings(options[:domain])
+ 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"]}"
- cs_cli.update_offering({
+ client.update_offering({
"id" => offer['id'],
'sortkey' => sortkey
})
sortkey -= 1
end
\ No newline at end of file