Class: Pvectl::Commands::EditVm
- Inherits:
-
Object
- Object
- Pvectl::Commands::EditVm
- Includes:
- EditResourceCommand
- Defined in:
- lib/pvectl/commands/edit_vm.rb,
sig/pvectl/commands/edit_vm.rbs
Overview
Handler for the pvectl edit vm command.
Includes EditResourceCommand for shared workflow and overrides template methods with VM-specific behavior.
Class Method Summary collapse
-
.register(cli) ⇒ void
Registers the edit command with the CLI.
Instance Method Summary collapse
-
#build_edit_service(connection) ⇒ Services::EditVm
Builds the VM edit service.
-
#execute_params(resource_id) ⇒ Hash
Builds execution parameters from a VM ID.
-
#resource_id_label ⇒ String
Human label for VM IDs.
-
#resource_label ⇒ String
Human label for VM resources.
Methods included from EditResourceCommand
#build_editor_session, #display_diff, #execute, included, #initialize, #load_config, #service_options, #usage_error
Class Method Details
.register(cli) ⇒ void
This method returns an undefined value.
Registers the edit command with the CLI.
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/pvectl/commands/edit_vm.rb', line 26 def self.register(cli) cli.desc "Edit a resource configuration" cli.long_desc <<~HELP Open a VM, container, node, or volume configuration in your text editor. The configuration is presented as YAML for easy editing. Changes are applied via the Proxmox API when you save and close the editor. EXAMPLES Edit a VM configuration: $ pvectl edit vm 100 Edit a container with a specific editor: $ pvectl edit container 200 --editor nano Edit a node configuration: $ pvectl edit node pve1 Edit node DNS resolver settings: $ pvectl edit dns pve1 Edit volume properties: $ pvectl edit volume vm 100 scsi0 Edit /etc/hosts on a node: $ pvectl edit hosts pve1 Preview changes without applying: $ pvectl edit vm 100 --dry-run NOTES Uses $EDITOR environment variable by default, falling back to vi. Override with --editor flag. In --dry-run mode, shows the diff between current and edited configuration without applying changes to Proxmox. Supported resource types: vm, container (ct), node, volume, dns, hosts. For DNS, the node identifier is given as a positional argument (pvectl edit dns NODE). DNS settings include search domain and up to three nameservers (dns1, dns2, dns3). For volumes, syntax is: pvectl edit volume <vm|container> <id> <disk> For hosts, the node identifier is given as a positional argument (pvectl edit hosts NODE). The /etc/hosts file is edited as raw text — Proxmox requires the pvelocalhost entry to remain present and will reject updates removing it. Not all configuration keys can be changed while a VM is running. Proxmox will reject invalid changes with an error message. SEE ALSO pvectl help describe View current configuration (read-only) pvectl help create Create a new resource pvectl help set Set individual resource properties HELP cli.arg_name "RESOURCE_TYPE RESOURCE_ID" cli.command :edit do |c| c.desc "Override editor command (default: $EDITOR or vi)" c.flag [:editor], arg_name: "CMD" c.desc "Show diff without applying changes" c.switch [:"dry-run"], negatable: false c.action do |, , args| resource_type = args.shift resource_ids = args exit_code = case resource_type when "vm" Commands::EditVm.execute(resource_ids, , ) when "container", "ct" Commands::EditContainer.execute(resource_ids, , ) when "node" Commands::EditNode.execute(resource_ids, , ) when "volume" Commands::EditVolume.execute(resource_ids, , ) when "dns" Commands::EditDns.execute(resource_ids, , ) when "hosts" Commands::EditHosts.execute(resource_ids, , ) else $stderr.puts "Error: Unknown resource type: #{resource_type}" $stderr.puts "Valid types: vm, container, node, volume, dns, hosts" ExitCodes::USAGE_ERROR end exit exit_code if exit_code != 0 end end end |
Instance Method Details
#build_edit_service(connection) ⇒ Services::EditVm
Builds the VM edit service.
144 145 146 147 148 149 150 151 |
# File 'lib/pvectl/commands/edit_vm.rb', line 144 def build_edit_service(connection) vm_repo = Pvectl::Repositories::Vm.new(connection) Pvectl::Services::EditVm.new( vm_repository: vm_repo, editor_session: build_editor_session, options: ) end |
#execute_params(resource_id) ⇒ Hash
Builds execution parameters from a VM ID.
136 137 138 |
# File 'lib/pvectl/commands/edit_vm.rb', line 136 def execute_params(resource_id) { vmid: resource_id.to_i } end |
#resource_id_label ⇒ String
Returns human label for VM IDs.
128 129 130 |
# File 'lib/pvectl/commands/edit_vm.rb', line 128 def resource_id_label "VMID" end |
#resource_label ⇒ String
Returns human label for VM resources.
123 124 125 |
# File 'lib/pvectl/commands/edit_vm.rb', line 123 def resource_label "VM" end |