Class: Pvectl::Services::Wakeonlan

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/services/wakeonlan.rb

Overview

Sends a Wake-on-LAN packet to a cluster node.

Verifies the node exists in the cluster, calls the WoL API endpoint, and wraps the outcome in a NodeOperationResult. The Proxmox API returns the MAC address used for the magic packet on success, which is surfaced in the result message for confirmation.

Examples:

Basic usage

service = Wakeonlan.new(node_repository: repo)
result = service.execute(node_name: "pve3")
result.successful? #=> true
result.message     #=> "Wake-on-LAN packet sent (MAC: AA:BB:CC:DD:EE:FF)"

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(node_repository:) ⇒ Wakeonlan

Creates a new service.

Parameters:



25
26
27
# File 'lib/pvectl/services/wakeonlan.rb', line 25

def initialize(node_repository:)
  @node_repository = node_repository
end

Instance Method Details

#execute(node_name:) ⇒ Models::NodeOperationResult

Sends the WoL packet to a node.

Parameters:

  • node_name (String)

    target node name

Returns:



33
34
35
36
37
38
39
40
41
# File 'lib/pvectl/services/wakeonlan.rb', line 33

def execute(node_name:)
  node = @node_repository.get(node_name)
  return not_found_result(node_name) unless node

  mac = @node_repository.wakeonlan(node_name)
  build_result(node, success: true, message: success_message(mac))
rescue StandardError => e
  build_result(node || Models::Node.new(name: node_name), success: false, error: e.message)
end