Class: Pvectl::Presenters::Volume

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

Overview

Presenter for virtual disks (volumes) attached to VMs and containers.

Defines column layout and formatting for table output. Standard columns show node, resource type, ID, name, storage, size, and format. Wide columns add volume ID, cache, discard, SSD, iothread, and backup flags.

Examples:

Using with formatter

presenter = Volume.new
formatter = Formatters::Table.new
output = formatter.format(volumes, 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/volume.rb', line 23

def columns
  %w[NODE RESOURCE ID NAME STORAGE SIZE FORMAT]
end

#extra_columnsArray<String>

Returns additional column headers for wide output.

Returns:

  • (Array<String>)

    extra column headers



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

def extra_columns
  %w[VOLUME-ID CACHE DISCARD SSD IOTHREAD BACKUP]
end

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

Returns additional values for wide output.

Parameters:

  • model (Models::Volume)

    Volume model

  • _context (Hash)

    optional context

Returns:

  • (Array<String>)

    extra values matching extra_columns order



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

def extra_values(model, **_context)
  @volume = model
  [
    volume.volume_id || "-",
    volume.cache || "-",
    volume.discard || "-",
    volume.ssd&.to_s || "-",
    volume.iothread&.to_s || "-",
    volume.backup&.to_s || "-"
  ]
end

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

Returns detailed description for describe command output.

Parameters:

Returns:

  • (Hash{String => Hash{String, String}})

    nested hash with Volume Info section



99
100
101
102
# File 'lib/pvectl/presenters/volume.rb', line 99

def to_description(model)
  @volume = model
  { "Volume Info" => volume_info_section }
end

#to_hash(model) ⇒ Hash{String => untyped}

Converts Volume model to hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash{String => untyped})

    hash representation with string keys



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

def to_hash(model)
  @volume = model
  {
    "name" => volume.name,
    "storage" => volume.storage,
    "volume_id" => volume.volume_id,
    "volid" => volume.volid,
    "size" => volume.size,
    "format" => volume.format,
    "resource_type" => volume.resource_type,
    "resource_id" => volume.resource_id,
    "node" => volume.node,
    "content" => volume.content,
    "cache" => volume.cache,
    "discard" => volume.discard,
    "ssd" => volume.ssd,
    "iothread" => volume.iothread,
    "backup" => volume.backup,
    "mp" => volume.mp
  }
end

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

Converts Volume model to table row values.

Parameters:

  • model (Models::Volume)

    Volume model

  • _context (Hash)

    optional context

Returns:

  • (Array<String>)

    row values matching columns order



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

def to_row(model, **_context)
  @volume = model
  [
    volume.node || "-",
    volume.resource_type || "-",
    volume.resource_id&.to_s || "-",
    volume.name || "-",
    volume.storage || "-",
    volume.size || "-",
    volume.format || "-"
  ]
end