Class: Pvectl::Config::Models::Cluster
- Inherits:
-
Object
- Object
- Pvectl::Config::Models::Cluster
- 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.
Instance Attribute Summary collapse
-
#certificate_authority ⇒ String?
readonly
Path to CA certificate file.
-
#max_retry_delay ⇒ Integer?
readonly
Maximum delay cap for exponential backoff.
-
#name ⇒ String
readonly
Unique name identifying this cluster.
-
#retry_count ⇒ Integer?
readonly
Maximum retry attempts.
-
#retry_delay ⇒ Integer?
readonly
Base delay between retries in seconds.
-
#retry_writes ⇒ Boolean?
readonly
Whether to retry write operations.
-
#server ⇒ String
readonly
Proxmox server URL (e.g., “pve.example.com:8006”).
-
#timeout ⇒ Integer?
readonly
Request timeout in seconds.
-
#verify_ssl ⇒ Boolean
readonly
Whether to verify SSL certificates.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Cluster
Creates a Cluster from a kubeconfig-style hash structure.
Instance Method Summary collapse
-
#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
constructor
Creates a new Cluster instance.
-
#to_hash ⇒ Hash
Converts the cluster to a kubeconfig-style hash structure.
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.
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 = @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_authority ⇒ String? (readonly)
Returns path to CA certificate file.
41 42 43 |
# File 'lib/pvectl/config/models/cluster.rb', line 41 def @certificate_authority end |
#max_retry_delay ⇒ Integer? (readonly)
Returns 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 |
#name ⇒ String (readonly)
Returns unique name identifying this cluster.
32 33 34 |
# File 'lib/pvectl/config/models/cluster.rb', line 32 def name @name end |
#retry_count ⇒ Integer? (readonly)
Returns maximum retry attempts.
47 48 49 |
# File 'lib/pvectl/config/models/cluster.rb', line 47 def retry_count @retry_count end |
#retry_delay ⇒ Integer? (readonly)
Returns 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_writes ⇒ Boolean? (readonly)
Returns whether to retry write operations.
56 57 58 |
# File 'lib/pvectl/config/models/cluster.rb', line 56 def retry_writes @retry_writes end |
#server ⇒ String (readonly)
Returns Proxmox server URL (e.g., “pve.example.com:8006”).
35 36 37 |
# File 'lib/pvectl/config/models/cluster.rb', line 35 def server @server end |
#timeout ⇒ Integer? (readonly)
Returns request timeout in seconds.
44 45 46 |
# File 'lib/pvectl/config/models/cluster.rb', line 44 def timeout @timeout end |
#verify_ssl ⇒ Boolean (readonly)
Returns 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.
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_hash ⇒ Hash
Converts the cluster to a kubeconfig-style hash structure.
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"] = if 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 |