Class: Chef::Knife::Cloud::GoogleRegionList

Inherits:
ResourceListCommand
  • Object
show all
Includes:
GoogleServiceOptions
Defined in:
lib/chef/knife/google_region_list.rb

Instance Method Summary collapse

Methods included from GoogleServiceOptions

included

Instance Method Details

#before_exec_commandObject



41
42
43
44
45
46
47
48
49
# File 'lib/chef/knife/google_region_list.rb', line 41

def before_exec_command
  @columns_with_info = [
    { label: "Region", key: "name" },
    { label: "Status", key: "status", value_callback: method(:format_status_value) },
    { label: "Zones",  key: "zones", value_callback: method(:format_zones) },
  ]

  @sort_by_field = "name"
end

#format_status_value(status) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/knife/google_region_list.rb', line 55

def format_status_value(status)
  status = status.downcase
  status_color = if status == "up"
                   :green
                 else
                   :red
                 end

  ui.color(status, status_color)
end

#format_zones(zones) ⇒ Object



66
67
68
# File 'lib/chef/knife/google_region_list.rb', line 66

def format_zones(zones)
  zones.map { |zone| zone.split("/").last }.sort.join(", ")
end

#query_resourceObject



51
52
53
# File 'lib/chef/knife/google_region_list.rb', line 51

def query_resource
  service.list_regions
end

#validate_params!Object



36
37
38
39
# File 'lib/chef/knife/google_region_list.rb', line 36

def validate_params!
  check_for_missing_config_values!
  super
end