Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding backup option for disks and fixing issues with updating compute node when unneeded #364

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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 @@ -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
Expand All @@ -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']
Expand Down
8 changes: 6 additions & 2 deletions app/helpers/proxmox_vm_volumes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions app/models/foreman_fog_proxmox/proxmox_volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
</div>
<%= 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') %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this line as this is an obsolete file and will be removed in next version.

<% end %>
5 changes: 5 additions & 0 deletions webpack/components/ProxmoxComputeSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
4 changes: 4 additions & 0 deletions webpack/components/ProxmoxServer/ProxmoxServerStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion webpack/components/ProxmoxServer/components/HardDisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -118,6 +117,14 @@ const HardDisk = ({
options={ProxmoxComputeSelectors.proxmoxCachesMap}
onChange={handleChange}
/>
<InputField
name={hdd?.backup?.name}
label={__('Backup')}
type="select"
value={hdd?.backup?.value}
options={ProxmoxComputeSelectors.proxmoxBackupsMap}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options={ProxmoxComputeSelectors.proxmoxBackupsMap}
info={__('Enable/disable volume backup')}
options={ProxmoxComputeSelectors.proxmoxBackupsMap}

onChange={handleChange}
/>
<InputField
name={hdd?.size?.name}
label={__('Size (GB)')}
Expand Down
Loading