Class: Pvectl::Commands::Ping
- Inherits:
-
Object
- Object
- Pvectl::Commands::Ping
- Defined in:
- lib/pvectl/commands/ping.rb
Overview
Handler for the ‘pvectl ping` command.
Verifies connectivity to the Proxmox cluster by calling the version endpoint and measuring response time. Provides a quick health check without detailed resource information.
Class Method Summary collapse
-
.execute(global_options) ⇒ Integer
Executes the ping command.
-
.register(cli) ⇒ void
Registers the ping command with the CLI.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the ping operation.
-
#initialize(global_options) ⇒ Ping
constructor
Creates a new Ping command instance.
Constructor Details
#initialize(global_options) ⇒ Ping
Creates a new Ping command instance.
76 77 78 79 80 81 |
# File 'lib/pvectl/commands/ping.rb', line 76 def initialize() @global_options = @output_format = [:output] || "table" @color_flag = [:color] @config = nil end |
Class Method Details
.execute(global_options) ⇒ Integer
Executes the ping command.
69 70 71 |
# File 'lib/pvectl/commands/ping.rb', line 69 def self.execute() new().execute end |
.register(cli) ⇒ void
This method returns an undefined value.
Registers the ping command with the CLI.
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 |
# File 'lib/pvectl/commands/ping.rb', line 28 def self.register(cli) cli.desc "Check connectivity to Proxmox cluster" cli.long_desc <<~HELP Verify connectivity to the Proxmox cluster by calling the version API endpoint and measuring response time. EXAMPLES Basic connectivity check: $ pvectl ping Wide output with latency: $ pvectl ping -o wide JSON output for scripting: $ pvectl ping -o json NOTES Uses the configured context (or PROXMOX_HOST environment variable) to determine which server to ping. Exit code 0 = connected, exit code 4 = connection error. SEE ALSO pvectl help config Manage cluster configuration pvectl help get nodes List cluster nodes HELP cli.command :ping do |c| c.action do |, , _args| exit_code = execute() exit exit_code if exit_code != 0 end end end |
Instance Method Details
#execute ⇒ Integer
Executes the ping operation.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/pvectl/commands/ping.rb', line 86 def execute load_config connection = Pvectl::Connection.new(@config) result = measure_ping(connection) output_result(result, @config.server) ExitCodes::SUCCESS rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError => e # Re-raise config errors to be handled by CLI error handler raise rescue Timeout::Error output_error("Connection timed out", server_url) ExitCodes::CONNECTION_ERROR rescue Errno::ECONNREFUSED output_error("Connection refused", server_url) ExitCodes::CONNECTION_ERROR rescue SocketError => e output_error(e., server_url) ExitCodes::CONNECTION_ERROR rescue StandardError => e output_error(e., server_url) ExitCodes::CONNECTION_ERROR end |