foreman_fog_proxmox 0.23.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a437699869ae38137e94761791e2a01d741e9dd36f924c286bfaa9afc139f9e7
4
- data.tar.gz: 5698645c6f2a3a3278959989e5214357263f3ba7c0091830d1f41205033582ea
3
+ metadata.gz: f08732412c42423f30a2f448a7bc48c6249bbf0a62050b28e43a56f4a774caac
4
+ data.tar.gz: ffecc9919a3f2c64f200b272a7e33065f43584f6734be25c74f794585beed665
5
5
  SHA512:
6
- metadata.gz: 1d29712272ab785a33e4bdc70f345b0da96ff22d020820bbefc27c14302c24c1207d198d6ec742562a4d30a84083b1e081b43bb6a855c432e5a67ce60ca8a5b9
7
- data.tar.gz: 9f3c39bbeca9d7364f4ee92cef02cc6fc7c398692cbc12f03a7c581324a9c21ca65ef1af33fcc892b1da02e3378f3f7c214fad2fb79bded7cfb028d55f5e5827
6
+ metadata.gz: d54a0db2ef661feeffb82d8002f7466bd1a8eb1d3b0b3d11215928b07600fbe591d9ca5cffeb36ff2d293e82523509406b949c8d81a8c2ab80ebdcf83bf95295
7
+ data.tar.gz: '0740284790c3189d29502bae8359fbf57faace0e1d27bc0e625b37ff17d0d93b31dfbd213f803e5ff2afcacb3726630cfb7176aa2d8c753ac0d31f7f0836393a'
@@ -23,11 +23,14 @@ $(document).ready(function () {
23
23
  function sslVerifyPeerSelected() {
24
24
  var selected = $("#compute_resource_ssl_verify_peer").is(':checked');
25
25
  var ssl_certs_block = $('#compute_resource_ssl_certs').parents('.clearfix');
26
+ var ssl_certs_group = $('#compute_resource_ssl_certs').parents('.form-group');
26
27
  var ssl_certs_textarea = $('#compute_resource_ssl_certs');
27
28
  if (selected) {
29
+ ssl_certs_group.removeClass('hide');
28
30
  ssl_certs_block.show();
29
31
  ssl_certs_textarea.show();
30
32
  } else {
33
+ ssl_certs_group.addClass('hide');
31
34
  ssl_certs_block.hide();
32
35
  ssl_certs_textarea.text('');
33
36
  ssl_certs_textarea.hide();
@@ -62,4 +65,11 @@ function authMethodSelected() {
62
65
  authMethods().forEach(function(method){
63
66
  toggleFieldset(method, selected);
64
67
  });
65
- }
68
+ }
69
+
70
+ window.tfm = window.tfm || {};
71
+ window.tfm.computeResource = window.tfm.computeResource || {};
72
+ window.tfm.computeResource.proxmox = {
73
+ authMethodSelected: authMethodSelected,
74
+ sslVerifyPeerSelected: sslVerifyPeerSelected,
75
+ };
@@ -130,8 +130,11 @@ module ProxmoxFormHelper
130
130
  def proxmox_valid_interface_compute_attributes?(compute_attributes, vm_type)
131
131
  return false unless compute_attributes.respond_to?(:keys)
132
132
 
133
- valid_keys = interface_compute_attributes_typed_keys(vm_type)
134
- compute_attributes.keys.map(&:to_s).all? { |key| valid_keys.include?(key) }
133
+ compute_attribute_keys = compute_attributes.keys.map(&:to_s)
134
+ required_keys = interface_compute_attributes_required_typed_keys(vm_type)
135
+ missing_keys = required_keys - compute_attribute_keys
136
+
137
+ required_keys.any? && missing_keys.empty?
135
138
  end
136
139
 
137
140
  def extract_attr(attrs, key)
@@ -55,6 +55,17 @@ module ProxmoxVMInterfacesHelper
55
55
  keys
56
56
  end
57
57
 
58
+ def interface_compute_attributes_required_typed_keys(type)
59
+ case type
60
+ when 'qemu'
61
+ ['model']
62
+ when 'lxc'
63
+ ['name']
64
+ else
65
+ []
66
+ end
67
+ end
68
+
58
69
  def interface_common_typed_keys(type)
59
70
  ['id', (type == 'qemu') ? 'macaddr' : 'hwaddr']
60
71
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2026
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module ForemanFogProxmox
21
+ module ComputeAttributesUpdateDetector
22
+ def update_required?(old_attrs, new_attrs)
23
+ old_attrs = old_attrs.deep_symbolize_keys
24
+ new_attrs = new_attrs.deep_symbolize_keys
25
+ new_attrs.each do |key, new_v|
26
+ old_v = old_attrs[key]
27
+ if new_v.is_a?(Hash)
28
+ unless old_v.is_a?(Hash)
29
+ logger.debug "Scheduling compute instance update because #{key} changed it's value from '#{old_v}' (#{old_v.class}) to '#{new_v}' (#{new_v.class})"
30
+ return true
31
+ end
32
+ return true if update_required?(old_v, new_v)
33
+ elsif old_v.to_s != new_v.to_s
34
+ logger.debug "Scheduling compute instance update because #{key} changed it's value from '#{old_v}' (#{old_v.class}) to '#{new_v}' (#{new_v.class})"
35
+ return true
36
+ end
37
+ end
38
+ false
39
+ end
40
+ end
41
+ end
@@ -35,6 +35,7 @@ module ForemanFogProxmox
35
35
  include ProxmoxOperatingSystems
36
36
  include ProxmoxVersion
37
37
  include ProxmoxConsole
38
+ include ComputeAttributesUpdateDetector
38
39
  validates :url, :format => { :with => URI::DEFAULT_PARSER.make_regexp }, :presence => true
39
40
  validates :auth_method, :presence => true, :inclusion => { in: ['access_ticket', 'user_token'],
40
41
  message: ->(value) do format('%<value>s is not a valid authentication method', { value: value }) end }
@@ -15,12 +15,10 @@ GNU General Public License for more details.
15
15
  You should have received a copy of the GNU General Public License
16
16
  along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
17
17
 
18
- <%= javascript_include_tag 'foreman_fog_proxmox/proxmox_compute_resource', "data-turbolinks-track" => true %>
19
-
20
18
  <% user_token = f.object.auth_method == 'user_token' %>
21
19
  <% access_ticket = f.object.auth_method == 'access_ticket' %>
22
- <% ssl_verify_peer = f.object.ssl_verify_peer == '1' %>
23
- <%= select_f f, :auth_method, proxmox_auth_methods_map, :id, :name, { }, :label_help => _("Click Test connection button before changing it"), :label => _('Authentication method'), :label_size => "col-md-2", :required => true, :onchange => 'authMethodSelected();' %>
20
+ <% ssl_verify_peer = f.object.ssl_verify_peer %>
21
+ <%= select_f f, :auth_method, proxmox_auth_methods_map, :id, :name, { }, :label_help => _("Click Test connection button before changing it"), :label => _('Authentication method'), :label_size => "col-md-2", :required => true, :onchange => 'tfm.computeResource.proxmox.authMethodSelected();' %>
24
22
  <%= field_set_tag _("Common fields"), :id => "compute_ressource_common_field_set" do %>
25
23
  <%= text_f f, :url, :help_block => _("e.g. https://127.0.0.1:8006/api2/json") %>
26
24
  <%= text_f f, :user , :help_block => _("e.g. root@pam") %>
@@ -33,8 +31,9 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
33
31
  <%= password_f f, :password, :keep_value => true, :unset => unset_password?, :required => access_ticket %>
34
32
  <% end %>
35
33
  <%= field_set_tag _("SSL fields"), :id => "compute_ressource_ssl_field_set" do %>
36
- <%= checkbox_f f, :ssl_verify_peer, :label => _("SSL verify peer"), :label_help => _("Click Test connection button before changing it"), :checked_value => '1', :onchange => 'sslVerifyPeerSelected();' %>
34
+ <%= checkbox_f f, :ssl_verify_peer, :label => _("SSL verify peer"), :label_help => _("Click Test connection button before changing it"), :checked_value => '1', :onchange => 'tfm.computeResource.proxmox.sslVerifyPeerSelected();' %>
37
35
  <%= textarea_f f, :ssl_certs, :label => _("X509 Certification Authorities"), :size => "col-md-4",
36
+ :wrapper_class => "form-group #{'hide' unless ssl_verify_peer}",
38
37
  :placeholder => _("Optionally provide a CA, or a correctly ordered CA chain. If left blank, disable ssl_verify_peer.") %>
39
38
  <% end %>
40
39
  <div class="col-md-offset-2">
@@ -18,5 +18,5 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ForemanFogProxmox
21
- VERSION = '0.23.0'
21
+ VERSION = '0.23.1'
22
22
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of ForemanFogProxmox.
4
+
5
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'test_plugin_helper'
19
+
20
+ module ForemanFogProxmox
21
+ class ProxmoxFormHelperTest < ActiveSupport::TestCase
22
+ include ProxmoxFormHelper
23
+
24
+ describe 'interface compute attribute validation' do
25
+ let(:required_attrs) do
26
+ {
27
+ 'qemu' => { 'model' => 'virtio' },
28
+ 'lxc' => { 'name' => 'eth0' },
29
+ }
30
+ end
31
+
32
+ it 'rejects attributes when required keys are missing' do
33
+ required_attrs.each_key do |vm_type|
34
+ assert_not send(:proxmox_valid_interface_compute_attributes?, { 'bridge' => 'vmbr0' }, vm_type)
35
+ end
36
+ end
37
+
38
+ it 'accepts attributes when required keys are present' do
39
+ required_attrs.each do |vm_type, attrs|
40
+ assert send(:proxmox_valid_interface_compute_attributes?, attrs, vm_type)
41
+ end
42
+ end
43
+
44
+ it 'accepts attributes when required keys are present with other keys' do
45
+ required_attrs.each do |vm_type, attrs|
46
+ assert send(:proxmox_valid_interface_compute_attributes?, attrs.merge('bridge' => 'vmbr0'), vm_type)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -54,11 +54,86 @@ module ForemanFogProxmox
54
54
  assert_equal :foreman_uuid, cr.provided_attributes[:uuid]
55
55
  end
56
56
 
57
+ test '#update_required? detects added HDD attributes' do
58
+ cr = FactoryBot.build_stubbed(:proxmox_cr)
59
+ old_attrs = hdd_compute_attrs(hdd_attrs('0'))
60
+ new_attrs = hdd_compute_attrs(hdd_attrs('0').merge('1' => hdd_attributes('virtio1', 'virtio', '1')))
61
+
62
+ assert cr.update_required?(old_attrs, new_attrs)
63
+ end
64
+
65
+ test '#update_required? detects removed HDD attributes' do
66
+ cr = FactoryBot.build_stubbed(:proxmox_cr)
67
+
68
+ old_attrs = hdd_compute_attrs(
69
+ hdd_attrs('0').merge('1' => hdd_attributes('virtio1', 'virtio', '1'))
70
+ )
71
+
72
+ new_attrs = hdd_compute_attrs(
73
+ hdd_attrs('0').merge('1' => { '_delete' => '1' })
74
+ )
75
+
76
+ assert cr.update_required?(old_attrs, new_attrs)
77
+ end
78
+
79
+ test '#update_required? detects modified existing HDD attributes' do
80
+ cr = FactoryBot.build_stubbed(:proxmox_cr)
81
+ old_attrs = hdd_compute_attrs(hdd_attrs('0'))
82
+ new_attrs = hdd_compute_attrs(hdd_attrs('0').deep_merge('0' => { 'size' => '20' }))
83
+
84
+ assert cr.update_required?(old_attrs, new_attrs)
85
+ end
86
+
87
+ test '#update_required? detects modified CPU flag' do
88
+ cr = FactoryBot.build_stubbed(:proxmox_cr)
89
+ old_attrs = { 'config_attributes' => { 'spectre' => '0' } }
90
+ new_attrs = { 'config_attributes' => { 'spectre' => '+1' } }
91
+
92
+ assert cr.update_required?(old_attrs, new_attrs)
93
+ end
94
+
95
+ test '#update_required? detects modified network interface' do
96
+ cr = FactoryBot.build_stubbed(:proxmox_cr)
97
+ old_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0', 'bridge' => 'vmbr0' } } }
98
+ new_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0', 'bridge' => 'vmbr1' } } }
99
+
100
+ assert cr.update_required?(old_attrs, new_attrs)
101
+ end
102
+
103
+ test '#update_required? detects added network interface' do
104
+ cr = FactoryBot.build_stubbed(:proxmox_cr)
105
+ old_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0' } } }
106
+ new_attrs = { 'interfaces_attributes' => { '0' => { 'id' => 'net0' }, '1' => { 'id' => 'net1' } } }
107
+
108
+ assert cr.update_required?(old_attrs, new_attrs)
109
+ end
110
+
57
111
  test '#node' do
58
112
  node = mock('node')
59
113
  cr = FactoryBot.build_stubbed(:proxmox_cr)
60
114
  cr.stubs(:node).returns(node)
61
115
  assert_equal node, (as_admin { cr.node })
62
116
  end
117
+
118
+ private
119
+
120
+ def hdd_compute_attrs(volumes_attrs)
121
+ { 'volumes_attributes' => volumes_attrs }
122
+ end
123
+
124
+ def hdd_attrs(index)
125
+ { index => hdd_attributes('scsi0', 'scsi', '0') }
126
+ end
127
+
128
+ def hdd_attributes(id, controller, device)
129
+ {
130
+ 'id' => id,
131
+ 'storage_type' => 'hard_disk',
132
+ 'controller' => controller,
133
+ 'device' => device,
134
+ 'storage' => 'local-lvm',
135
+ 'size' => '10',
136
+ }
137
+ end
63
138
  end
64
139
  end
@@ -1,3 +1,5 @@
1
+ import '../app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource';
2
+
1
3
  // Placeholder to initialize routes (compare foreman_ansible)
2
4
 
3
5
  /*
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_fog_proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Robert
@@ -153,6 +153,7 @@ files:
153
153
  - app/models/concerns/host_ext/proxmox/for_vm.rb
154
154
  - app/models/concerns/host_ext/proxmox/interfaces.rb
155
155
  - app/models/concerns/orchestration/proxmox/compute.rb
156
+ - app/models/foreman_fog_proxmox/compute_attributes_update_detector.rb
156
157
  - app/models/foreman_fog_proxmox/options_select.rb
157
158
  - app/models/foreman_fog_proxmox/proxmox.rb
158
159
  - app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb
@@ -254,6 +255,7 @@ files:
254
255
  - test/functional/compute_resources_controller_test.rb
255
256
  - test/test_plugin_helper.rb
256
257
  - test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
258
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_form_helper_test.rb
257
259
  - test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
258
260
  - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb
259
261
  - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb
@@ -333,6 +335,7 @@ test_files:
333
335
  - test/functional/compute_resources_controller_test.rb
334
336
  - test/test_plugin_helper.rb
335
337
  - test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb
338
+ - test/unit/foreman_fog_proxmox/helpers/proxmox_form_helper_test.rb
336
339
  - test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb
337
340
  - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb
338
341
  - test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb