From edc4a0c93a5a1d5c0ed336174147a62cbc241e86 Mon Sep 17 00:00:00 2001 From: Manisha Singhal Date: Thu, 29 Feb 2024 12:20:17 +0530 Subject: [PATCH] fix: auto set vmid when creating host from Foreman API (#312) fixes #254 --- app/models/foreman_fog_proxmox/proxmox_vm_commands.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb b/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb index 8287cb81f..7cf90de20 100644 --- a/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +++ b/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb @@ -32,10 +32,9 @@ def start_on_boot(vm, args) end def create_vm(args = {}) - vmid = args[:vmid].to_i type = args[:type] node = client.nodes.get(args[:node_id]) - vmid = node.servers.next_id.to_i if vmid < 1 + vmid = args[:vmid] = assign_vmid(args[:vmid].to_i, node) raise ::Foreman::Exception, format(N_('invalid vmid=%s'), vmid: vmid) unless node.servers.id_valid?(vmid) image_id = args[:image_id] @@ -55,6 +54,10 @@ def create_vm(args = {}) raise e end + def assign_vmid(vmid, node) + vmid < 1 ? node.servers.next_id : vmid + end + def compute_clone_attributes(args, container, type) args = parse_cloudinit_config(args) if args[:user_data] parsed_args = parse_typed_vm(args, type)