diff --git a/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb b/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb index 0a94aa436..6d2037b75 100644 --- a/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +++ b/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb @@ -45,7 +45,7 @@ def create_vm(args = {}) update_pool(vm, args[:pool]) if args[:pool] else logger.warn("create vm: args=#{args}") - vm = node.send(vm_collection(type)).create(parse_typed_vm(args, type)) + vm = node.send(vm_collection(type)).create(parse_typed_vm(update_extra_volumes_definitions(args), type)) end start_on_boot(vm, args) rescue StandardError => e diff --git a/app/models/foreman_fog_proxmox/proxmox_vm_new.rb b/app/models/foreman_fog_proxmox/proxmox_vm_new.rb index ac0a6900b..d79b20802 100644 --- a/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +++ b/app/models/foreman_fog_proxmox/proxmox_vm_new.rb @@ -161,7 +161,7 @@ def config_attributes(type = 'qemu') end def new_vm(new_attr = {}) - new_attr = ActiveSupport::HashWithIndifferentAccess.new(new_attr) + new_attr = ActiveSupport::HashWithIndifferentAccess.new(update_extra_volumes_definitions(new_attr)) type = new_attr['type'] type ||= 'qemu' new_typed_vm(new_attr, type) diff --git a/app/models/foreman_fog_proxmox/proxmox_volumes.rb b/app/models/foreman_fog_proxmox/proxmox_volumes.rb index 693e2e22b..aa72dc600 100644 --- a/app/models/foreman_fog_proxmox/proxmox_volumes.rb +++ b/app/models/foreman_fog_proxmox/proxmox_volumes.rb @@ -24,6 +24,43 @@ module ForemanFogProxmox module ProxmoxVolumes include ProxmoxVMHelper + def update_extra_volumes_definitions(data_in) + new_data = {} + data_in.each do |key,value| + if key != 'volumes_attributes' + new_data[key] = value + else + # Start to look into the data that needs to be updated + volumes_attributes = {} + value.each do |index,dev_specs| + nr_of_keys_found = dev_specs.keys.count + + # Only if this contains only 1 set like: {"size"=>"xxGB"} + if #{index} > 0 && nr_of_keys_found == 1 + + # Copy the data from the first entry + newid = "#{value['0']['controller']}#{index}" + newdev = { + 'storage_type' => value['0']['storage_type'], + 'storage' => value['0']['storage'], + 'controller' => value['0']['controller'], + 'cache' => value['0']['cache'], + 'device' => index, + 'id' => newid, + 'size' => dev_specs['size'], + } + volumes_attributes[index] = newdev + else + volumes_attributes[index] = dev_specs + end + end + # now add the (reworked) data back + new_data['volumes_attributes'] = volumes_attributes + end + end + return new_data + end + def delete_volume(vm, id, volume_attributes) logger.info("vm #{vm.identity} delete volume #{id}") vm.detach(id)