Class: Pvectl::Commands::WakeonlanNode
- Inherits:
-
Object
- Object
- Pvectl::Commands::WakeonlanNode
- Defined in:
- lib/pvectl/commands/wakeonlan_node.rb
Overview
Handler for the ‘pvectl wakeonlan node` command.
Sends a Wake-on-LAN magic packet to a cluster node. The target node must have its MAC address registered in the cluster configuration (via ‘pvecm` or the web UI) — without it, Proxmox cannot assemble the packet and the command returns an error.
The Proxmox API returns the MAC address used for the packet on success, which is surfaced in the output for confirmation.
Class Method Summary collapse
-
.register(cli) ⇒ void
Registers the ‘wakeonlan node` command with the CLI.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the wakeonlan command.
-
#initialize(node_name, options, global_options, service: nil) ⇒ WakeonlanNode
constructor
Creates a new command instance.
Constructor Details
#initialize(node_name, options, global_options, service: nil) ⇒ WakeonlanNode
Creates a new command instance.
75 76 77 78 79 80 |
# File 'lib/pvectl/commands/wakeonlan_node.rb', line 75 def initialize(node_name, , , service: nil) @node_name = node_name @options = @global_options = @service = service end |
Class Method Details
.register(cli) ⇒ void
This method returns an undefined value.
Registers the ‘wakeonlan node` command with the CLI.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pvectl/commands/wakeonlan_node.rb', line 26 def self.register(cli) cli.desc "Send Wake-on-LAN packet to a cluster node" cli.long_desc <<~HELP Trigger a Wake-on-LAN magic packet to a cluster node via the Proxmox API (POST /nodes/{node}/wakeonlan). EXAMPLES Wake a node: $ pvectl wakeonlan node pve3 Output as JSON: $ pvectl wakeonlan node pve3 -o json NOTES The target node must have its MAC address registered in the cluster configuration beforehand. Use `pvecm` or the Proxmox web UI to set the MAC for each node before relying on WoL. The packet is sent by another online node in the cluster, so at least one other node must be reachable. SEE ALSO pvectl help get nodes List nodes and current status pvectl help describe node Show node details HELP cli.arg_name "RESOURCE_TYPE NAME" cli.command :wakeonlan do |c| c.action do |, , args| resource_type = args.shift resource_name = args.shift unless resource_type == "node" $stderr.puts "Error: Only `pvectl wakeonlan node <NAME>` is supported" exit Pvectl::ExitCodes::USAGE_ERROR end cmd = WakeonlanNode.new(resource_name, {}, ) exit_code = cmd.execute exit exit_code if exit_code != 0 end end end |
Instance Method Details
#execute ⇒ Integer
Executes the wakeonlan command.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pvectl/commands/wakeonlan_node.rb', line 85 def execute return usage_error("NODE name is required") if @node_name.nil? || @node_name.to_s.empty? result = service.execute(node_name: @node_name) render(result) result.successful? ? ExitCodes::SUCCESS : ExitCodes::GENERAL_ERROR rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError raise rescue Timeout::Error, Errno::ECONNREFUSED, SocketError => e $stderr.puts "Error: #{e.}" ExitCodes::CONNECTION_ERROR rescue StandardError => e $stderr.puts "Error: #{e.}" ExitCodes::GENERAL_ERROR end |