Class: Pvectl::Models::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/models/service.rb

Overview

Represents a Proxmox service running on a node.

Services are system daemons that make up the Proxmox VE platform, such as pveproxy, pvedaemon, pve-cluster, etc.

Examples:

Creating a service instance

service = Service.new(
  service: "pveproxy",
  name: "pveproxy",
  state: "running",
  desc: "PVE API Proxy Server"
)
service.running? # => true

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Service

Creates a new Service instance.

Parameters:

  • attrs (Hash) (defaults to: {})

    service attributes

Options Hash (attrs):

  • :service (String)

    the service identifier

  • :name (String)

    the display name

  • :state (String)

    the current state

  • :desc (String)

    the description

  • :active_state (String)

    systemd ActiveState

  • :unit_state (String)

    systemd UnitFileState

  • :node (String)

    the node this service runs on



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pvectl/models/service.rb', line 53

def initialize(attrs = {})
  super
  @service = attributes[:service]
  @name = attributes[:name]
  @state = attributes[:state]
  @desc = attributes[:desc]
  # Accept both symbol keys (:active_state) and dasherized keys (:"active-state")
  @active_state = attributes[:active_state] || attributes[:"active-state"]
  @unit_state = attributes[:unit_state] || attributes[:"unit-state"]
  @node = attributes[:node]
end

Instance Attribute Details

#active_stateString? (readonly)

Returns systemd ActiveState (active, inactive, failed, …).

Returns:

  • (String, nil)

    systemd ActiveState (active, inactive, failed, …)



35
36
37
# File 'lib/pvectl/models/service.rb', line 35

def active_state
  @active_state
end

#descString? (readonly)

Returns the service description.

Returns:

  • (String, nil)

    the service description



32
33
34
# File 'lib/pvectl/models/service.rb', line 32

def desc
  @desc
end

#nameString? (readonly)

Returns the display name of the service.

Returns:

  • (String, nil)

    the display name of the service



26
27
28
# File 'lib/pvectl/models/service.rb', line 26

def name
  @name
end

#nodeString? (readonly)

Returns node name this service belongs to.

Returns:

  • (String, nil)

    node name this service belongs to



41
42
43
# File 'lib/pvectl/models/service.rb', line 41

def node
  @node
end

#serviceString (readonly)

Returns the service identifier.

Returns:

  • (String)

    the service identifier



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

def service
  @service
end

#stateString (readonly)

Returns the current state (running, stopped, etc.).

Returns:

  • (String)

    the current state (running, stopped, etc.)



29
30
31
# File 'lib/pvectl/models/service.rb', line 29

def state
  @state
end

#unit_stateString? (readonly)

Returns systemd UnitFileState (enabled, disabled, masked, …).

Returns:

  • (String, nil)

    systemd UnitFileState (enabled, disabled, masked, …)



38
39
40
# File 'lib/pvectl/models/service.rb', line 38

def unit_state
  @unit_state
end

Instance Method Details

#display_nameString

Returns the display name, falling back to service identifier.

Returns:

  • (String)

    the name to display



75
76
77
# File 'lib/pvectl/models/service.rb', line 75

def display_name
  name || service
end

#running?Boolean

Checks if the service is currently running.

Returns:

  • (Boolean)

    true if state is “running”



68
69
70
# File 'lib/pvectl/models/service.rb', line 68

def running?
  state == "running"
end