Class: Pvectl::Presenters::Service

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

Overview

Presenter for systemd services on Proxmox nodes.

Defines column layout and formatting for table output of node services. Standard columns show node, name, state, active, enabled, description. Wide adds the systemd unit identifier.

Examples:

Using with formatter

presenter = Service.new
formatter = Formatters::Table.new
output = formatter.format(services, presenter)

See Also:

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_description, #to_wide_row, #uptime_human, #wide_columns

Instance Method Details

#columnsArray<String>

Returns column headers for standard table output.



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

def columns
  %w[NODE NAME STATE ACTIVE ENABLED DESCRIPTION]
end

#extra_columnsArray<String>

Returns additional column headers for wide output.



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

def extra_columns
  %w[UNIT]
end

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

Returns additional values for wide output.



55
56
57
# File 'lib/pvectl/presenters/service.rb', line 55

def extra_values(model, **_context)
  [model.service || "-"]
end

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

Converts a Service model to hash for JSON/YAML output.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pvectl/presenters/service.rb', line 63

def to_hash(model)
  {
    "node" => model.node,
    "service" => model.service,
    "name" => model.name,
    "state" => model.state,
    "active_state" => model.active_state,
    "unit_state" => model.unit_state,
    "desc" => model.desc
  }
end

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

Converts a Service model to table row values.



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

def to_row(model, **_context)
  [
    model.node || "-",
    model.display_name || "-",
    model.state || "-",
    model.active_state || "-",
    model.unit_state || "-",
    model.desc || "-"
  ]
end