Module: ProxmoxVmHelper
- Included in:
- ForemanFogProxmox::Proxmox
- Defined in:
- app/helpers/proxmox_vm_helper.rb
Constant Summary collapse
Instance Method Summary collapse
- #add_cdrom_to_config_server(vm, config) ⇒ Object
- #convert_memory_size(config_hash, key) ⇒ Object
- #convert_sizes(args) ⇒ Object
- #disk_to_cdrom(disk, cdrom) ⇒ Object
- #object_to_config_hash(vm, type) ⇒ Object
- #remove_deletes(args) ⇒ Object
Instance Method Details
#add_cdrom_to_config_server(vm, config) ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/helpers/proxmox_vm_helper.rb', line 43 def add_cdrom_to_config_server(vm,config) cd_disks = vm.config.disks.select { |disk| disk.id == 'ide2' } cdrom = {} disk_to_cdrom(cd_disks.first,cdrom) config = config.merge(cdrom) config end |
#convert_memory_size(config_hash, key) ⇒ Object
75 76 77 78 79 |
# File 'app/helpers/proxmox_vm_helper.rb', line 75 def convert_memory_size(config_hash, key) # default unit memory size is Mb memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s config_hash.store(key, memory) end |
#convert_sizes(args) ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/helpers/proxmox_vm_helper.rb', line 63 def convert_sizes(args) convert_memory_size(args['config_attributes'],'memory') convert_memory_size(args['config_attributes'],'min_memory') convert_memory_size(args['config_attributes'],'shares') convert_memory_size(args['config_attributes'],'swap') args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) } end |
#disk_to_cdrom(disk, cdrom) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/proxmox_vm_helper.rb', line 51 def disk_to_cdrom(disk,cdrom) volid = disk.volid cdrom_a = %w[none cdrom] if cdrom_a.include? volid cdrom.store('cdrom',volid) else cdrom.store('cdrom','image') cdrom.store('cdrom_iso',volid) cdrom.store('cdrom_storage',disk.storage) end end |
#object_to_config_hash(vm, type) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/proxmox_vm_helper.rb', line 30 def object_to_config_hash(vm,type) vm_h = ActiveSupport::HashWithIndifferentAccess.new main_a = %w[hostname name vmid] type = vm.config.attributes['type'] type = vm.type unless type main = vm.attributes.select { |key,_value| main_a.include? key } main_a += %w[templated] config = vm.config.attributes.reject { |key,_value| main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key) } vm_h = vm_h.merge(main) vm_h = vm_h.merge({'config_attributes': config}) vm_h end |
#remove_deletes(args) ⇒ Object
71 72 73 |
# File 'app/helpers/proxmox_vm_helper.rb', line 71 def remove_deletes(args) args['volumes_attributes'].delete_if { |_key,value| value.has_key? '_delete' } if args['volumes_attributes'] end |