Class: Pvectl::Connection
- Inherits:
-
Object
- Object
- Pvectl::Connection
- Defined in:
- lib/pvectl/connection.rb,
lib/pvectl/connection/retry_handler.rb
Overview
Wrapper for Proxmox API communication.
Connection encapsulates the proxmox-api gem client, providing a unified interface for API access. It handles both token and password authentication, and includes retry logic with exponential backoff and timeout handling.
Defined Under Namespace
Classes: RetryHandler
Instance Attribute Summary collapse
-
#config ⇒ Config::Models::ResolvedConfig
readonly
The configuration used.
-
#retry_handler ⇒ Connection::RetryHandler
readonly
The retry handler instance.
Instance Method Summary collapse
-
#client ⇒ ProxmoxAPI
Returns the Proxmox API client, creating it if necessary.
-
#initialize(config, logger: nil) ⇒ Connection
constructor
Creates a new Connection instance.
-
#verify! ⇒ void
Verifies the connection to the Proxmox server.
-
#version ⇒ Hash
Gets the Proxmox server version information.
Constructor Details
#initialize(config, logger: nil) ⇒ Connection
Creates a new Connection instance.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pvectl/connection.rb', line 39 def initialize(config, logger: nil) @config = config @client = nil @logger = logger @retry_handler = RetryHandler.new( max_retries: config.retry_count, base_delay: config.retry_delay, max_delay: config.max_retry_delay, retry_writes: config.retry_writes, logger: logger ) end |
Instance Attribute Details
#config ⇒ Config::Models::ResolvedConfig (readonly)
Returns the configuration used.
30 31 32 |
# File 'lib/pvectl/connection.rb', line 30 def config @config end |
#retry_handler ⇒ Connection::RetryHandler (readonly)
Returns the retry handler instance.
33 34 35 |
# File 'lib/pvectl/connection.rb', line 33 def retry_handler @retry_handler end |
Instance Method Details
#client ⇒ ProxmoxAPI
Returns the Proxmox API client, creating it if necessary.
55 56 57 |
# File 'lib/pvectl/connection.rb', line 55 def client @client ||= create_client end |
#verify! ⇒ void
This method returns an undefined value.
Verifies the connection to the Proxmox server.
Makes a test request to the API version endpoint to verify connectivity and authentication. Uses retry logic for resilience.
67 68 69 |
# File 'lib/pvectl/connection.rb', line 67 def verify! version end |
#version ⇒ Hash
Gets the Proxmox server version information.
75 76 77 78 79 80 81 |
# File 'lib/pvectl/connection.rb', line 75 def version with_timeout do retry_handler.with_retry(method: :get) do client.version.get end end end |