Class: Pvectl::Presenters::Volume

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

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 Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#format_bytes, #format_firewall, #format_firewall_rules, #format_task_history, #resource, #tags_array, #tags_display, #template_display, #to_wide_row, #uptime_human, #wide_columns

Instance Attribute Details

#volumeModels::Volume (readonly)

Returns the current volume being presented.

Returns:



107
108
109
# File 'lib/pvectl/presenters/volume.rb', line 107

def volume
  @volume
end

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

#volume_info_sectionHash{String => String}

Builds the Volume Info section hash. Optional fields are only included when they have values.

Returns:

  • (Hash{String => String})

    volume info key-value pairs



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/pvectl/presenters/volume.rb', line 113

def volume_info_section
  info = {
    "Name" => volume.name || "-",
    "Storage" => volume.storage || "-",
    "Volume ID" => volume.volume_id || "-",
    "Full Volume ID" => volume.volid || "-",
    "Size" => volume.size || "-",
    "Format" => volume.format || "-",
    "Resource Type" => volume.resource_type || "-",
    "Resource ID" => volume.resource_id&.to_s || "-",
    "Node" => volume.node || "-"
  }
  info["Content"] = volume.content if volume.content
  info["Cache"] = volume.cache if volume.cache
  info["Discard"] = volume.discard if volume.discard
  info["SSD"] = volume.ssd if volume.ssd
  info["IO Thread"] = volume.iothread if volume.iothread
  info["Backup"] = volume.backup if volume.backup
  info["Mount Point"] = volume.mp if volume.mp
  info
end