Class: Pvectl::Services::CreateVm
- Inherits:
-
Object
- Object
- Pvectl::Services::CreateVm
- Defined in:
- lib/pvectl/services/create_vm.rb
Overview
Orchestrates VM creation operations.
Handles auto-VMID allocation, parameter building (mapping disk/net/cloud-init configs to Proxmox API format), sync/async modes, and optional auto-start.
Constant Summary collapse
- DEFAULT_TIMEOUT =
Returns Default timeout for create operations (seconds).
300- START_TIMEOUT =
Returns Default timeout for start operations (seconds).
60
Instance Method Summary collapse
-
#execute(vmid: nil, name:, node:, cores: nil, sockets: nil, cpu_type: nil, numa: nil, memory: nil, balloon: nil, disks: nil, scsihw: nil, cdrom: nil, nets: nil, bios: nil, boot_order: nil, machine: nil, efidisk: nil, cloud_init: nil, agent: nil, ostype: nil, description: nil, tags: nil, pool: nil) ⇒ Models::VmOperationResult
Executes VM creation operation.
-
#initialize(vm_repository:, task_repository:, options: {}) ⇒ CreateVm
constructor
Creates a new CreateVm service.
Constructor Details
#initialize(vm_repository:, task_repository:, options: {}) ⇒ CreateVm
Creates a new CreateVm service.
34 35 36 37 38 |
# File 'lib/pvectl/services/create_vm.rb', line 34 def initialize(vm_repository:, task_repository:, options: {}) @vm_repository = vm_repository @task_repository = task_repository @options = end |
Instance Method Details
#execute(vmid: nil, name:, node:, cores: nil, sockets: nil, cpu_type: nil, numa: nil, memory: nil, balloon: nil, disks: nil, scsihw: nil, cdrom: nil, nets: nil, bios: nil, boot_order: nil, machine: nil, efidisk: nil, cloud_init: nil, agent: nil, ostype: nil, description: nil, tags: nil, pool: nil) ⇒ Models::VmOperationResult
Executes VM creation operation.
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 |
# File 'lib/pvectl/services/create_vm.rb', line 66 def execute(vmid: nil, name:, node:, cores: nil, sockets: nil, cpu_type: nil, numa: nil, memory: nil, balloon: nil, disks: nil, scsihw: nil, cdrom: nil, nets: nil, bios: nil, boot_order: nil, machine: nil, efidisk: nil, cloud_init: nil, agent: nil, ostype: nil, description: nil, tags: nil, pool: nil) vmid ||= @vm_repository.next_available_vmid params = build_params( name: name, cores: cores, sockets: sockets, cpu_type: cpu_type, numa: numa, memory: memory, balloon: balloon, disks: disks, scsihw: scsihw, cdrom: cdrom, nets: nets, bios: bios, boot_order: boot_order, machine: machine, efidisk: efidisk, cloud_init: cloud_init, agent: agent, ostype: ostype, description: description, tags: , pool: pool ) upid = @vm_repository.create(node, vmid, params) resource_info = { vmid: vmid, name: name, node: node } if @options[:async] build_result(resource_info, task_upid: upid, success: :pending) else task = @task_repository.wait(upid, timeout: timeout) start_vm(vmid, node) if task.successful? && @options[:start] build_result(resource_info, task: task, success: task.successful?) end rescue StandardError => e build_result({ vmid: vmid, name: name, node: node }, success: false, error: e.) end |