Module: Chef::Knife::ProxmoxVmProvision

Included in:
ProxmoxVmBootstrap, ProxmoxVmCreate
Defined in:
lib/chef/knife/helpers/proxmox_vm_provision.rb

Overview

Shared provisioning concern for the ‘knife proxmox vm …` commands that clone and configure a VM. Owns the CLI surface and the clone→configure→start→wait pipeline so both `vm create` (provision only) and `vm bootstrap` (provision + Chef bootstrap) declare it once.

The mixin is intentionally agnostic about whether a bootstrap follows: it resolves cloud-init auth and plants it on the guest, but never touches the bootstrap connection. The bootstrap command layers that on by overriding #apply_provision_auth!.

Constant Summary collapse

VMBR_PATTERN =

Proxmox bridge interface names: “vmbr” followed by digits (vmbr0, vmbr1, …). IP/gateway validation is handled separately by IPAddr in #validate_ip!/#validate_gateway!.

/\Avmbr\d+\z/
PRIVATE_KEY_MARKER =

A pasted PRIVATE key must never travel as an authorized public key.

/-----BEGIN [A-Z ]*PRIVATE KEY-----/
PUBLIC_KEY_PREFIXES =

Public-key formats cloud-init understands.

%w{ssh- ecdsa- sk- ssh-ed25519}.freeze
ENV_CIPASSWORD =

ENV override for the cloud-init password so it never lands in shell history.

"KNIFE_PROXMOX_CIPASSWORD"

Class Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/chef/knife/helpers/proxmox_vm_provision.rb', line 29

def self.included(includer)
  includer.class_eval do
    # --- Source template / clone placement --------------------------------

    option :template,
      long:        "--template NAME_OR_VMID",
      description: "Source template to clone (name or numeric VMID). Required."

    option :target_node,
      long:        "--target-node NODE",
      description: "Target node for the clone (migrate on clone). Defaults to the template's node."

    option :newid,
      long:        "--newid VMID",
      description: "VMID for the new VM. Defaults to the cluster's next free id."

    option :linked_clone,
      long:        "--linked-clone",
      description: "Linked clone instead of the default full clone " \
                   "(needs a storage that supports it; --storage is then ignored).",
      boolean:     true

    option :storage,
      long:        "--storage STORAGE",
      description: "Target storage for a full clone."

    option :pool,
      long:        "--pool POOL",
      description: "Resource pool to place the new VM in."

    # --- Hardware ---------------------------------------------------------

    option :cores,
      long:        "--cores N",
      description: "Number of CPU cores."

    option :sockets,
      long:        "--sockets N",
      description: "Number of CPU sockets."

    option :memory,
      long:        "--memory MiB",
      description: "Memory in MiB."

    # --- Networking -------------------------------------------------------

    option :bridge,
      long:        "--bridge vmbrN",
      description: "Network bridge for net0 (e.g. vmbr0)."

    option :vlan,
      long:        "--vlan TAG",
      description: "VLAN tag for net0."

    option :ip,
      long:        "--ip CIDR|IP|dhcp",
      description: "Static IP (CIDR or bare IPv4) or the literal 'dhcp'."

    option :gateway,
      long:        "--gateway IP",
      description: "Default gateway (IPv4)."

    option :prefix,
      long:        "--prefix N",
      description: "Netmask prefix length when --ip is a bare IPv4 (default 24)."

    option :nameserver,
      long:        "--nameserver IP",
      description: "cloud-init DNS nameserver."

    option :searchdomain,
      long:        "--searchdomain DOMAIN",
      description: "cloud-init DNS search domain."

    # --- cloud-init auth --------------------------------------------------

    option :ciuser,
      long:        "--ciuser USER",
      description: "cloud-init default user."

    option :ssh_public_key,
      long:        "--ssh-public-key PATH",
      description: "Path to an SSH PUBLIC key authorized for the cloud-init user."

    option :cipassword,
      long:        "--cipassword",
      description: "Prompt (no echo) for a cloud-init password. " \
                   "Prefer #{ENV_CIPASSWORD} in the environment.",
      boolean:     true

    # --- Timeouts ---------------------------------------------------------

    option :clone_timeout,
      long:        "--clone-timeout SECONDS",
      description: "Seconds to wait for the clone task (default 600).",
      default:     600

    option :boot_timeout,
      long:        "--boot-timeout SECONDS",
      description: "Seconds to wait for the guest to boot and open SSH (default 300).",
      default:     300
  end
end