Skip to content

Commit

Permalink
Added for backups and to stop always updating proxmox
Browse files Browse the repository at this point in the history
  • Loading branch information
btoneill committed Oct 9, 2024
1 parent 3d7b2d2 commit 05eeaef
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/helpers/proxmox_vm_attrs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmAttrsHelper
module ProxmoxVMAttrsHelper
def object_to_attributes_hash(vms, from_profile, start_checked)
param_scope = from_profile ? "compute_attribute[vm_attrs]" : "host[compute_attributes]"
vm_h = ActiveSupport::HashWithIndifferentAccess.new
Expand Down Expand Up @@ -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', 'backup' ]
keys = ['id', 'volid', 'storage_type', 'storage', 'controller', 'device', 'cache', 'backup', 'size' ]
type = 'hard_disk'
elsif vol.cdrom?
keys = ['id', 'storage_type', 'cdrom', 'storage', 'volid']
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/proxmox_vm_volumes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
require 'foreman_fog_proxmox/hash_collection'

# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmVolumesHelper
include ProxmoxVmCdromHelper
include ProxmoxVmCloudinitHelper
module ProxmoxVMVolumesHelper
include ProxmoxVMCdromHelper
include ProxmoxVMCloudinitHelper

def add_disk_options(disk, args)
options = ForemanFogProxmox::HashCollection.new_hash_reject_keys(args,
Expand Down Expand Up @@ -55,7 +55,7 @@ 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?
args['backup'] = '1' if args.key?('backup') && args['backup'].nil?
args['backup'] = '1' if args['backup'].nil?
add_disk_options(disk, args) unless args.key?('options')
disk[:options] = args['options'] if args.key?('options')
disk.key?(:storage) ? disk : {}
Expand Down
3 changes: 1 addition & 2 deletions app/models/concerns/host_ext/proxmox/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/foreman_fog_proxmox/proxmox_vm_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
require 'foreman_fog_proxmox/hash_collection'

module ForemanFogProxmox
module ProxmoxVmNew
include ProxmoxVmHelper
module ProxmoxVMNew
include ProxmoxVMHelper

def cdrom_defaults
{ storage_type: 'cdrom', id: 'ide2', volid: 'none', media: 'cdrom' }
Expand Down
9 changes: 1 addition & 8 deletions app/models/foreman_fog_proxmox/proxmox_volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

module ForemanFogProxmox
module ProxmoxVolumes
include ProxmoxVmHelper
include ProxmoxVMHelper

def delete_volume(vm, id, volume_attributes)
logger.info("vm #{vm.identity} delete volume #{id}")
Expand All @@ -35,18 +35,11 @@ def delete_volume(vm, id, volume_attributes)

def volume_options(vm, id, volume_attributes)
options = {}
# Default to iothread and backup being enabled, as they are enabled by default
# This will pickup and set value properly if run before this change was
# implemented
volume_attributes['iothread'] = '1' if volume_attributes['iothread'].empty?
volume_attributes['backup'] = '1' if volume_attributes['backup'].empty?
# Fixes issue with cache being blank when it should be 'none' if nothing is selected
volume_attributes['cache'] = 'none' if volume_attributes['cache'].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.store(:iothread, volume_attributes['iothread']) unless vm.container? || volume_attributes['iothread'].empty?
options
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
<%= 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') %>
<%= checkbox_f f, :iothread, :checked => (f.object.iothread== '1' || f.object.iothread.nil? ), :label => _('IO Thread'), :label_help => _('Enable/disable IO Thread') %>
<% end %>
2 changes: 1 addition & 1 deletion lib/foreman_fog_proxmox/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.

module ForemanFogProxmox
VERSION = '0.16.2.3'
VERSION = '0.17.0'
end
5 changes: 5 additions & 0 deletions webpack/components/ProxmoxComputeSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ const ProxmoxComputeSelectors = {
{ value: 'unsafe', label: 'Write back unsafe' },
{ value: 'none', label: 'No cache' },
],

proxmoxBackupsMap: [
{ value: '1', label: 'Yes' },
{ value: '0', label: 'No' },
],

proxmoxCpusMap: [
{ value: 'athlon', label: 'athlon' },
Expand Down
4 changes: 0 additions & 4 deletions webpack/components/ProxmoxServer/ProxmoxServerStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ const ProxmoxServerStorage = ({ storage, storages, paramScope, nodeId }) => {
name: `${paramScope}[volumes_attributes][${nextId}][backup]`,
value: 1,
},
iothread: {
name: `${paramScope}[volumes_attributes][${nextId}][iothread]`,
value: null,
},
size: {
name: `${paramScope}[volumes_attributes][${nextId}][size]`,
value: 8,
Expand Down
16 changes: 3 additions & 13 deletions webpack/components/ProxmoxServer/components/HardDisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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) {
Expand Down Expand Up @@ -121,20 +121,10 @@ const HardDisk = ({
<InputField
name={hdd?.backup?.name}
label={__('Backup')}
type="checkbox"
type="select"
value={hdd?.backup?.value}
checked={String(hdd?.backup?.value) === '1'}
onChange={handleChange}
tooltip={__('Do we backup this disk.')}
/>
<InputField
name={hdd?.iothread?.name}
label={__('IOThread')}
type="checkbox"
value={hdd?.iothread?.value}
checked={String(hdd?.iothread?.value) === '1'}
options={ProxmoxComputeSelectors.proxmoxBackupsMap}
onChange={handleChange}
tooltip={__('Do we enable IO Threads.')}
/>
<InputField
name={hdd?.size?.name}
Expand Down

0 comments on commit 05eeaef

Please sign in to comment.