Skip to content

Commit

Permalink
added taking over incomplete volume parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees van Veen committed Oct 6, 2024
1 parent c237bc0 commit 0c9c260
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
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
37 changes: 37 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,43 @@ module ForemanFogProxmox
module ProxmoxVolumes
include ProxmoxVMHelper

def update_extra_volumes_definitions(data_in)
new_data = {}
data_in.each do |key,value|

Check failure on line 29 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/SpaceAfterComma: Space missing after comma.
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|

Check failure on line 35 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/SpaceAfterComma: Space missing after comma.
nr_of_keys_found = dev_specs.keys.count

Check failure on line 36 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Lint/UselessAssignment: Useless assignment to variable - `nr_of_keys_found`.

# Only if this contains only 1 set like: {"size"=>"xxGB"}
if #{index} > 0 && nr_of_keys_found == 1

Check failure on line 39 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/LeadingCommentSpace: Missing space after `#`.

# Copy the data from the first entry
newid = "#{value['0']['controller']}#{index}"

Check failure on line 42 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/ConditionPosition: Place the condition on the same line as `if`.

Check failure on line 42 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Lint/AssignmentInCondition: Use `==` if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
newdev = {
'storage_type' => value['0']['storage_type'],
'storage' => value['0']['storage'],

Check failure on line 45 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
'controller' => value['0']['controller'],

Check failure on line 46 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
'cache' => value['0']['cache'],

Check failure on line 47 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
'device' => index,

Check failure on line 48 in app/models/foreman_fog_proxmox/proxmox_volumes.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
'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)
Expand Down

0 comments on commit 0c9c260

Please sign in to comment.