Class: Chef::Knife::Cloud::GoogleRegionQuotas
- Inherits:
-
Command
- Object
- Command
- Chef::Knife::Cloud::GoogleRegionQuotas
- Includes:
- GoogleServiceOptions
- Defined in:
- lib/chef/knife/google_region_quotas.rb
Instance Method Summary collapse
- #execute_command ⇒ Object
- #format_name(name) ⇒ Object
- #format_number(number) ⇒ Object
- #table_header ⇒ Object
- #validate_params! ⇒ Object
Methods included from GoogleServiceOptions
Instance Method Details
#execute_command ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
73 74 75 |
# File 'lib/chef/knife/google_region_quotas.rb', line 73 def format_name(name) name.split("_").map(&:capitalize).join(" ") end |
#format_number(number) ⇒ Object
77 78 79 |
# 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 ⇒ Object
65 66 67 68 69 70 71 |
# 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! ⇒ Object
36 37 38 39 |
# File 'lib/chef/knife/google_region_quotas.rb', line 36 def validate_params! check_for_missing_config_values! super end |