Class: Pvectl::Services::Sendkey
- Inherits:
-
Object
- Object
- Pvectl::Services::Sendkey
- Defined in:
- lib/pvectl/services/sendkey.rb
Overview
Orchestrates QEMU monitor key-send operations for a single VM.
Resolves the VM (and its node) via the repository, validates that the target VM is running, and forwards the key sequence verbatim to the Proxmox API. The key string is passed through unmodified — interpretation is delegated to QEMU’s qcode parser.
Instance Method Summary collapse
-
#execute(vmid:, key:, node: nil) ⇒ Models::VmOperationResult
Sends a QEMU key sequence to a VM.
-
#initialize(vm_repository:) ⇒ Sendkey
constructor
Creates a new Sendkey service.
Constructor Details
#initialize(vm_repository:) ⇒ Sendkey
Creates a new Sendkey service.
21 22 23 |
# File 'lib/pvectl/services/sendkey.rb', line 21 def initialize(vm_repository:) @vm_repository = vm_repository end |
Instance Method Details
#execute(vmid:, key:, node: nil) ⇒ Models::VmOperationResult
Sends a QEMU key sequence to a VM.
Looks up the VM (the node kwarg is honored when provided, otherwise the node is taken from the resolved VM). Returns a failed VmOperationResult when the VM cannot be found, is not running, or the underlying API call raises.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pvectl/services/sendkey.rb', line 36 def execute(vmid:, key:, node: nil) vmid_int = vmid.to_i vm = @vm_repository.get(vmid_int) return not_found_result(vmid_int) unless vm target_node = node || vm.node return not_running_result(vm, target_node, key) unless vm.status == "running" @vm_repository.sendkey(vmid_int, target_node, key) success_result(vm, target_node, key) rescue StandardError => e failure_result(vm, target_node || vm&.node, key, e.) end |