Class: Pvectl::Commands::Cloudinit::Regenerate

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/commands/cloudinit/regenerate.rb

Overview

Handler for the ‘pvectl cloudinit regenerate vm <id>` subcommand.

Triggers Proxmox to rebuild the cloud-init ISO from the current VM configuration. The operation is synchronous on the Proxmox side and returns null on success.

Examples:

Usage

pvectl cloudinit regenerate vm 100
pvectl cloudinit regenerate vm 100 --node pve2

Class Method Summary collapse

Class Method Details

.execute(args, options, global_options) ⇒ Integer

Executes the regenerate subcommand.

Parameters:

  • args (Array<String>)

    command arguments (RESOURCE_TYPE, ID)

  • options (Hash)

    command-local options (:node)

  • global_options (Hash)

    global CLI options

Returns:

  • (Integer)

    exit code



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/pvectl/commands/cloudinit/regenerate.rb', line 63

def self.execute(args, options, global_options)
  resource_type = args[0]
  vmid_arg = args[1]

  return Cloudinit.usage_error("Resource type required (vm)") unless resource_type
  return Cloudinit.usage_error("VMID is required") unless vmid_arg
  return Cloudinit.unknown_resource_type(resource_type) unless resource_type == "vm"

  Cloudinit.with_service(global_options) do |service|
    result = service.regenerate(vmid_arg.to_i, node: options[:node])
    $stdout.puts "Cloud-init ISO regenerated for VM #{result[:vmid]} on #{result[:node]}."
  end
end

.register_subcommand(parent) ⇒ void

This method returns an undefined value.

Registers the regenerate subcommand under the cloudinit parent.

Parameters:

  • parent (GLI::Command)

    parent cloudinit command



21
22
23
24
25
26
27
28
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
# File 'lib/pvectl/commands/cloudinit/regenerate.rb', line 21

def self.register_subcommand(parent)
  parent.desc "Regenerate the cloud-init ISO for a VM"
  parent.long_desc <<~HELP
    DESCRIPTION
      Rebuild the cloud-init configuration drive (ISO) for a VM from
      the current Proxmox configuration. This is required after
      editing cloud-init-related options (user, ipconfig, sshkeys, etc.)
      for the changes to take effect inside the guest on next boot.

    EXAMPLES
      Regenerate cloud-init for VM 100:
        $ pvectl cloudinit regenerate vm 100

      Skip VMID lookup by passing the node explicitly:
        $ pvectl cloudinit regenerate vm 100 --node pve2

    NOTES
      Cloud-init is a VM-only feature — LXC containers do not expose
      cloud-init endpoints.

      The VM does NOT need to be running. The regenerated ISO will
      be picked up at the next guest reboot.

    SEE ALSO
      pvectl help cloudinit pending   Show pending cloud-init changes
      pvectl help cloudinit dump      Inspect generated cloud-init YAML
  HELP
  parent.arg_name "RESOURCE_TYPE ID"
  parent.command :regenerate do |c|
    c.action do |global_options, options, args|
      exit_code = execute(args, options, global_options)
      exit exit_code if exit_code != 0
    end
  end
end