diff --git a/app/helpers/proxmox_vm_attrs_helper.rb b/app/helpers/proxmox_vm_attrs_helper.rb index 3c30622db..cb4e2a9f4 100644 --- a/app/helpers/proxmox_vm_attrs_helper.rb +++ b/app/helpers/proxmox_vm_attrs_helper.rb @@ -47,7 +47,7 @@ def object_to_attributes_hash(vms, from_profile, start_checked) def cpu_flags_attrs(param_scope, config) flag_attrs = ActiveSupport::HashWithIndifferentAccess.new - Fog::Proxmox::CpuHelper.flags.each do |key, _val| + Fog::Proxmox::CpuHelper.flags.each_key do |key| flag_attrs.merge!({ key => { :name => "#{param_scope}[config_attributes][#{key}]", :value => config.public_send(key) } }) end flag_attrs @@ -62,7 +62,7 @@ def volumes_attrs(param_scope, volumes) keys = ['id', 'volid', 'storage', 'size', 'storage_type'] type = 'rootfs' elsif vol.hard_disk? - keys = ['id', 'volid', 'storage_type', 'storage', 'controller', 'device', 'cache', 'size'] + keys = ['id', 'volid', 'storage_type', 'storage', 'controller', 'device', 'cache', 'backup', 'size'] type = 'hard_disk' elsif vol.cdrom? keys = ['id', 'storage_type', 'cdrom', 'storage', 'volid'] diff --git a/app/helpers/proxmox_vm_volumes_helper.rb b/app/helpers/proxmox_vm_volumes_helper.rb index 146d911d7..94996248b 100644 --- a/app/helpers/proxmox_vm_volumes_helper.rb +++ b/app/helpers/proxmox_vm_volumes_helper.rb @@ -55,8 +55,12 @@ def parse_hard_disk_volume(args) disk[:volid] = args['volid'] if args.key?('volid') && !args['volid'].empty? disk[:storage] = args['storage'].to_s if args.key?('storage') && !args['storage'].empty? disk[:size] = args['size'].to_i if args.key?('size') && !args['size'].empty? - add_disk_options(disk, args) unless args.key?('options') - disk[:options] = args['options'] if args.key?('options') + args['backup'] = '1' if args['backup'].nil? + if args.key?('options') + disk[:options] = args['options'] + else + add_disk_options(disk, args) + end disk.key?(:storage) ? disk : {} end diff --git a/app/models/concerns/host_ext/proxmox/interfaces.rb b/app/models/concerns/host_ext/proxmox/interfaces.rb index fbc633a8d..6685af1dc 100644 --- a/app/models/concerns/host_ext/proxmox/interfaces.rb +++ b/app/models/concerns/host_ext/proxmox/interfaces.rb @@ -49,12 +49,11 @@ def cidr_ip(interface_attributes, v = 4) def add_interface_to_compute_attributes(index, interface_attributes, compute_attributes) compute_attributes[index] = {} - compute_attributes[index].store('id', interface_attributes['identifier']) compute_attributes[index].store('_delete', interface_attributes['_destroy']) compute_attributes[index].store('macaddr', interface_attributes['mac']) compute_attributes[index].store('ip', cidr_ip(interface_attributes)) compute_attributes[index].store('ip6', cidr_ip(interface_attributes, 6)) - compute_attributes[index].merge!(interface_attributes['compute_attributes'].reject { |k, _v| k == 'id' }) + compute_attributes[index].merge(interface_attributes['compute_attributes']) end end end diff --git a/app/models/foreman_fog_proxmox/proxmox_interfaces.rb b/app/models/foreman_fog_proxmox/proxmox_interfaces.rb index 7f5a1a665..9d98125a5 100644 --- a/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +++ b/app/models/foreman_fog_proxmox/proxmox_interfaces.rb @@ -118,7 +118,7 @@ def dhcp?(nic_compute_attributes, v6 = false) def set_mac(nic_compute_attributes, mac, type) mac_attr_name = { 'qemu' => :macaddr, 'lxc' => :hwaddr } mac_key = mac_attr_name[type] || 'mac' - nic_compute_attributes[mac_key] = Net::Validations.normalize_mac(mac).upcase + nic_compute_attributes[mac_key] = Net::Validations.normalize_mac(mac) end def host_interfaces_attrs(host) diff --git a/app/models/foreman_fog_proxmox/proxmox_vm_new.rb b/app/models/foreman_fog_proxmox/proxmox_vm_new.rb index ac0a6900b..dd369f546 100644 --- a/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +++ b/app/models/foreman_fog_proxmox/proxmox_vm_new.rb @@ -42,7 +42,7 @@ def hard_disk_typed_defaults(vm_type) controller = 'virtio' device = 0 id = "#{controller}#{device}" - options = { cache: 'none' } + options = { cache: 'none', backup: '1' } volume_attributes_h = volume_attributes_h.merge(controller: controller, device: device) when 'lxc' id = 'rootfs' diff --git a/app/models/foreman_fog_proxmox/proxmox_volumes.rb b/app/models/foreman_fog_proxmox/proxmox_volumes.rb index 693e2e22b..f9e8c99eb 100644 --- a/app/models/foreman_fog_proxmox/proxmox_volumes.rb +++ b/app/models/foreman_fog_proxmox/proxmox_volumes.rb @@ -35,8 +35,10 @@ def delete_volume(vm, id, volume_attributes) def volume_options(vm, id, volume_attributes) options = {} + volume_attributes['backup'] = '1' if volume_attributes['backup'].empty? options.store(:mp, volume_attributes['mp']) if vm.container? && id != 'rootfs' options.store(:cache, volume_attributes['cache']) unless vm.container? || volume_attributes['cache'].empty? + options.store(:backup, volume_attributes['backup']) unless vm.container? || volume_attributes['backup'].empty? options end diff --git a/app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb b/app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb index d648f4a58..42c165242 100644 --- a/app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb +++ b/app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb @@ -32,4 +32,5 @@ along with ForemanFogProxmox. If not, see . %> <%= select_f f, :cache, proxmox_caches_map, :id, :name, { include_blank: true }, :label => _('Cache'), :label_size => "col-md-2" %> <%= text_f f, :size, :class => "input-mini", :label => _("Size (GB)"), :label_size => "col-md-2", :disabled => !hard_disk %> + <%= checkbox_f f, :backup, :checked => (f.object.backup == '1' || f.object.backup.nil? ), :label => _('Backup'), :label_help => _('Enable/disable volume backup') %> <% end %> diff --git a/webpack/components/ProxmoxComputeSelectors.js b/webpack/components/ProxmoxComputeSelectors.js index 784b005fe..093c58ef7 100644 --- a/webpack/components/ProxmoxComputeSelectors.js +++ b/webpack/components/ProxmoxComputeSelectors.js @@ -74,6 +74,11 @@ const ProxmoxComputeSelectors = { { value: 'none', label: 'No cache' }, ], + proxmoxBackupsMap: [ + { value: '1', label: 'Yes' }, + { value: '0', label: 'No' }, + ], + proxmoxCpusMap: [ { value: 'athlon', label: 'athlon' }, { value: 'EPYC', label: 'EPYC' }, diff --git a/webpack/components/ProxmoxServer/ProxmoxServerStorage.js b/webpack/components/ProxmoxServer/ProxmoxServerStorage.js index b57afa47d..09a78e8bb 100644 --- a/webpack/components/ProxmoxServer/ProxmoxServerStorage.js +++ b/webpack/components/ProxmoxServer/ProxmoxServerStorage.js @@ -123,6 +123,10 @@ const ProxmoxServerStorage = ({ storage, storages, paramScope, nodeId }) => { name: `${paramScope}[volumes_attributes][${nextId}][cache]`, value: null, }, + backup: { + name: `${paramScope}[volumes_attributes][${nextId}][backup]`, + value: 1, + }, size: { name: `${paramScope}[volumes_attributes][${nextId}][size]`, value: 8, diff --git a/webpack/components/ProxmoxServer/components/HardDisk.js b/webpack/components/ProxmoxServer/components/HardDisk.js index f9cda5e28..9b1600a49 100644 --- a/webpack/components/ProxmoxServer/components/HardDisk.js +++ b/webpack/components/ProxmoxServer/components/HardDisk.js @@ -29,7 +29,6 @@ const HardDisk = ({ const handleChange = e => { const { name, value } = e.target; const updatedKey = Object.keys(hdd).find(key => hdd[key].name === name); - if (updatedKey === 'controller') { const updatedDeviceInfo = createUniqueDevice('hard_disk', value); if (updatedDeviceInfo) { @@ -118,6 +117,14 @@ const HardDisk = ({ options={ProxmoxComputeSelectors.proxmoxCachesMap} onChange={handleChange} /> +