Module: Chef::Knife::ProxmoxBase

Included in:
ProxmoxClusterList, ProxmoxTemplateList, ProxmoxVmBootstrap, ProxmoxVmCreate, ProxmoxVmList
Defined in:
lib/chef/knife/helpers/proxmox_base.rb

Overview

Shared behaviour mixed into every ‘knife proxmox …` command (SEAM 2).

Owns cluster resolution, the Client/Api factory and the secret-from-ENV override so individual commands stay declarative: they call #proxmox_api, #proxmox_client and #msg_pair and never touch the clusters hash or the environment directly.

The token secret is resolved with ENV precedence and is never sent empty — a missing secret is a loud, fatal error, not a silent default.

Constant Summary collapse

ENV_SECRET_GLOBAL =

Global ENV override applied to whichever cluster is selected.

"KNIFE_PROXMOX_TOKEN_SECRET"
ENV_SECRET_PREFIX =

Per-cluster ENV override prefix; suffix is the cluster key normalized via #env_key.

"KNIFE_PROXMOX_TOKEN_SECRET_"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/chef/knife/helpers/proxmox_base.rb', line 23

def self.included(includer)
  includer.class_eval do
    option :proxmox_cluster,
      long:        "--proxmox-cluster NAME",
      description: "Proxmox cluster key from knife[:proxmox_clusters]"
  end
end

Instance Method Details

#msg_pair(label, value, color = :cyan) ⇒ Object

Print a colored “label: value” line, skipping blank values. Not a knife-core helper; commands depend on it being defined here.



52
53
54
# File 'lib/chef/knife/helpers/proxmox_base.rb', line 52

def msg_pair(label, value, color = :cyan)
  ui.info("#{ui.color(label, color)}: #{value}") if value && !value.to_s.empty?
end

#proxmox_apiObject

The endpoint map over #proxmox_client. Memoized.



45
46
47
48
# File 'lib/chef/knife/helpers/proxmox_base.rb', line 45

def proxmox_api
  # Anchor at top level: inside Chef::Knife, a bare Knife resolves to Chef::Knife.
  @proxmox_api ||= ::Knife::Proxmox::Api.new(proxmox_client)
end

#proxmox_clientObject

The transport client for the selected cluster. Warns on every run when TLS verification is disabled. Memoized.



40
41
42
# File 'lib/chef/knife/helpers/proxmox_base.rb', line 40

def proxmox_client
  @proxmox_client ||= build_proxmox_client
end

#proxmox_cluster_configObject

The selected cluster as a symbol-keyed Hash, with :token_secret resolved through the ENV override. Fatals (and lists available keys) when no cluster is selected or the selected key is unknown. Memoized.



34
35
36
# File 'lib/chef/knife/helpers/proxmox_base.rb', line 34

def proxmox_cluster_config
  @proxmox_cluster_config ||= resolve_cluster_config
end

#proxmox_token_secret_present?(cluster_key, cluster_hash) ⇒ Boolean

Whether a token secret resolves for the given cluster (symbol-keyed hash), using the same precedence as #resolve_token_secret but without fatal-ing. Lets ‘cluster list` report secret presence from a single source of truth.

Returns:

  • (Boolean)


59
60
61
# File 'lib/chef/knife/helpers/proxmox_base.rb', line 59

def proxmox_token_secret_present?(cluster_key, cluster_hash)
  !token_secret_from_sources(cluster_key, cluster_hash).nil?
end