Class: Pvectl::Commands::SetVm

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

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

Instance Method Summary collapse

Methods included from SetResourceCommand

#display_diff, #execute, included, #initialize, #load_config, #parse_key_values, #service_options, #usage_error

Class Method Details

.register(cli) ⇒ void

This method returns an undefined value.

Registers the set command with the CLI.



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 "    Set configuration properties on a resource without opening an editor.\n    Accepts key=value pairs as arguments. This is the non-interactive\n    counterpart to the edit command.\n\n    EXAMPLES\n      Set VM memory and CPU:\n        $ pvectl set vm 100 memory=4096 cores=2\n\n      Set container hostname:\n        $ pvectl set container 200 hostname=web01\n\n      Resize a volume:\n        $ pvectl set volume vm 100 scsi0 size=+10G\n\n      Set volume cache mode:\n        $ pvectl set volume vm 100 scsi0 cache=writeback\n\n      Set node description:\n        $ pvectl set node pve1 description=\"Production node\"\n\n      Change node timezone:\n        $ pvectl set node pve1 timezone=Europe/Warsaw\n\n      Preview changes without applying:\n        $ pvectl set vm 100 memory=8192 --dry-run\n\n    NOTES\n      Volume resize (size=) is irreversible. A confirmation prompt is shown\n      unless --yes is specified.\n\n      Keys are passed directly to the Proxmox API. Use Proxmox documentation\n      to find valid configuration keys for each resource type.\n\n    SEE ALSO\n      pvectl help edit        Interactive configuration editor\n      pvectl help describe    View current configuration\n  HELP\n  cli.arg_name \"RESOURCE_TYPE RESOURCE_ID [SUB_ID] KEY=VALUE [KEY=VALUE ...]\"\n  cli.command :set do |c|\n    c.desc \"Skip confirmation prompt\"\n    c.switch [:yes, :y], negatable: false\n\n    c.desc \"Target node name\"\n    c.flag [:node, :n], arg_name: \"NODE\"\n\n    c.desc \"Show diff without applying changes\"\n    c.switch [:\"dry-run\"], negatable: false\n\n    c.action do |global_options, options, args|\n      resource_type = args.shift\n\n      exit_code = case resource_type\n      when \"vm\"\n        Commands::SetVm.execute(args, options, global_options)\n      when \"container\", \"ct\"\n        Commands::SetContainer.execute(args, options, global_options)\n      when \"volume\", \"vol\"\n        Commands::SetVolume.execute(args, options, global_options)\n      when \"node\"\n        Commands::SetNode.execute(args, options, global_options)\n      when nil\n        $stderr.puts \"Error: Resource type required (vm, container, volume, node)\"\n        ExitCodes::USAGE_ERROR\n      else\n        $stderr.puts \"Error: Unknown resource type: \#{resource_type}\"\n        $stderr.puts \"Valid types: vm, container, volume, node\"\n        ExitCodes::USAGE_ERROR\n      end\n\n      exit exit_code if exit_code != 0\n    end\n  end\nend\n"

Instance Method Details

#build_set_service(connection) ⇒ Services::SetVm

Builds the VM set service.



127
128
129
130
131
132
133
# File 'lib/pvectl/commands/set_vm.rb', line 127

def build_set_service(connection)
  vm_repo = Pvectl::Repositories::Vm.new(connection)
  Pvectl::Services::SetVm.new(
    vm_repository: vm_repo,
    options: service_options
  )
end

#execute_params(resource_id, key_values) ⇒ Hash

Builds execution parameters from a VM ID.



119
120
121
# File 'lib/pvectl/commands/set_vm.rb', line 119

def execute_params(resource_id, key_values)
  { vmid: resource_id.to_i, params: key_values }
end

#resource_id_labelString



110
111
112
# File 'lib/pvectl/commands/set_vm.rb', line 110

def resource_id_label
  "VMID"
end

#resource_labelString



105
106
107
# File 'lib/pvectl/commands/set_vm.rb', line 105

def resource_label
  "VM"
end