Class: Pvectl::Presenters::Disk

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/presenters/disk.rb

Overview

Presenter for physical disks on Proxmox nodes.

Defines column layout and formatting for table output. Standard columns show device, model, size, type, health, and usage. Wide columns add serial, vendor, WWN, GPT, and mount status.

Examples:

Using with formatter

presenter = Disk.new
formatter = Formatters::Table.new
output = formatter.format(disks, presenter)

See Also:

Instance Method Summary collapse

Methods inherited from Base

#tags_array, #tags_display, #template_display, #to_wide_row, #uptime_human, #wide_columns

Instance Method Details

#columnsArray<String>

Returns column headers for standard table output.

Returns:

  • (Array<String>)

    column headers



23
24
25
# File 'lib/pvectl/presenters/disk.rb', line 23

def columns
  %w[NODE DEVICE MODEL SIZE TYPE HEALTH USED]
end

#extra_columnsArray<String>

Returns additional column headers for wide output.

Returns:

  • (Array<String>)

    extra column headers



30
31
32
# File 'lib/pvectl/presenters/disk.rb', line 30

def extra_columns
  %w[SERIAL VENDOR WWN GPT MOUNTED]
end

#extra_values(model, **_context) ⇒ Array<String>

Returns additional values for wide output.

Parameters:

Returns:

  • (Array<String>)

    extra values matching extra_columns order



57
58
59
60
61
62
63
64
65
66
# File 'lib/pvectl/presenters/disk.rb', line 57

def extra_values(model, **_context)
  @disk = model
  [
    disk.serial || "-",
    disk.vendor || "-",
    disk.wwn || "-",
    format_boolean(disk.gpt),
    format_boolean(disk.mounted)
  ]
end

#to_description(model) ⇒ Hash{String => Object}

Returns detailed description for describe command output.

Parameters:

Returns:

  • (Hash{String => Object})

    nested hash with Device Info and SMART sections



95
96
97
98
99
100
# File 'lib/pvectl/presenters/disk.rb', line 95

def to_description(model)
  @disk = model
  result = { "Device Info" => device_info_section }
  result["SMART Attributes"] = smart_attributes_section if disk.smart_type
  result
end

#to_hash(model) ⇒ Hash

Converts PhysicalDisk model to hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash)

    hash representation with string keys



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pvectl/presenters/disk.rb', line 72

def to_hash(model)
  @disk = model
  {
    "node" => disk.node,
    "device" => disk.devpath,
    "model" => disk.model,
    "size_bytes" => disk.size,
    "size_gb" => disk.size_gb,
    "type" => disk.type,
    "health" => disk.health,
    "used" => disk.used,
    "serial" => disk.serial,
    "vendor" => disk.vendor,
    "wwn" => disk.wwn,
    "gpt" => disk.gpt? || false,
    "mounted" => disk.mounted? || false
  }
end

#to_row(model, **_context) ⇒ Array<String>

Converts PhysicalDisk model to table row values.

Parameters:

Returns:

  • (Array<String>)

    row values matching columns order



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pvectl/presenters/disk.rb', line 39

def to_row(model, **_context)
  @disk = model
  [
    disk.node || "-",
    disk.devpath || "-",
    disk.model || "-",
    format_size,
    disk.type || "-",
    disk.health || "-",
    disk.used || "-"
  ]
end