Class: Pvectl::Config::Models::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/config/models/cluster.rb

Overview

Represents a Proxmox cluster server configuration.

Cluster is an immutable value object containing connection settings for a single Proxmox server. It stores the server URL, SSL options, and retry/timeout configuration.

Examples:

Creating a cluster from constructor

cluster = Cluster.new(
  name: "production",
  server: "https://pve.example.com:8006",
  verify_ssl: true,
  certificate_authority: "/path/to/ca.crt"
)

Creating from YAML config hash

hash = {
  "name" => "production",
  "cluster" => {
    "server" => "https://pve.example.com:8006",
    "insecure-skip-tls-verify" => false
  }
}
cluster = Cluster.from_hash(hash)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, server:, verify_ssl: true, certificate_authority: nil, timeout: nil, retry_count: nil, retry_delay: nil, max_retry_delay: nil, retry_writes: nil) ⇒ Cluster

Creates a new Cluster instance.

Parameters:

  • name (String)

    unique name for this cluster

  • server (String)

    Proxmox server URL

  • verify_ssl (Boolean) (defaults to: true)

    whether to verify SSL (default: true)

  • certificate_authority (String, nil) (defaults to: nil)

    path to CA certificate

  • timeout (Integer, nil) (defaults to: nil)

    request timeout in seconds

  • retry_count (Integer, nil) (defaults to: nil)

    maximum retry attempts

  • retry_delay (Integer, nil) (defaults to: nil)

    base delay between retries

  • max_retry_delay (Integer, nil) (defaults to: nil)

    maximum delay cap

  • retry_writes (Boolean, nil) (defaults to: nil)

    whether to retry write operations

Raises:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/pvectl/config/models/cluster.rb', line 71

def initialize(name:, server:, verify_ssl: true, certificate_authority: nil,
               timeout: nil, retry_count: nil, retry_delay: nil,
               max_retry_delay: nil, retry_writes: nil)
  @name = name
  @server = server
  @verify_ssl = verify_ssl
  @certificate_authority = certificate_authority
  @timeout = timeout
  @retry_count = retry_count
  @retry_delay = retry_delay
  @max_retry_delay = max_retry_delay
  @retry_writes = retry_writes

  validate_retry_settings!
end

Instance Attribute Details

#certificate_authorityString? (readonly)

Returns path to CA certificate file.

Returns:

  • (String, nil)

    path to CA certificate file



41
42
43
# File 'lib/pvectl/config/models/cluster.rb', line 41

def certificate_authority
  @certificate_authority
end

#max_retry_delayInteger? (readonly)

Returns maximum delay cap for exponential backoff.

Returns:

  • (Integer, nil)

    maximum delay cap for exponential backoff



53
54
55
# File 'lib/pvectl/config/models/cluster.rb', line 53

def max_retry_delay
  @max_retry_delay
end

#nameString (readonly)

Returns unique name identifying this cluster.

Returns:

  • (String)

    unique name identifying this cluster



32
33
34
# File 'lib/pvectl/config/models/cluster.rb', line 32

def name
  @name
end

#retry_countInteger? (readonly)

Returns maximum retry attempts.

Returns:

  • (Integer, nil)

    maximum retry attempts



47
48
49
# File 'lib/pvectl/config/models/cluster.rb', line 47

def retry_count
  @retry_count
end

#retry_delayInteger? (readonly)

Returns base delay between retries in seconds.

Returns:

  • (Integer, nil)

    base delay between retries in seconds



50
51
52
# File 'lib/pvectl/config/models/cluster.rb', line 50

def retry_delay
  @retry_delay
end

#retry_writesBoolean? (readonly)

Returns whether to retry write operations.

Returns:

  • (Boolean, nil)

    whether to retry write operations



56
57
58
# File 'lib/pvectl/config/models/cluster.rb', line 56

def retry_writes
  @retry_writes
end

#serverString (readonly)

Returns Proxmox server URL (e.g., “pve.example.com:8006”).

Returns:



35
36
37
# File 'lib/pvectl/config/models/cluster.rb', line 35

def server
  @server
end

#timeoutInteger? (readonly)

Returns request timeout in seconds.

Returns:

  • (Integer, nil)

    request timeout in seconds



44
45
46
# File 'lib/pvectl/config/models/cluster.rb', line 44

def timeout
  @timeout
end

#verify_sslBoolean (readonly)

Returns whether to verify SSL certificates.

Returns:

  • (Boolean)

    whether to verify SSL certificates



38
39
40
# File 'lib/pvectl/config/models/cluster.rb', line 38

def verify_ssl
  @verify_ssl
end

Class Method Details

.from_hash(hash) ⇒ Cluster

Creates a Cluster from a kubeconfig-style hash structure.

Examples:

Hash structure

{
  "name" => "production",
  "cluster" => {
    "server" => "https://pve.example.com:8006",
    "insecure-skip-tls-verify" => true,
    "certificate-authority" => "/path/to/ca.crt"
  }
}

Parameters:

  • hash (Hash)

    hash with “name” and “cluster” keys

Returns:

  • (Cluster)

    new cluster instance

Raises:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/pvectl/config/models/cluster.rb', line 102

def self.from_hash(hash)
  cluster_data = hash["cluster"] || {}

  new(
    name: hash["name"],
    server: cluster_data["server"],
    verify_ssl: !cluster_data["insecure-skip-tls-verify"],
    certificate_authority: cluster_data["certificate-authority"],
    timeout: cluster_data["timeout"],
    retry_count: cluster_data["retry-count"],
    retry_delay: cluster_data["retry-delay"],
    max_retry_delay: cluster_data["max-retry-delay"],
    retry_writes: cluster_data["retry-writes"]
  )
end

Instance Method Details

#to_hashHash

Converts the cluster to a kubeconfig-style hash structure.

Returns:

  • (Hash)

    hash representation suitable for YAML serialization



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/pvectl/config/models/cluster.rb', line 121

def to_hash
  cluster_data = {
    "server" => server,
    "insecure-skip-tls-verify" => !verify_ssl
  }
  cluster_data["certificate-authority"] = certificate_authority if certificate_authority
  cluster_data["timeout"] = timeout if timeout
  cluster_data["retry-count"] = retry_count if retry_count
  cluster_data["retry-delay"] = retry_delay if retry_delay
  cluster_data["max-retry-delay"] = max_retry_delay if max_retry_delay
  cluster_data["retry-writes"] = retry_writes unless retry_writes.nil?

  {
    "name" => name,
    "cluster" => cluster_data
  }
end