class Chef::Knife::Cloud::GoogleRegionQuotas

Public Instance Methods

execute_command() click to toggle source
# File lib/chef/knife/google_region_quotas.rb, line 41
def execute_command
  service.list_regions.each do |region|
    ui.msg(ui.color("Region: #{region.name}", :bold))

    quotas = region.quotas
    if quotas.nil? || quotas.empty?
      ui.warn("No quota information available for this region.")
      ui.msg("")
      next
    end

    output = []
    output << table_header
    quotas.each do |quota|
      output << format_name(quota.metric)
      output << format_number(quota.limit)
      output << format_number(quota.usage)
    end

    ui.msg(ui.list(output.flatten, :uneven_columns_across, table_header.size))
    ui.msg("")
  end
end
format_name(name) click to toggle source
# File lib/chef/knife/google_region_quotas.rb, line 73
def format_name(name)
  name.split("_").map(&:capitalize).join(" ")
end
format_number(number) click to toggle source
# File lib/chef/knife/google_region_quotas.rb, line 77
def format_number(number)
  number % 1 == 0 ? number.to_i.to_s : number.to_s
end
table_header() click to toggle source
# File lib/chef/knife/google_region_quotas.rb, line 65
def table_header
  [
    ui.color("Quota", :bold),
    ui.color("Limit", :bold),
    ui.color("Usage", :bold),
  ]
end
validate_params!() click to toggle source
Calls superclass method
# File lib/chef/knife/google_region_quotas.rb, line 36
def validate_params!
  check_for_missing_config_values!
  super
end