Class: Pvectl::Connection

Inherits:
Object
  • Object
show all
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.

Examples:

Creating a connection with ResolvedConfig

config = service.current_config
connection = Connection.new(config)
connection.verify!
client = connection.client

Checking API version

version = connection.version
puts "Proxmox VE #{version['release']}"

Creating a connection with logging

logger = Logger.new($stderr)
connection = Connection.new(config, logger: logger)

Defined Under Namespace

Classes: RetryHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger: nil) ⇒ Connection

Creates a new Connection instance.

Parameters:



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

#configConfig::Models::ResolvedConfig (readonly)

Returns the configuration used.

Returns:



30
31
32
# File 'lib/pvectl/connection.rb', line 30

def config
  @config
end

#retry_handlerConnection::RetryHandler (readonly)

Returns the retry handler instance.

Returns:



33
34
35
# File 'lib/pvectl/connection.rb', line 33

def retry_handler
  @retry_handler
end

Instance Method Details

#clientProxmoxAPI

Returns the Proxmox API client, creating it if necessary.

Returns:

  • (ProxmoxAPI)

    API client instance



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.

Raises:

  • (RuntimeError)

    if connection fails

  • (Timeout::Error)

    if request times out



67
68
69
# File 'lib/pvectl/connection.rb', line 67

def verify!
  version
end

#versionHash

Gets the Proxmox server version information.

Returns:

  • (Hash)

    version information including ‘release’, ‘version’, ‘repoid’

Raises:

  • (Timeout::Error)

    if request times out



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