Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto set vmid when creating host from Foreman API #312

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/models/foreman_fog_proxmox/proxmox_vm_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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=%<vmid>s'), vmid: vmid) unless node.servers.id_valid?(vmid)

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