From 3bde0b2bc364706356ba5803b18f4f0f72a1bb8b Mon Sep 17 00:00:00 2001 From: Manisha Singhal Date: Mon, 12 Feb 2024 09:05:34 +0100 Subject: [PATCH] fix: auto set vmid when creating host from Foreman API fixes #254 --- app/models/foreman_fog_proxmox/proxmox_vm_commands.rb | 6 ++++-- 1 file changed, 4 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..a00d811b3 100644 --- a/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +++ b/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb @@ -31,11 +31,12 @@ def start_on_boot(vm, args) vm end + # rubocop:disable Metrics/AbcSize 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 = node.servers.next_id.to_i if args[:vmid].to_i < 1 || args[:vmid].nil? + args[:vmid] = vmid if args[:vmid].nil? raise ::Foreman::Exception, format(N_('invalid vmid=%s'), vmid: vmid) unless node.servers.id_valid?(vmid) image_id = args[:image_id] @@ -54,6 +55,7 @@ def create_vm(args = {}) destroy_vm id.to_s + '_' + vm.vmid.to_s if vm raise e end + # rubocop:enable Metrics/AbcSize def compute_clone_attributes(args, container, type) args = parse_cloudinit_config(args) if args[:user_data]