Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_vm_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_vm_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions app/models/foreman_fog_proxmox/proxmox_volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,40 @@ 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|
# Only if this contains only 1 set like: {"size"=>"xxGB"}
if index > 0 && dev_specs.keys.count == 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
new_data
end

def delete_volume(vm, id, volume_attributes)
logger.info("vm #{vm.identity} delete volume #{id}")
vm.detach(id)
Expand Down