fluke/devops-client/lib/devops-client/output/flavors.rb
2015-04-14 16:29:02 +04:00

49 lines
1.5 KiB
Ruby

require "devops-client/output/base"
require "devops-client/output/concerns/has_provider"
module Output
class Flavors < Base
include Concerns::HasProvider
def table
headers, rows = create(@data, @options[:given_provider])
create_table(headers, rows, I18n.t("output.title.flavor.list"))
end
def csv
headers, rows = create(@data, @options[:given_provider])
create_csv(headers, rows)
end
private
def create list, provider
abort(I18n.t("output.not_found.flavor.list")) if list.nil? or list.empty?
headers = nil
rows = []
if provider == "openstack"
headers = [
I18n.t("output.table_header.id"),
I18n.t("output.table_header.virtual_cpus"),
I18n.t("output.table_header.disk"),
I18n.t("output.table_header.ram")
]
list.each do |l|
rows << [ l["id"], l["v_cpus"], l["disk"], l["ram"] ]
end
elsif provider == "ec2"
headers = [
I18n.t("output.table_header.name"),
I18n.t("output.table_header.id"),
I18n.t("output.table_header.virtual_cpus"),
I18n.t("output.table_header.disk"),
I18n.t("output.table_header.ram")
]
list.each do |l|
rows << [ l["name"], l["id"], l["cores"], l["disk"], l["ram"] ]
end
end
return headers, rows
end
end
end