Class: Pvectl::Presenters::Storage
- Defined in:
- lib/pvectl/presenters/storage.rb
Overview
Presenter for Proxmox cluster storage pools.
Defines column layout and formatting for table output. Standard columns show essential storage info. Wide columns add content types and shared status.
Instance Method Summary collapse
-
#avail_display ⇒ String
Returns available storage formatted with appropriate unit (GB or TB).
-
#avail_gb ⇒ Float?
Returns available bytes in GB.
-
#columns ⇒ Array<String>
Returns column headers for standard table output.
-
#content_display ⇒ String
Returns content types for display.
-
#disk_total_gb ⇒ Float?
Returns total disk in GB.
-
#disk_used_gb ⇒ Float?
Returns disk used in GB.
-
#extra_columns ⇒ Array<String>
Returns additional column headers for wide output.
-
#extra_values(model, **_context) ⇒ Array<String>
Returns additional values for wide output.
-
#node_display ⇒ String
Returns node display.
-
#shared_display ⇒ String
Returns shared status for display.
-
#status_display ⇒ String
Returns status for display.
-
#to_description(model) ⇒ Hash
Converts Storage model to description format for describe command.
-
#to_hash(model) ⇒ Hash
Converts Storage model to hash for JSON/YAML output.
-
#to_row(model, **_context) ⇒ Array<String>
Converts Storage model to table row values.
-
#total_display ⇒ String
Returns total storage formatted with appropriate unit (GB or TB).
-
#type_display ⇒ String
Returns storage type for display.
-
#usage_display ⇒ String
Returns usage percentage for display.
-
#usage_percent ⇒ Integer?
Returns storage usage percentage.
-
#used_display ⇒ String
Returns used storage formatted with appropriate unit (GB or TB).
Methods inherited from Base
#tags_array, #tags_display, #template_display, #to_wide_row, #uptime_human, #wide_columns
Instance Method Details
#avail_display ⇒ String
Returns available storage formatted with appropriate unit (GB or TB).
184 185 186 187 188 |
# File 'lib/pvectl/presenters/storage.rb', line 184 def avail_display return "-" unless storage.active? && avail_gb format_size(avail_gb) end |
#avail_gb ⇒ Float?
Returns available bytes in GB.
175 176 177 178 179 |
# File 'lib/pvectl/presenters/storage.rb', line 175 def avail_gb return nil if storage.avail.nil? (storage.avail.to_f / 1024 / 1024 / 1024).round(1) end |
#columns ⇒ Array<String>
Returns column headers for standard table output.
23 24 25 |
# File 'lib/pvectl/presenters/storage.rb', line 23 def columns %w[NAME TYPE STATUS USED TOTAL %USED NODE] end |
#content_display ⇒ String
Returns content types for display.
220 221 222 |
# File 'lib/pvectl/presenters/storage.rb', line 220 def content_display storage.content.nil? || storage.content.empty? ? "-" : storage.content end |
#disk_total_gb ⇒ Float?
Returns total disk in GB.
157 158 159 160 161 |
# File 'lib/pvectl/presenters/storage.rb', line 157 def disk_total_gb return nil if storage.maxdisk.nil? (storage.maxdisk.to_f / 1024 / 1024 / 1024).round(1) end |
#disk_used_gb ⇒ Float?
Returns disk used in GB.
148 149 150 151 152 |
# File 'lib/pvectl/presenters/storage.rb', line 148 def disk_used_gb return nil if storage.disk.nil? (storage.disk.to_f / 1024 / 1024 / 1024).round(1) end |
#extra_columns ⇒ Array<String>
Returns additional column headers for wide output.
30 31 32 |
# File 'lib/pvectl/presenters/storage.rb', line 30 def extra_columns %w[CONTENT SHARED] end |
#extra_values(model, **_context) ⇒ Array<String>
Returns additional values for wide output.
57 58 59 60 61 62 63 |
# File 'lib/pvectl/presenters/storage.rb', line 57 def extra_values(model, **_context) @storage = model [ content_display, shared_display ] end |
#node_display ⇒ String
Returns node display. Shows “-” for shared storage (available on multiple nodes).
141 142 143 |
# File 'lib/pvectl/presenters/storage.rb', line 141 def node_display storage.shared? ? "-" : (storage.node || "-") end |
#shared_display ⇒ String
Returns shared status for display.
227 228 229 |
# File 'lib/pvectl/presenters/storage.rb', line 227 def shared_display storage.shared? ? "yes" : "no" end |
#status_display ⇒ String
Returns status for display. Maps “available” to “active” for consistency with kubectl style.
133 134 135 |
# File 'lib/pvectl/presenters/storage.rb', line 133 def status_display storage.active? ? "active" : "inactive" end |
#to_description(model) ⇒ Hash
Converts Storage model to description format for describe command.
Returns a structured Hash with sections for kubectl-style vertical output. Nested Hashes create indented subsections. Arrays of Hashes render as inline tables.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/pvectl/presenters/storage.rb', line 98 def to_description(model) @storage = model { "Name" => storage.name, "Type" => type_display, "Status" => status_display, "Shared" => shared_display, "Nodes" => nodes_display, "Capacity" => build_capacity_section, "Configuration" => build_configuration_section, "Content Summary" => format_content_summary, "Backup Retention" => format_backup_retention } end |
#to_hash(model) ⇒ Hash
Converts Storage model to hash for JSON/YAML output.
Returns a structured hash with nested objects for complex data.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/pvectl/presenters/storage.rb', line 71 def to_hash(model) @storage = model { "name" => storage.name, "type" => storage.plugintype, "status" => storage.status, "node" => storage.node, "shared" => storage.shared?, "content" => storage.content, "disk" => { "used_bytes" => storage.disk, "total_bytes" => storage.maxdisk, "used_gb" => disk_used_gb, "total_gb" => disk_total_gb, "usage_percent" => usage_percent } } end |
#to_row(model, **_context) ⇒ Array<String>
Converts Storage model to table row values.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pvectl/presenters/storage.rb', line 39 def to_row(model, **_context) @storage = model [ storage.name, type_display, status_display, used_display, total_display, usage_display, node_display ] end |
#total_display ⇒ String
Returns total storage formatted with appropriate unit (GB or TB).
202 203 204 205 206 |
# File 'lib/pvectl/presenters/storage.rb', line 202 def total_display return "-" if disk_total_gb.nil? format_size(disk_total_gb) end |
#type_display ⇒ String
Returns storage type for display.
125 126 127 |
# File 'lib/pvectl/presenters/storage.rb', line 125 def type_display storage.plugintype || "-" end |
#usage_display ⇒ String
Returns usage percentage for display.
211 212 213 214 215 |
# File 'lib/pvectl/presenters/storage.rb', line 211 def usage_display return "-" unless storage.active? && usage_percent "#{usage_percent}%" end |
#usage_percent ⇒ Integer?
Returns storage usage percentage.
166 167 168 169 170 |
# File 'lib/pvectl/presenters/storage.rb', line 166 def usage_percent return nil if storage.maxdisk.nil? || storage.maxdisk.zero? || storage.disk.nil? ((storage.disk.to_f / storage.maxdisk) * 100).round end |
#used_display ⇒ String
Returns used storage formatted with appropriate unit (GB or TB).
193 194 195 196 197 |
# File 'lib/pvectl/presenters/storage.rb', line 193 def used_display return "-" unless storage.active? && disk_used_gb format_size(disk_used_gb) end |