Class: Pvectl::Commands::SetVm

Inherits:
Object
  • Object
show all
Includes:
SetResourceCommand
Defined in:
lib/pvectl/commands/set_vm.rb

Overview

Handler for the ‘pvectl set vm` command.

Includes SetResourceCommand for shared workflow and overrides template methods with VM-specific behavior.

Also registers the top-level ‘set` command with all resource types.

Examples:

Basic usage

pvectl set vm 100 memory=4096 cores=2

Dry-run mode

pvectl set vm 100 memory=8192 --dry-run

Class Method Summary collapse

Methods included from SetResourceCommand

#execute, included, #initialize

Class Method Details

.register(cli) ⇒ void

This method returns an undefined value.

Registers the set command with the CLI.

Parameters:

  • cli (GLI::App)

    the CLI application object



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
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
# File 'lib/pvectl/commands/set_vm.rb', line 25

def self.register(cli)
  cli.desc "Set a resource property (non-interactive)"
  cli.long_desc <<~HELP
    Set configuration properties on a resource without opening an editor.
    Accepts key=value pairs as arguments. This is the non-interactive
    counterpart to the edit command.

    EXAMPLES
      Set VM memory and CPU:
        $ pvectl set vm 100 memory=4096 cores=2

      Set container hostname:
        $ pvectl set container 200 hostname=web01

      Resize a volume:
        $ pvectl set volume vm 100 scsi0 size=+10G

      Set volume cache mode:
        $ pvectl set volume vm 100 scsi0 cache=writeback

      Set node description:
        $ pvectl set node pve1 description="Production node"

      Change node timezone:
        $ pvectl set node pve1 timezone=Europe/Warsaw

      Preview changes without applying:
        $ pvectl set vm 100 memory=8192 --dry-run

    NOTES
      Volume resize (size=) is irreversible. A confirmation prompt is shown
      unless --yes is specified.

      Keys are passed directly to the Proxmox API. Use Proxmox documentation
      to find valid configuration keys for each resource type.

    SEE ALSO
      pvectl help edit        Interactive configuration editor
      pvectl help describe    View current configuration
  HELP
  cli.arg_name "RESOURCE_TYPE RESOURCE_ID [SUB_ID] KEY=VALUE [KEY=VALUE ...]"
  cli.command :set do |c|
    c.desc "Skip confirmation prompt"
    c.switch [:yes, :y], negatable: false

    c.desc "Target node name"
    c.flag [:node, :n], arg_name: "NODE"

    c.desc "Show diff without applying changes"
    c.switch [:"dry-run"], negatable: false

    c.action do |global_options, options, args|
      resource_type = args.shift

      exit_code = case resource_type
      when "vm"
        Commands::SetVm.execute(args, options, global_options)
      when "container", "ct"
        Commands::SetContainer.execute(args, options, global_options)
      when "volume", "vol"
        Commands::SetVolume.execute(args, options, global_options)
      when "node"
        Commands::SetNode.execute(args, options, global_options)
      when nil
        $stderr.puts "Error: Resource type required (vm, container, volume, node)"
        ExitCodes::USAGE_ERROR
      else
        $stderr.puts "Error: Unknown resource type: #{resource_type}"
        $stderr.puts "Valid types: vm, container, volume, node"
        ExitCodes::USAGE_ERROR
      end

      exit exit_code if exit_code != 0
    end
  end
end