Skip to content

Commit

Permalink
fix: auto set vmid when creating host from Foreman API
Browse files Browse the repository at this point in the history
fixes #254
  • Loading branch information
Manisha15 committed Feb 12, 2024
1 parent eb652d7 commit 3bde0b2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/foreman_fog_proxmox/proxmox_vm_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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=%<vmid>s'), vmid: vmid) unless node.servers.id_valid?(vmid)

image_id = args[:image_id]
Expand All @@ -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]
Expand Down

0 comments on commit 3bde0b2

Please sign in to comment.