Class: Chef::Knife::Cloud::GoogleDiskList
- Inherits:
-
ResourceListCommand
- Object
- ResourceListCommand
- Chef::Knife::Cloud::GoogleDiskList
- Includes:
- GoogleServiceOptions
- Defined in:
- lib/chef/knife/google_disk_list.rb
Instance Method Summary collapse
- #before_exec_command ⇒ Object
- #format_disk_type(type) ⇒ Object
- #format_source_image(source) ⇒ Object
- #format_status_value(status) ⇒ Object
- #format_users(users) ⇒ Object
- #query_resource ⇒ Object
- #validate_params! ⇒ Object
Methods included from GoogleServiceOptions
Instance Method Details
#before_exec_command ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef/knife/google_disk_list.rb', line 41 def before_exec_command @columns_with_info = [ { label: "Zone", key: "name" }, { label: "Status", key: "status", value_callback: method(:format_status_value) }, { label: "Size (GB)", key: "size_gb" }, { label: "Type", key: "type", value_callback: method(:format_disk_type) }, { label: "Source Image", key: "source_image", value_callback: method(:format_source_image) }, { label: "Attached To", key: "users", value_callback: method(:format_users) }, ] @sort_by_field = "name" end |
#format_disk_type(type) ⇒ Object
69 70 71 |
# File 'lib/chef/knife/google_disk_list.rb', line 69 def format_disk_type(type) type.split("/").last end |
#format_source_image(source) ⇒ Object
73 74 75 76 77 |
# File 'lib/chef/knife/google_disk_list.rb', line 73 def format_source_image(source) return "unknown" if source.nil? || source.empty? source.split("/").last(4).join("/") end |
#format_status_value(status) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef/knife/google_disk_list.rb', line 58 def format_status_value(status) status = status.downcase status_color = if status == "ready" :green else :red end ui.color(status, status_color) end |
#format_users(users) ⇒ Object
79 80 81 82 83 |
# File 'lib/chef/knife/google_disk_list.rb', line 79 def format_users(users) return "none" if users.nil? || users.empty? users.map { |user| user.split("/").last(5).join("/") }.join(", ") end |
#query_resource ⇒ Object
54 55 56 |
# File 'lib/chef/knife/google_disk_list.rb', line 54 def query_resource service.list_disks end |
#validate_params! ⇒ Object
36 37 38 39 |
# File 'lib/chef/knife/google_disk_list.rb', line 36 def validate_params! check_for_missing_config_values!(:gce_zone) super end |